Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LastSyncTime can be empty #21829

Merged
merged 3 commits into from
Jun 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System;
using System.Text;
using System.Xml.Linq;
using Azure.Core;

namespace Azure.Data.Tables.Models
{
public partial class TableGeoReplicationInfo
{
internal static TableGeoReplicationInfo DeserializeTableGeoReplicationInfo(XElement element)
{
TableGeoReplicationStatus status = default;
DateTimeOffset lastSyncedOn = default;
if (element.Element("Status") is XElement statusElement)
{
status = new TableGeoReplicationStatus(statusElement.Value);
}
if (element.Element("LastSyncTime") is XElement lastSyncTimeElement)
{
// LastSyncTime can be empty (see https://docs.microsoft.com/en-us/rest/api/storageservices/get-table-service-stats#response-body)
lastSyncedOn = (lastSyncTimeElement.Value.Length == 0) switch
{
true => DateTimeOffset.MinValue,
false => lastSyncTimeElement.GetDateTimeOffsetValue("R")
};
}
return new TableGeoReplicationInfo(status, lastSyncedOn);
}
}
}
60 changes: 47 additions & 13 deletions sdk/tables/Azure.Data.Tables/tests/TableServiceClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the MIT License.

using System;
using System.Threading.Tasks;
using Azure.Core.TestFramework;
using Azure.Data.Tables.Sas;
using NUnit.Framework;
Expand All @@ -11,19 +12,20 @@ namespace Azure.Data.Tables.Tests
public class TableServiceClientTests : ClientTestBase
{
public TableServiceClientTests(bool isAsync) : base(isAsync)
{
}
{ }

/// <summary>
/// The table account name.
/// </summary>
private readonly string _accountName = "someaccount";

private const string Secret = "Kg==";

/// <summary>
/// The table endpoint.
/// </summary>
private readonly Uri _url = new Uri($"https://someaccount.table.core.windows.net");

private readonly Uri _urlHttp = new Uri($"http://someaccount.table.core.windows.net");

private TableServiceClient service_Instrumented { get; set; }
Expand All @@ -40,17 +42,35 @@ public void TestSetup()
[Test]
public void ConstructorValidatesArguments()
{
Assert.That(() => new TableServiceClient(null, new TableSharedKeyCredential(_accountName, string.Empty)), Throws.InstanceOf<ArgumentNullException>(), "The constructor should validate the url.");

Assert.That(() => new TableServiceClient(_url, credential: default(TableSharedKeyCredential)), Throws.InstanceOf<ArgumentNullException>(), "The constructor should validate the TablesSharedKeyCredential.");

Assert.That(() => new TableServiceClient(_urlHttp, new AzureSasCredential("sig")), Throws.InstanceOf<ArgumentException>(), "The constructor should validate the Uri is https when using a SAS token.");

Assert.That(() => new TableServiceClient(_url, default(AzureSasCredential)), Throws.InstanceOf<ArgumentNullException>(), "The constructor should not accept a null credential");

Assert.That(() => new TableServiceClient(_url, new TableSharedKeyCredential(_accountName, string.Empty)), Throws.Nothing, "The constructor should accept valid arguments.");

Assert.That(() => new TableServiceClient(_urlHttp, new TableSharedKeyCredential(_accountName, string.Empty)), Throws.Nothing, "The constructor should accept an http url.");
Assert.That(
() => new TableServiceClient(null, new TableSharedKeyCredential(_accountName, string.Empty)),
Throws.InstanceOf<ArgumentNullException>(),
"The constructor should validate the url.");

Assert.That(
() => new TableServiceClient(_url, credential: default(TableSharedKeyCredential)),
Throws.InstanceOf<ArgumentNullException>(),
"The constructor should validate the TablesSharedKeyCredential.");

Assert.That(
() => new TableServiceClient(_urlHttp, new AzureSasCredential("sig")),
Throws.InstanceOf<ArgumentException>(),
"The constructor should validate the Uri is https when using a SAS token.");

Assert.That(
() => new TableServiceClient(_url, default(AzureSasCredential)),
Throws.InstanceOf<ArgumentNullException>(),
"The constructor should not accept a null credential");

Assert.That(
() => new TableServiceClient(_url, new TableSharedKeyCredential(_accountName, string.Empty)),
Throws.Nothing,
"The constructor should accept valid arguments.");

Assert.That(
() => new TableServiceClient(_urlHttp, new TableSharedKeyCredential(_accountName, string.Empty)),
Throws.Nothing,
"The constructor should accept an http url.");
}

/// <summary>
Expand Down Expand Up @@ -111,5 +131,19 @@ public void GenerateSasUri()

Assert.AreEqual("?" + expectedSas, actualSas.Query);
}

[Test]
public async Task GetStatisticsHandlesEmptyLAstUpdatedTime(
[Values("Tue, 23 Mar 2021 18:29:21 GMT", "")]
string date)
{
var response = new MockResponse(200);
response.SetContent(
$"<?xml version=\"1.0\" encoding=\"utf-8\"?><StorageServiceStats><GeoReplication><Status>live</Status><LastSyncTime>{date}</LastSyncTime></GeoReplication></StorageServiceStats>");
var mockTransport = new MockTransport(response);
var service = InstrumentClient(new TableServiceClient(_url, new AzureSasCredential("sig"), new TableClientOptions { Transport = mockTransport }));

await service.GetStatisticsAsync();
}
}
}