Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
83cee90
Code changes to add regional endpoints for account metadata calls.
kundadebdatta Jan 17, 2024
1e12015
Code changes to refactor some codes.
kundadebdatta Jan 19, 2024
7f68b28
Code changes to add unit tests.
kundadebdatta Jan 22, 2024
7aa43f8
Code changes to make minor code clean-up.
kundadebdatta Jan 23, 2024
58517ed
Merge branch 'master' into users/kundadebdatta/4236_add_custom_domain…
kundadebdatta Jan 23, 2024
60a0803
Code changes to fix tests. Refactored API.
kundadebdatta Jan 23, 2024
a3b4c78
Merge branch 'users/kundadebdatta/4236_add_custom_domain_names' of ht…
kundadebdatta Jan 23, 2024
6efe507
Code changes to refactor the enumeration logic inside global endpoint…
kundadebdatta Jan 25, 2024
fb5af02
Code changes to address review comments.
kundadebdatta Jan 25, 2024
55f1ace
Code changes to fix minor API parameter.
kundadebdatta Jan 25, 2024
94b0058
Code changes to update the API naming.
kundadebdatta Jan 26, 2024
9cc57ad
Code changes to update some attribute names.
kundadebdatta Jan 26, 2024
3c4498f
Merge branch 'master' into users/kundadebdatta/4236_add_custom_domain…
kundadebdatta Jan 26, 2024
348e4a7
Code changes to refactor service endpoint creation logic.
kundadebdatta Jan 29, 2024
ea51744
Code changes to address review comments.
kundadebdatta Jan 30, 2024
b8788d4
Merge branch 'master' into users/kundadebdatta/4236_add_custom_domain…
kundadebdatta Jan 30, 2024
f177371
Code changes to address review comments.
kundadebdatta Feb 6, 2024
35d1c9a
Merge branch 'master' into users/kundadebdatta/4236_add_custom_domain…
kundadebdatta Feb 6, 2024
d4c3526
Code changes to update the API contract.
kundadebdatta Feb 6, 2024
5a39ba3
Merge branch 'master' into users/kundadebdatta/4236_add_custom_domain…
kundadebdatta Feb 6, 2024
65b9b44
Cosmetic code changes.
kundadebdatta Feb 6, 2024
be9b5d7
Merge branch 'master' into users/kundadebdatta/4236_add_custom_domain…
kundadebdatta Feb 7, 2024
3a9d168
Code changes to address review comments.
kundadebdatta Feb 8, 2024
581c6af
Merge branch 'master' into users/kundadebdatta/4236_add_custom_domain…
kundadebdatta Feb 8, 2024
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
Prev Previous commit
Next Next commit
Code changes to add unit tests.
  • Loading branch information
kundadebdatta committed Jan 22, 2024
commit 7f68b28c5b1fd7d1113d349b855c694d1adb339c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ namespace Microsoft.Azure.Cosmos
using Microsoft.Azure.Cosmos.Tracing;
using Microsoft.Azure.Cosmos.Tracing.TraceData;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Text;

/// <summary>
/// Tests for <see cref="GatewayAccountReader"/>.
Expand Down Expand Up @@ -102,34 +104,111 @@ public void DocumentClient_BuildHttpClientFactory_WithFactory()
}

