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

Per Partition Automatic Failover: Adds requirement to enable application region or application preferred regions for PPAF #4987

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
11 changes: 6 additions & 5 deletions Microsoft.Azure.Cosmos/src/CosmosClientOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1136,11 +1136,12 @@ private void ValidateLimitToEndpointSettings()
}

private void ValidatePartitionLevelFailoverSettings()
{
if (this.EnablePartitionLevelFailover
&& (this.ApplicationPreferredRegions == null || this.ApplicationPreferredRegions.Count == 0))
{
throw new ArgumentException($"{nameof(this.ApplicationPreferredRegions)} is required when {nameof(this.EnablePartitionLevelFailover)} is enabled.");
{
if (this.EnablePartitionLevelFailover
&& string.IsNullOrEmpty(this.ApplicationRegion)
&& (this.ApplicationPreferredRegions is null || this.ApplicationPreferredRegions.Count == 0))
{
throw new ArgumentException($"{nameof(this.ApplicationPreferredRegions)} or {nameof(this.ApplicationRegion)} is required when {nameof(this.EnablePartitionLevelFailover)} is enabled.");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1134,6 +1134,47 @@ public void TestServerCertificatesValidationWithDisableSSLFlagTrue(string connSt
#nullable disable
}

[TestMethod]
public void PPAFClientApplicationRegionCreationTest()
{
CosmosClientOptions cosmosClientOptions = new CosmosClientOptions
{
ApplicationRegion = Regions.WestUS2,
EnablePartitionLevelFailover = true
};

CosmosClient cosmosClient = new CosmosClient(ConnectionString, cosmosClientOptions);
Assert.AreEqual(Regions.WestUS2, cosmosClient.ClientOptions.ApplicationRegion);
Assert.IsTrue(cosmosClient.ClientOptions.EnablePartitionLevelFailover);
}

[TestMethod]
public void PPAFClientApplicationPreferredRegionCreationTest()
{
CosmosClientOptions cosmosClientOptions = new CosmosClientOptions
{
ApplicationPreferredRegions = new List<string> { Regions.WestUS2, Regions.EastUS2 },
EnablePartitionLevelFailover = true
};

CosmosClient cosmosClient = new CosmosClient(ConnectionString, cosmosClientOptions);
Assert.AreEqual(Regions.WestUS2, cosmosClient.ClientOptions.ApplicationPreferredRegions[0]);
Assert.AreEqual(Regions.EastUS2, cosmosClient.ClientOptions.ApplicationPreferredRegions[1]);
Assert.IsTrue(cosmosClient.ClientOptions.EnablePartitionLevelFailover);
}

[TestMethod]
[ExpectedException(typeof(ArgumentException))]
NaluTripician marked this conversation as resolved.
Show resolved Hide resolved
public void PPAFClientNoRegionsTest()
{
CosmosClientOptions cosmosClientOptions = new CosmosClientOptions
{
EnablePartitionLevelFailover = true
};

_ = new CosmosClient(ConnectionString, cosmosClientOptions);
}

private class TestWebProxy : IWebProxy
{
public ICredentials Credentials { get; set; }
Expand Down
Loading