diff --git a/Microsoft.Azure.Cosmos/src/Batch/BatchAsyncContainerExecutor.cs b/Microsoft.Azure.Cosmos/src/Batch/BatchAsyncContainerExecutor.cs index ce4f8ccfe2..3dfa37876e 100644 --- a/Microsoft.Azure.Cosmos/src/Batch/BatchAsyncContainerExecutor.cs +++ b/Microsoft.Azure.Cosmos/src/Batch/BatchAsyncContainerExecutor.cs @@ -67,7 +67,7 @@ public BatchAsyncContainerExecutor( this.maxServerRequestBodyLength = maxServerRequestBodyLength; this.maxServerRequestOperationCount = maxServerRequestOperationCount; this.timerWheel = TimerWheel.CreateTimerWheel(BatchAsyncContainerExecutor.TimerWheelResolution, BatchAsyncContainerExecutor.TimerWheelBucketCount); - this.retryOptions = cosmosClientContext.ClientOptions.GetConnectionPolicy().RetryOptions; + this.retryOptions = cosmosClientContext.ClientOptions.GetConnectionPolicy(cosmosClientContext.Client.ClientId).RetryOptions; } public virtual async Task AddAsync( diff --git a/Microsoft.Azure.Cosmos/src/ConnectionPolicy.cs b/Microsoft.Azure.Cosmos/src/ConnectionPolicy.cs index c5daddaac2..b76c7a3cd4 100644 --- a/Microsoft.Azure.Cosmos/src/ConnectionPolicy.cs +++ b/Microsoft.Azure.Cosmos/src/ConnectionPolicy.cs @@ -39,7 +39,7 @@ public ConnectionPolicy() this.ConnectionMode = ConnectionMode.Gateway; this.MaxConcurrentFanoutRequests = defaultMaxConcurrentFanoutRequests; this.MediaReadMode = MediaReadMode.Buffered; - this.UserAgentContainer = new UserAgentContainer(); + this.UserAgentContainer = new UserAgentContainer(clientId: 0); this.preferredLocations = new ObservableCollection(); this.EnableEndpointDiscovery = true; this.MaxConnectionLimit = defaultMaxConcurrentConnectionLimit; diff --git a/Microsoft.Azure.Cosmos/src/CosmosClient.cs b/Microsoft.Azure.Cosmos/src/CosmosClient.cs index ae57d5173b..2ca1bcd942 100644 --- a/Microsoft.Azure.Cosmos/src/CosmosClient.cs +++ b/Microsoft.Azure.Cosmos/src/CosmosClient.cs @@ -250,11 +250,11 @@ internal CosmosClient( clientOptions ??= new CosmosClientOptions(); + this.ClientId = this.IncrementNumberOfClientsCreated(); this.ClientContext = ClientContextCore.Create( this, clientOptions); - - this.IncrementNumberOfClientsCreated(); + this.ClientConfigurationTraceDatum = new ClientConfigurationTraceDatum(this.ClientContext, DateTime.UtcNow); } @@ -479,6 +479,7 @@ internal CosmosClient( internal RequestInvokerHandler RequestHandler => this.ClientContext.RequestHandler; internal CosmosClientContext ClientContext { get; } internal ClientConfigurationTraceDatum ClientConfigurationTraceDatum { get; } + internal int ClientId { get; } /// /// Reads the for the Azure Cosmos DB account. @@ -1195,9 +1196,9 @@ private Task InitializeContainersAsync(IReadOnlyList<(string databaseId, string } } - private void IncrementNumberOfClientsCreated() + private int IncrementNumberOfClientsCreated() { - Interlocked.Increment(ref numberOfClientsCreated); + return Interlocked.Increment(ref numberOfClientsCreated); } private async Task InitializeContainerAsync(string databaseId, string containerId, CancellationToken cancellationToken = default) diff --git a/Microsoft.Azure.Cosmos/src/CosmosClientOptions.cs b/Microsoft.Azure.Cosmos/src/CosmosClientOptions.cs index 9d8336b90c..34ac6d9b9f 100644 --- a/Microsoft.Azure.Cosmos/src/CosmosClientOptions.cs +++ b/Microsoft.Azure.Cosmos/src/CosmosClientOptions.cs @@ -646,7 +646,7 @@ internal CosmosClientOptions Clone() return cloneConfiguration; } - internal virtual ConnectionPolicy GetConnectionPolicy() + internal virtual ConnectionPolicy GetConnectionPolicy(int clientId) { this.ValidateDirectTCPSettings(); this.ValidateLimitToEndpointSettings(); @@ -657,7 +657,7 @@ internal virtual ConnectionPolicy GetConnectionPolicy() RequestTimeout = this.RequestTimeout, ConnectionMode = this.ConnectionMode, ConnectionProtocol = this.ConnectionProtocol, - UserAgentContainer = this.CreateUserAgentContainerWithFeatures(), + UserAgentContainer = this.CreateUserAgentContainerWithFeatures(clientId), UseMultipleWriteLocations = true, IdleTcpConnectionTimeout = this.IdleTcpConnectionTimeout, OpenTcpConnectionTimeout = this.OpenTcpConnectionTimeout, @@ -808,7 +808,7 @@ private void ValidateDirectTCPSettings() } } - internal UserAgentContainer CreateUserAgentContainerWithFeatures() + internal UserAgentContainer CreateUserAgentContainerWithFeatures(int clientId) { CosmosClientOptionsFeatures features = CosmosClientOptionsFeatures.NoFeatures; if (this.AllowBulkExecution) @@ -830,6 +830,7 @@ internal UserAgentContainer CreateUserAgentContainerWithFeatures() string regionConfiguration = this.GetRegionConfiguration(); return new UserAgentContainer( + clientId: clientId, features: featureString, regionConfiguration: regionConfiguration, suffix: this.ApplicationName); diff --git a/Microsoft.Azure.Cosmos/src/Resource/ClientContextCore.cs b/Microsoft.Azure.Cosmos/src/Resource/ClientContextCore.cs index 08ac35b797..dcda9e62aa 100644 --- a/Microsoft.Azure.Cosmos/src/Resource/ClientContextCore.cs +++ b/Microsoft.Azure.Cosmos/src/Resource/ClientContextCore.cs @@ -71,7 +71,7 @@ internal static CosmosClientContext Create( apitype: clientOptions.ApiType, sendingRequestEventArgs: clientOptions.SendingRequestEventArgs, transportClientHandlerFactory: clientOptions.TransportClientHandlerFactory, - connectionPolicy: clientOptions.GetConnectionPolicy(), + connectionPolicy: clientOptions.GetConnectionPolicy(cosmosClient.ClientId), enableCpuMonitor: clientOptions.EnableCpuMonitor, storeClientFactory: clientOptions.StoreClientFactory, desiredConsistencyLevel: clientOptions.GetDocumentsConsistencyLevel(), diff --git a/Microsoft.Azure.Cosmos/src/UserAgentContainer.cs b/Microsoft.Azure.Cosmos/src/UserAgentContainer.cs index c5c45a5262..4a7a7ddd91 100644 --- a/Microsoft.Azure.Cosmos/src/UserAgentContainer.cs +++ b/Microsoft.Azure.Cosmos/src/UserAgentContainer.cs @@ -11,14 +11,18 @@ namespace Microsoft.Azure.Cosmos internal class UserAgentContainer : Documents.UserAgentContainer { private const int MaxOperatingSystemString = 30; + private const int MaxClientId = 10; private readonly string cosmosBaseUserAgent; + private readonly string clientId; public UserAgentContainer( + int clientId, string features = null, string regionConfiguration = "NS", string suffix = null) : base() { + this.clientId = System.Math.Min(clientId, UserAgentContainer.MaxClientId).ToString(); this.cosmosBaseUserAgent = this.CreateBaseUserAgentString( features: features, regionConfiguration: regionConfiguration); @@ -30,7 +34,6 @@ public UserAgentContainer( protected virtual void GetEnvironmentInformation( out string clientVersion, out string directVersion, - out string clientId, out string processArchitecture, out string operatingSystem, out string runtimeFramework) @@ -38,7 +41,6 @@ protected virtual void GetEnvironmentInformation( EnvironmentInformation environmentInformation = new EnvironmentInformation(); clientVersion = environmentInformation.ClientVersion; directVersion = environmentInformation.DirectVersion; - clientId = CosmosClient.numberOfClientsCreated.ToString(); processArchitecture = environmentInformation.ProcessArchitecture; operatingSystem = environmentInformation.OperatingSystem; runtimeFramework = environmentInformation.RuntimeFramework; @@ -51,7 +53,6 @@ private string CreateBaseUserAgentString( this.GetEnvironmentInformation( out string clientVersion, out string directVersion, - out string clientId, out string processArchitecture, out string operatingSystem, out string runtimeFramework); @@ -63,7 +64,7 @@ private string CreateBaseUserAgentString( // Regex replaces all special characters with empty space except . - | since they do not cause format exception for the user agent string. // Do not change the cosmos-netstandard-sdk as it is required for reporting - string baseUserAgent = $"cosmos-netstandard-sdk/{clientVersion}" + Regex.Replace($"|{directVersion}|{clientId}|{processArchitecture}|{operatingSystem}|{runtimeFramework}|", @"[^0-9a-zA-Z\.\|\-]+", " "); + string baseUserAgent = $"cosmos-netstandard-sdk/{clientVersion}" + Regex.Replace($"|{directVersion}|{this.clientId}|{processArchitecture}|{operatingSystem}|{runtimeFramework}|", @"[^0-9a-zA-Z\.\|\-]+", " "); if (!string.IsNullOrEmpty(regionConfiguration)) { diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/HeadersValidationTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/HeadersValidationTests.cs index 2a665f49bf..3c0d027b6e 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/HeadersValidationTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/HeadersValidationTests.cs @@ -584,7 +584,7 @@ public void ValidateCustomUserAgentHeader() ConnectionPolicy policy = new ConnectionPolicy(); policy.UserAgentSuffix = suffix; - string expectedUserAgent = new Cosmos.UserAgentContainer().BaseUserAgent + suffix; + string expectedUserAgent = new Cosmos.UserAgentContainer(clientId: 0).BaseUserAgent + suffix; string actualUserAgent = policy.UserAgentContainer.UserAgent; int startIndexOfClientCounter = expectedUserAgent.IndexOfNth('|', 2) + 1; diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/UserAgentTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/UserAgentTests.cs index 4ad5897ebf..c0906969a5 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/UserAgentTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/UserAgentTests.cs @@ -36,7 +36,7 @@ public async Task ValidateUserAgentHeaderWithMacOs(bool useMacOs) using (CosmosClient client = TestCommon.CreateCosmosClient(clientOptions)) { - Cosmos.UserAgentContainer userAgentContainer = client.ClientOptions.GetConnectionPolicy().UserAgentContainer; + Cosmos.UserAgentContainer userAgentContainer = client.ClientOptions.GetConnectionPolicy(client.ClientId).UserAgentContainer; string userAgentString = userAgentContainer.UserAgent; Assert.IsTrue(userAgentString.Contains(suffix)); @@ -83,14 +83,14 @@ public void ValidateUniqueClientIdHeader() public void VerifyUserAgentContent() { EnvironmentInformation envInfo = new EnvironmentInformation(); - Cosmos.UserAgentContainer userAgentContainer = new Cosmos.UserAgentContainer(); + Cosmos.UserAgentContainer userAgentContainer = new Cosmos.UserAgentContainer(clientId: 0); string serialization = userAgentContainer.UserAgent; Assert.IsTrue(serialization.Contains(envInfo.ProcessArchitecture)); string[] values = serialization.Split('|'); Assert.AreEqual($"cosmos-netstandard-sdk/{envInfo.ClientVersion}", values[0]); Assert.AreEqual(envInfo.DirectVersion, values[1]); - Assert.AreEqual(CosmosClient.numberOfClientsCreated.ToString(), values[2]); + Assert.AreEqual("0", values[2]); Assert.AreEqual(envInfo.ProcessArchitecture, values[3]); Assert.AreEqual(envInfo.OperatingSystem, values[4]); Assert.AreEqual(envInfo.RuntimeFramework, values[5]); @@ -173,7 +173,7 @@ await this.ValidateUserAgentStringAsync( [TestMethod] public void VerifyDefaultUserAgentContainsRegionConfig() { - UserAgentContainer userAgentContainer = new Cosmos.UserAgentContainer(); + UserAgentContainer userAgentContainer = new Cosmos.UserAgentContainer(clientId: 0); Assert.IsTrue(userAgentContainer.UserAgent.Contains("|NS|")); } @@ -181,16 +181,48 @@ public void VerifyDefaultUserAgentContainsRegionConfig() public void VerifyClientIDForUserAgentString() { CosmosClient.numberOfClientsCreated = 0; // reset - for (int i = 0; i < 10; i++) + const int max = 10; + for (int i = 1; i < max + 5; i++) { using (CosmosClient client = TestCommon.CreateCosmosClient()) { string userAgentString = client.DocumentClient.ConnectionPolicy.UserAgentContainer.UserAgent; - Assert.AreEqual(userAgentString.Split('|')[2], i.ToString()); + if (i <= max) + { + Assert.AreEqual(userAgentString.Split('|')[2], i.ToString()); + } + else + { + Assert.AreEqual(userAgentString.Split('|')[2], max.ToString()); + } } } } + [TestMethod] + public async Task VerifyClientIDIncrements_Concurrent() + { + CosmosClient.numberOfClientsCreated = 0; // reset + const int max = 10; + List expected = new List(); + for (int i = 1; i < max + 5; i++) + { + expected.Add(i > max ? max : i); + } + + List> tasks = new List>(); + for (int i = 1; i < max + 5; i++) + { + tasks.Add(Task.Factory.StartNew(() => TestCommon.CreateCosmosClient())); + } + + await Task.WhenAll(tasks); + List actual = tasks.Select(r => + int.Parse(r.Result.DocumentClient.ConnectionPolicy.UserAgentContainer.UserAgent.Split('|')[2])).ToList(); + actual.Sort(); + CollectionAssert.AreEqual(expected, actual); + } + private async Task ValidateUserAgentStringAsync( CosmosClientOptions cosmosClientOptions, string userAgentContentToValidate, @@ -241,7 +273,7 @@ public async Task VerifyUserAgentWithFeatures(bool setApplicationName, bool useM using (CosmosClient client = TestCommon.CreateCosmosClient(cosmosClientOptions)) { - Cosmos.UserAgentContainer userAgentContainer = client.ClientOptions.GetConnectionPolicy().UserAgentContainer; + Cosmos.UserAgentContainer userAgentContainer = client.ClientOptions.GetConnectionPolicy(client.ClientId).UserAgentContainer; string userAgentString = userAgentContainer.UserAgent; if (setApplicationName) @@ -272,7 +304,7 @@ public async Task VerifyUserAgentWithFeatures(bool setApplicationName, bool useM using (CosmosClient client = TestCommon.CreateCosmosClient(cosmosClientOptions)) { - Cosmos.UserAgentContainer userAgentContainer = client.ClientOptions.GetConnectionPolicy().UserAgentContainer; + Cosmos.UserAgentContainer userAgentContainer = client.ClientOptions.GetConnectionPolicy(client.ClientId).UserAgentContainer; string userAgentString = userAgentContainer.UserAgent; if (setApplicationName) @@ -290,17 +322,17 @@ public async Task VerifyUserAgentWithFeatures(bool setApplicationName, bool useM private sealed class MacUserAgentStringClientOptions : CosmosClientOptions { - internal override ConnectionPolicy GetConnectionPolicy() + internal override ConnectionPolicy GetConnectionPolicy(int clientId) { - ConnectionPolicy connectionPolicy = base.GetConnectionPolicy(); - MacOsUserAgentContainer userAgent = this.CreateUserAgentContainer(); + ConnectionPolicy connectionPolicy = base.GetConnectionPolicy(clientId); + MacOsUserAgentContainer userAgent = this.CreateUserAgentContainer(clientId); connectionPolicy.UserAgentContainer = userAgent; return connectionPolicy; } - internal MacOsUserAgentContainer CreateUserAgentContainer() + internal MacOsUserAgentContainer CreateUserAgentContainer(int clientId) { CosmosClientOptionsFeatures features = CosmosClientOptionsFeatures.NoFeatures; if (this.AllowBulkExecution) @@ -320,6 +352,7 @@ internal MacOsUserAgentContainer CreateUserAgentContainer() } return new MacOsUserAgentContainer( + clientId: clientId, features: featureString, suffix: this.ApplicationName); } @@ -327,10 +360,12 @@ internal MacOsUserAgentContainer CreateUserAgentContainer() private sealed class MacOsUserAgentContainer : Cosmos.UserAgentContainer { - public MacOsUserAgentContainer(string features = null, + public MacOsUserAgentContainer(int clientId, + string features = null, string regionConfiguration = "N", string suffix = null) - : base(features, + : base(clientId, + features, regionConfiguration, suffix) { @@ -339,7 +374,6 @@ public MacOsUserAgentContainer(string features = null, protected override void GetEnvironmentInformation( out string clientVersion, out string directVersion, - out string clientId, out string processArchitecture, out string operatingSystem, out string runtimeFramework) @@ -350,7 +384,6 @@ protected override void GetEnvironmentInformation( base.GetEnvironmentInformation( clientVersion: out clientVersion, directVersion: out directVersion, - clientId: out clientId, processArchitecture: out processArchitecture, operatingSystem: out _, runtimeFramework: out runtimeFramework); @@ -369,7 +402,7 @@ private CosmosClientOptions SetEnvironmentInformation(bool useMacOs) private string GetClientIdFromCosmosClient(CosmosClient client) { - Cosmos.UserAgentContainer userAgentContainer = client.ClientOptions.GetConnectionPolicy().UserAgentContainer; + Cosmos.UserAgentContainer userAgentContainer = client.ClientOptions.GetConnectionPolicy(client.ClientId).UserAgentContainer; string userAgentString = userAgentContainer.UserAgent; string clientId = userAgentString.Split('|')[2]; return clientId; diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Batch/BatchAsyncContainerExecutorTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Batch/BatchAsyncContainerExecutorTests.cs index 96154f65f6..b342d1e041 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Batch/BatchAsyncContainerExecutorTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Batch/BatchAsyncContainerExecutorTests.cs @@ -351,6 +351,8 @@ private Mock MockClientContext() .Returns>, TraceComponent, TraceLevel>( (operationName, requestOptions, func, comp, level) => func(NoOpTrace.Singleton)); + mockContext.Setup(x => x.Client).Returns(MockCosmosUtil.CreateMockCosmosClient()); + return mockContext; } diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/CosmosClientOptionsUnitTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/CosmosClientOptionsUnitTests.cs index 2feafb1e02..a3e5f44482 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/CosmosClientOptionsUnitTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/CosmosClientOptionsUnitTests.cs @@ -82,7 +82,7 @@ public void VerifyCosmosConfigurationPropertiesGetUpdated() Assert.IsFalse(clientOptions.EnablePartitionLevelFailover); //Verify GetConnectionPolicy returns the correct values for default - ConnectionPolicy policy = clientOptions.GetConnectionPolicy(); + ConnectionPolicy policy = clientOptions.GetConnectionPolicy(clientId: 0); Assert.AreEqual(ConnectionMode.Direct, policy.ConnectionMode); Assert.AreEqual(Protocol.Tcp, policy.ConnectionProtocol); Assert.AreEqual(clientOptions.GatewayModeMaxConnectionLimit, policy.MaxConnectionLimit); @@ -132,7 +132,7 @@ public void VerifyCosmosConfigurationPropertiesGetUpdated() Assert.IsTrue(clientOptions.EnablePartitionLevelFailover); //Verify GetConnectionPolicy returns the correct values - policy = clientOptions.GetConnectionPolicy(); + policy = clientOptions.GetConnectionPolicy(clientId: 0); Assert.AreEqual(region, policy.PreferredLocations[0]); Assert.AreEqual(ConnectionMode.Gateway, policy.ConnectionMode); Assert.AreEqual(Protocol.Https, policy.ConnectionProtocol); @@ -171,7 +171,7 @@ public void VerifyCosmosConfigurationPropertiesGetUpdated() CollectionAssert.AreEqual(preferredLocations.ToArray(), clientOptions.ApplicationPreferredRegions.ToArray()); //Verify GetConnectionPolicy returns the correct values - policy = clientOptions.GetConnectionPolicy(); + policy = clientOptions.GetConnectionPolicy(clientId: 0); Assert.AreEqual(idleTcpConnectionTimeout, policy.IdleTcpConnectionTimeout); Assert.AreEqual(openTcpConnectionTimeout, policy.OpenTcpConnectionTimeout); Assert.AreEqual(maxRequestsPerTcpConnection, policy.MaxRequestsPerTcpConnection); @@ -250,12 +250,12 @@ public void UserAgentContainsEnvironmentInformation() string userAgentSuffix = "testSuffix"; cosmosClientOptions.ApplicationName = userAgentSuffix; Assert.AreEqual(userAgentSuffix, cosmosClientOptions.ApplicationName); - Cosmos.UserAgentContainer userAgentContainer = cosmosClientOptions.CreateUserAgentContainerWithFeatures(); + Cosmos.UserAgentContainer userAgentContainer = cosmosClientOptions.CreateUserAgentContainerWithFeatures(clientId: 0); Assert.AreEqual(userAgentSuffix, userAgentContainer.Suffix); Assert.IsTrue(userAgentContainer.UserAgent.StartsWith(expectedValue)); Assert.IsTrue(userAgentContainer.UserAgent.EndsWith(userAgentSuffix)); - ConnectionPolicy connectionPolicy = cosmosClientOptions.GetConnectionPolicy(); + ConnectionPolicy connectionPolicy = cosmosClientOptions.GetConnectionPolicy(clientId: 0); Assert.AreEqual(userAgentSuffix, connectionPolicy.UserAgentSuffix); Assert.IsTrue(connectionPolicy.UserAgentContainer.UserAgent.StartsWith(expectedValue)); Assert.IsTrue(connectionPolicy.UserAgentContainer.UserAgent.EndsWith(userAgentSuffix)); @@ -389,7 +389,7 @@ public void VerifyCorrectProtocolIsSet() public void VerifyLimitToEndpointSettings() { CosmosClientOptions cosmosClientOptions = new CosmosClientOptions { ApplicationRegion = Regions.EastUS, LimitToEndpoint = true }; - cosmosClientOptions.GetConnectionPolicy(); + cosmosClientOptions.GetConnectionPolicy(clientId: 0); } [TestMethod] @@ -397,7 +397,7 @@ public void VerifyLimitToEndpointSettings() public void VerifyLimitToEndpointSettingsWithPreferredRegions() { CosmosClientOptions cosmosClientOptions = new CosmosClientOptions { ApplicationPreferredRegions = new List() { Regions.EastUS }, LimitToEndpoint = true }; - cosmosClientOptions.GetConnectionPolicy(); + cosmosClientOptions.GetConnectionPolicy(clientId: 0); } [TestMethod] @@ -405,7 +405,7 @@ public void VerifyLimitToEndpointSettingsWithPreferredRegions() public void VerifyApplicationRegionSettingsWithPreferredRegions() { CosmosClientOptions cosmosClientOptions = new CosmosClientOptions { ApplicationPreferredRegions = new List() { Regions.EastUS }, ApplicationRegion = Regions.EastUS }; - cosmosClientOptions.GetConnectionPolicy(); + cosmosClientOptions.GetConnectionPolicy(clientId: 0); } [TestMethod] @@ -438,7 +438,7 @@ public void HttpClientFactoryBuildsConnectionPolicy() CosmosClientOptions clientOptions = cosmosClient.ClientOptions; Assert.AreEqual(clientOptions.HttpClientFactory, this.HttpClientFactoryDelegate); - ConnectionPolicy policy = clientOptions.GetConnectionPolicy(); + ConnectionPolicy policy = clientOptions.GetConnectionPolicy(clientId: 0); Assert.AreEqual(policy.HttpClientFactory, this.HttpClientFactoryDelegate); } @@ -452,7 +452,7 @@ public void WithLimitToEndpointAffectsEndpointDiscovery() CosmosClientOptions cosmosClientOptions = cosmosClientBuilder.Build(new MockDocumentClient()).ClientOptions; Assert.IsFalse(cosmosClientOptions.LimitToEndpoint); - ConnectionPolicy connectionPolicy = cosmosClientOptions.GetConnectionPolicy(); + ConnectionPolicy connectionPolicy = cosmosClientOptions.GetConnectionPolicy(clientId: 0); Assert.IsTrue(connectionPolicy.EnableEndpointDiscovery); cosmosClientBuilder @@ -461,7 +461,7 @@ public void WithLimitToEndpointAffectsEndpointDiscovery() cosmosClientOptions = cosmosClientBuilder.Build(new MockDocumentClient()).ClientOptions; Assert.IsTrue(cosmosClientOptions.LimitToEndpoint); - connectionPolicy = cosmosClientOptions.GetConnectionPolicy(); + connectionPolicy = cosmosClientOptions.GetConnectionPolicy(clientId: 0); Assert.IsFalse(connectionPolicy.EnableEndpointDiscovery); } diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/GatewayAddressCacheTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/GatewayAddressCacheTests.cs index cfaf0f19c2..f063fee427 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/GatewayAddressCacheTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/GatewayAddressCacheTests.cs @@ -130,7 +130,7 @@ public void GlobalAddressResolverUpdateAsyncSynchronizationTest() SynchronizationContext.SetSynchronizationContext(syncContext); syncContext.Post(_ => { - UserAgentContainer container = new UserAgentContainer(); + UserAgentContainer container = new UserAgentContainer(clientId: 0); FakeMessageHandler messageHandler = new FakeMessageHandler(); AccountProperties databaseAccount = new AccountProperties();