[TestMethod]
public async Task InitializeReaderAsync_WhenInvokedWithRegionalEndpoints_ShouldRetryWhenPrimaryEndpointFails()
[DataRow(true, DisplayName = "Validate that when regional endpoints are provided in the connection policy, the request will be retried in the regional endpoints.")]
[DataRow(false, DisplayName = "Validate that when regional endpoints are not provided in the connection policy, the request will be failed in the primary endpoint.")]
public async Task InitializeReaderAsync_WhenRegionalEndpointsProvided_ShouldRetryWithRegionalEndpointsWhenPrimaryFails(
bool regionalEndpointsProvided)
{
HttpMessageHandler messageHandler = new CustomMessageHandler();
HttpClient staticHttpClient = new HttpClient(messageHandler);
string accountPropertiesResponse = "{\r\n \"_self\": \"\",\r\n \"id\": \"localhost\",\r\n \"_rid\": \"127.0.0.1\",\r\n \"media\": \"//media/\",\r\n \"addresses\": \"//addresses/\",\r\n \"_dbs\": \"//dbs/\",\r\n \"writableLocations\": [\r\n {\r\n \"name\": \"South Central US\",\r\n \"databaseAccountEndpoint\": \"https://127.0.0.1:8081/\"\r\n }" +
"\r\n ],\r\n \"readableLocations\": [\r\n {\r\n \"name\": \"South Central US\",\r\n \"databaseAccountEndpoint\": \"https://127.0.0.1:8081/\"\r\n }\r\n ],\r\n \"enableMultipleWriteLocations\": false,\r\n \"userReplicationPolicy\": {\r\n \"asyncReplication\": false,\r\n \"minReplicaSetSize\": 1,\r\n \"maxReplicasetSize\": 4\r\n },\r\n \"userConsistencyPolicy\": {\r\n " +
"\"defaultConsistencyLevel\": \"Session\"\r\n },\r\n \"systemReplicationPolicy\": {\r\n \"minReplicaSetSize\": 1,\r\n \"maxReplicasetSize\": 4\r\n },\r\n \"readPolicy\": {\r\n \"primaryReadCoefficient\": 1,\r\n \"secondaryReadCoefficient\": 1\r\n },\r\n \"queryEngineConfiguration\": \"{\\\"maxSqlQueryInputLength\\\":262144,\\\"maxJoinsPerSqlQuery\\\":5," +
"\\\"maxLogicalAndPerSqlQuery\\\":500,\\\"maxLogicalOrPerSqlQuery\\\":500,\\\"maxUdfRefPerSqlQuery\\\":10,\\\"maxInExpressionItemsCount\\\":16000,\\\"queryMaxInMemorySortDocumentCount\\\":500,\\\"maxQueryRequestTimeoutFraction\\\":0.9,\\\"sqlAllowNonFiniteNumbers\\\":false,\\\"sqlAllowAggregateFunctions\\\":true,\\\"sqlAllowSubQuery\\\":true,\\\"sqlAllowScalarSubQuery\\\":true,\\\"allowNewKeywords\\\":true,\\\"" +
"sqlAllowLike\\\":true,\\\"sqlAllowGroupByClause\\\":true,\\\"maxSpatialQueryCells\\\":12,\\\"spatialMaxGeometryPointCount\\\":256,\\\"sqlDisableOptimizationFlags\\\":0,\\\"sqlAllowTop\\\":true,\\\"enableSpatialIndexing\\\":true}\"\r\n}";

StringContent content = new(accountPropertiesResponse);
HttpResponseMessage responseMessage = new()
{
StatusCode = HttpStatusCode.OK,
Content = content,
};

Mock<CosmosHttpClient> mockHttpClient = new();
mockHttpClient
.SetupSequence(x => x.GetAsync(
It.IsAny<Uri>(),
It.IsAny<INameValueCollection>(),
It.IsAny<ResourceType>(),
It.IsAny<HttpTimeoutPolicy>(),
It.IsAny<IClientSideRequestStatistics>(),
It.IsAny<CancellationToken>()))
.ThrowsAsync(new Exception("Service is Unavailable at the Moment."))
.ThrowsAsync(new Exception("Service is Unavailable at the Moment."))
.ReturnsAsync(responseMessage);

ConnectionPolicy connectionPolicy = new()
{
ConnectionMode = ConnectionMode.Direct,
};

if (regionalEndpointsProvided)
{
connectionPolicy.SetRegionalEndpoints(
new List<string>()
{
"https://testfed2.documents-test.windows-int.net:443/",
"https://testfed3.documents-test.windows-int.net:443/",
"https://testfed4.documents-test.windows-int.net:443/",
});
}

GatewayAccountReader accountReader = new GatewayAccountReader(
serviceEndpoint: new Uri("https://testfed1.documents-test.windows-int.net:443/"),
cosmosAuthorization: Mock.Of<AuthorizationTokenProvider>(),
connectionPolicy: connectionPolicy,
httpClient: mockHttpClient.Object);

if (regionalEndpointsProvided)
{
AccountProperties accountProperties = await accountReader.InitializeReaderAsync();

Assert.IsNotNull(accountProperties);
Assert.AreEqual("localhost", accountProperties.Id);
Assert.AreEqual("127.0.0.1", accountProperties.ResourceId);
}
else
{
Exception exception = await Assert.ThrowsExceptionAsync<Exception>(() => accountReader.InitializeReaderAsync());
Assert.IsNotNull(exception);
Assert.AreEqual("Service is Unavailable at the Moment.", exception.Message);
}
}

Mock<HttpClient> mockedHttpClient = new();
[TestMethod]
public async Task InitializeReaderAsync_WhenRegionalEndpointsProvided_ShouldThrowAggregateExceptionWithAllEndpointsFail()
{
Mock<CosmosHttpClient> mockHttpClient = new();
mockHttpClient
.Setup(x => x.GetAsync(
It.IsAny<Uri>(),
It.IsAny<INameValueCollection>(),
It.IsAny<ResourceType>(),
It.IsAny<HttpTimeoutPolicy>(),
It.IsAny<IClientSideRequestStatistics>(),
It.IsAny<CancellationToken>()))
.ThrowsAsync(new Exception("Service is Unavailable at the Moment."));

ConnectionPolicy connectionPolicy = new()
{
EnablePartitionLevelFailover = true,
ConnectionMode = ConnectionMode.Direct,
};

connectionPolicy.SetRegionalEndpoints(
new List<string>()
{
"https://dkppaf1.documents-test.windows-int.net:443/",
"https://dkppaf2.documents-test.windows-int.net:443/",
"https://dkppaf6.documents-test.windows-int.net:443/",
"https://testfed2.documents-test.windows-int.net:443/",
"https://testfed3.documents-test.windows-int.net:443/",
"https://testfed4.documents-test.windows-int.net:443/",
});

GatewayAccountReader accountReader = new GatewayAccountReader(
serviceEndpoint: new Uri("https://localhost"),
serviceEndpoint: new Uri("https://testfed1.documents-test.windows-int.net:443/"),
cosmosAuthorization: Mock.Of<AuthorizationTokenProvider>(),
connectionPolicy: connectionPolicy,
httpClient: MockCosmosUtil.CreateCosmosHttpClient(() => staticHttpClient));
httpClient: mockHttpClient.Object);

AggregateException exception = await Assert.ThrowsExceptionAsync<AggregateException>(() => accountReader.InitializeReaderAsync());
Assert.IsNotNull(exception);
Assert.AreEqual("Service is Unavailable at the Moment.", exception.InnerException.Message);
}

public class CustomMessageHandler : HttpMessageHandler
Expand Down