public GatewayStoreClient( CosmosHttpClient httpClient, ICommunicationEventSource eventSource, JsonSerializerSettings serializerSettings = null) { this.httpClient = httpClient; this.SerializerSettings = serializerSettings; this.eventSource = eventSource; }
// Backlog: Auth abstractions are spilling through. 4 arguments for this CTOR are result of it. public GatewayAccountReader(Uri serviceEndpoint, AuthorizationTokenProvider cosmosAuthorization, ConnectionPolicy connectionPolicy, CosmosHttpClient httpClient) { this.httpClient = httpClient; this.serviceEndpoint = serviceEndpoint; this.cosmosAuthorization = cosmosAuthorization ?? throw new ArgumentNullException(nameof(AuthorizationTokenProvider)); this.connectionPolicy = connectionPolicy; }
public GatewayAccountReader(Uri serviceEndpoint, IComputeHash stringHMACSHA256Helper, bool hasResourceToken, string resourceToken, ConnectionPolicy connectionPolicy, CosmosHttpClient httpClient) { this.httpClient = httpClient; this.serviceEndpoint = serviceEndpoint; this.authKeyHashFunction = stringHMACSHA256Helper; this.hasAuthKeyResourceToken = hasResourceToken; this.authKeyResourceToken = resourceToken; this.connectionPolicy = connectionPolicy; }
public GatewayStoreModel( GlobalEndpointManager endpointManager, ISessionContainer sessionContainer, ConsistencyLevel defaultConsistencyLevel, DocumentClientEventSource eventSource, JsonSerializerSettings serializerSettings, CosmosHttpClient httpClient) { this.endpointManager = endpointManager; this.sessionContainer = sessionContainer; this.defaultConsistencyLevel = defaultConsistencyLevel; this.eventSource = eventSource; this.gatewayStoreClient = new GatewayStoreClient( httpClient, this.eventSource, serializerSettings); }
public async Task GatewayStatsDurationTest() { bool failedOnce = false; Func <HttpRequestMessage, Task <HttpResponseMessage> > sendFunc = async request => { await Task.Delay(1000); if (!failedOnce) { failedOnce = true; throw new OperationCanceledException(); } return(new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent("Response") }); }; HttpMessageHandler mockMessageHandler = new MockMessageHandler(sendFunc); CosmosHttpClient cosmosHttpClient = MockCosmosUtil.CreateCosmosHttpClient(() => new HttpClient(mockMessageHandler), DocumentClientEventSource.Instance); Tracing.TraceData.ClientSideRequestStatisticsTraceDatum clientSideRequestStatistics = new Tracing.TraceData.ClientSideRequestStatisticsTraceDatum(DateTime.UtcNow); await cosmosHttpClient.SendHttpAsync(() => new ValueTask <HttpRequestMessage>(new HttpRequestMessage(HttpMethod.Get, "http://someuri.com")), ResourceType.Document, HttpTimeoutPolicyDefault.Instance, clientSideRequestStatistics, CancellationToken.None); Assert.AreEqual(clientSideRequestStatistics.HttpResponseStatisticsList.Count, 2); // The duration is calculated using date times which can cause the duration to be slightly off. This allows for up to 15 Ms of variance. // https://stackoverflow.com/questions/2143140/c-sharp-datetime-now-precision#:~:text=The%20precision%20is%20related%20to,35%2D40%20ms%20accuracy Assert.IsTrue(clientSideRequestStatistics.HttpResponseStatisticsList[0].Duration.TotalMilliseconds >= 985, $"First request did was not delayed by at least 1 second. {JsonConvert.SerializeObject(clientSideRequestStatistics.HttpResponseStatisticsList[0])}"); Assert.IsTrue(clientSideRequestStatistics.HttpResponseStatisticsList[1].Duration.TotalMilliseconds >= 985, $"Second request did was not delayed by at least 1 second. {JsonConvert.SerializeObject(clientSideRequestStatistics.HttpResponseStatisticsList[1])}"); Assert.IsTrue(clientSideRequestStatistics.HttpResponseStatisticsList[0].RequestStartTime < clientSideRequestStatistics.HttpResponseStatisticsList[1].RequestStartTime); }
public async Task DocumentClient_BuildHttpClientFactory_WithHandler() { HttpMessageHandler messageHandler = new CustomMessageHandler(); ConnectionPolicy connectionPolicy = new ConnectionPolicy() { HttpClientFactory = () => new HttpClient(messageHandler) }; CosmosHttpClient httpClient = CosmosHttpClientCore.CreateWithConnectionPolicy( apiType: ApiType.None, eventSource: DocumentClientEventSource.Instance, connectionPolicy: connectionPolicy, httpMessageHandler: null, sendingRequestEventArgs: null, receivedResponseEventArgs: null); Assert.IsNotNull(httpClient); HttpResponseMessage response = await httpClient.GetAsync( uri : new Uri("https://localhost"), additionalHeaders : new DictionaryNameValueCollection(), resourceType : ResourceType.Document, diagnosticsContext : null, cancellationToken : default);