public GatewayAddressCache( Uri serviceEndpoint, Protocol protocol, IAuthorizationTokenProvider tokenProvider, UserAgentContainer userAgent, IServiceConfigurationReader serviceConfigReader, long suboptimalPartitionForceRefreshIntervalInSeconds = 600, HttpMessageHandler messageHandler = null, ApiType apiType = ApiType.None) { this.addressEndpoint = new Uri(serviceEndpoint + "/" + Paths.AddressPathSegment); this.protocol = protocol; this.tokenProvider = tokenProvider; this.serviceEndpoint = serviceEndpoint; this.serviceConfigReader = serviceConfigReader; this.serverPartitionAddressCache = new AsyncCache <PartitionKeyRangeIdentity, PartitionAddressInformation>(); this.suboptimalServerPartitionTimestamps = new ConcurrentDictionary <PartitionKeyRangeIdentity, DateTime>(); this.suboptimalMasterPartitionTimestamp = DateTime.MaxValue; this.suboptimalPartitionForceRefreshIntervalInSeconds = suboptimalPartitionForceRefreshIntervalInSeconds; this.httpClient = messageHandler == null ? new HttpClient() : new HttpClient(messageHandler); this.protocolFilter = string.Format(CultureInfo.InvariantCulture, GatewayAddressCache.protocolFilterFormat, Constants.Properties.Protocol, GatewayAddressCache.ProtocolString(this.protocol)); // Set requested API version header for version enforcement. this.httpClient.DefaultRequestHeaders.Add(HttpConstants.HttpHeaders.Version, HttpConstants.Versions.CurrentVersion); this.httpClient.AddUserAgentHeader(userAgent); this.httpClient.AddApiTypeHeader(apiType); }
public GlobalAddressResolver( GlobalEndpointManager endpointManager, Protocol protocol, IAuthorizationTokenProvider tokenProvider, CollectionCache collectionCache, PartitionKeyRangeCache routingMapProvider, UserAgentContainer userAgentContainer, IServiceConfigurationReader serviceConfigReader, HttpMessageHandler messageHandler, ConnectionPolicy connectionPolicy, ApiType apiType) { this.endpointManager = endpointManager; this.protocol = protocol; this.tokenProvider = tokenProvider; this.userAgentContainer = userAgentContainer; this.collectionCache = collectionCache; this.routingMapProvider = routingMapProvider; this.serviceConfigReader = serviceConfigReader; this.messageHandler = messageHandler; this.requestTimeout = connectionPolicy.RequestTimeout; this.apiType = apiType; int maxBackupReadEndpoints = !connectionPolicy.EnableReadRequestsFallback.HasValue || connectionPolicy.EnableReadRequestsFallback.Value ? GlobalAddressResolver.MaxBackupReadRegions : 0; this.enableTcpConnectionEndpointRediscovery = connectionPolicy.EnableTcpConnectionEndpointRediscovery; this.maxEndpoints = maxBackupReadEndpoints + 2; // for write and alternate write endpoint (during failover) this.addressCacheByEndpoint = new ConcurrentDictionary <Uri, EndpointCache>(); foreach (Uri endpoint in endpointManager.WriteEndpoints) { this.GetOrAddEndpoint(endpoint); } foreach (Uri endpoint in endpointManager.ReadEndpoints) { this.GetOrAddEndpoint(endpoint); } }
public void UserAgentContainsEnvironmentInformation() { EnvironmentInformation environmentInformation = new EnvironmentInformation(); string expectedValue = "cosmos-netstandard-sdk/" + environmentInformation.ClientVersion; CosmosClientOptions cosmosClientOptions = new CosmosClientOptions(); string userAgentSuffix = "testSuffix"; cosmosClientOptions.ApplicationName = userAgentSuffix; Assert.AreEqual(userAgentSuffix, cosmosClientOptions.ApplicationName); UserAgentContainer userAgentContainer = cosmosClientOptions.BuildUserAgentContainer(); Assert.AreEqual(userAgentSuffix, userAgentContainer.Suffix); Assert.IsTrue(userAgentContainer.UserAgent.StartsWith(expectedValue)); Assert.IsTrue(userAgentContainer.UserAgent.EndsWith(userAgentSuffix)); ConnectionPolicy connectionPolicy = cosmosClientOptions.GetConnectionPolicy(); Assert.AreEqual(userAgentSuffix, connectionPolicy.UserAgentSuffix); Assert.IsTrue(connectionPolicy.UserAgentContainer.UserAgent.StartsWith(expectedValue)); Assert.IsTrue(connectionPolicy.UserAgentContainer.UserAgent.EndsWith(userAgentSuffix)); }