예제 #1
0
        public async Task DiagnosticsAreSetThroughResponseAsync()
        {
            List <TransactionalBatchOperationResult> results = new List <TransactionalBatchOperationResult>();

            ItemBatchOperation[] arrayOperations = new ItemBatchOperation[1];

            ItemBatchOperation operation = new ItemBatchOperation(OperationType.Read, 0, Cosmos.PartitionKey.Null, "0");

            results.Add(
                new TransactionalBatchOperationResult(HttpStatusCode.OK)
            {
                ResourceStream = new MemoryStream(new byte[] { 0x41, 0x42 }, index: 0, count: 2, writable: false, publiclyVisible: true),
                ETag           = operation.Id
            });

            arrayOperations[0] = operation;

            MemoryStream responseContent = await new BatchResponsePayloadWriter(results).GeneratePayloadAsync();

            SinglePartitionKeyServerBatchRequest batchRequest = await SinglePartitionKeyServerBatchRequest.CreateAsync(
                partitionKey : null,
                operations : new ArraySegment <ItemBatchOperation>(arrayOperations),
                serializerCore : MockCosmosUtil.Serializer,
                cancellationToken : default(CancellationToken));

            PointOperationStatistics diagnostics = new PointOperationStatistics(
                activityId: Guid.NewGuid().ToString(),
                statusCode: HttpStatusCode.OK,
                subStatusCode: SubStatusCodes.Unknown,
                responseTimeUtc: DateTime.UtcNow,
                requestCharge: 0,
                errorMessage: string.Empty,
                method: HttpMethod.Get,
                requestUri: "http://localhost",
                requestSessionToken: null,
                responseSessionToken: null);

            ResponseMessage responseMessage = new ResponseMessage(HttpStatusCode.OK)
            {
                Content = responseContent,
            };

            responseMessage.DiagnosticsContext.AddDiagnosticsInternal(diagnostics);

            TransactionalBatchResponse batchresponse = await TransactionalBatchResponse.FromResponseMessageAsync(
                responseMessage,
                batchRequest,
                MockCosmosUtil.Serializer,
                true,
                CancellationToken.None);

            PartitionKeyRangeBatchResponse response = new PartitionKeyRangeBatchResponse(arrayOperations.Length, batchresponse, MockCosmosUtil.Serializer);

            string pointDiagnosticString = diagnostics.ToString();

            pointDiagnosticString = pointDiagnosticString.Substring(1, pointDiagnosticString.Length - 2);
            string diagnosticContextString = response.DiagnosticsContext.ToString();

            Assert.IsTrue(diagnosticContextString.Contains(pointDiagnosticString));
        }
        public async Task DiagnosticsAreSetThroughResponseAsync()
        {
            List <TransactionalBatchOperationResult> results = new List <TransactionalBatchOperationResult>();

            ItemBatchOperation[] arrayOperations = new ItemBatchOperation[1];

            ItemBatchOperation operation = new ItemBatchOperation(OperationType.AddComputeGatewayRequestCharges, 0, "0");

            results.Add(
                new TransactionalBatchOperationResult(HttpStatusCode.OK)
            {
                ResourceStream = new MemoryStream(new byte[] { 0x41, 0x42 }, index: 0, count: 2, writable: false, publiclyVisible: true),
                ETag           = operation.Id
            });

            arrayOperations[0] = operation;

            MemoryStream responseContent = await new BatchResponsePayloadWriter(results).GeneratePayloadAsync();

            SinglePartitionKeyServerBatchRequest batchRequest = await SinglePartitionKeyServerBatchRequest.CreateAsync(
                partitionKey : null,
                operations : new ArraySegment <ItemBatchOperation>(arrayOperations),
                serializerCore : MockCosmosUtil.Serializer,
                cancellationToken : default(CancellationToken));

            CosmosDiagnostics diagnostics = new PointOperationStatistics(
                activityId: Guid.NewGuid().ToString(),
                statusCode: HttpStatusCode.OK,
                subStatusCode: SubStatusCodes.Unknown,
                requestCharge: 0,
                errorMessage: string.Empty,
                method: HttpMethod.Get,
                requestUri: new Uri("http://localhost"),
                requestSessionToken: null,
                responseSessionToken: null,
                clientSideRequestStatistics: new CosmosClientSideRequestStatistics());

            TransactionalBatchResponse batchresponse = await TransactionalBatchResponse.FromResponseMessageAsync(
                new ResponseMessage(HttpStatusCode.OK) { Content = responseContent, Diagnostics = diagnostics },
                batchRequest,
                MockCosmosUtil.Serializer);

            PartitionKeyRangeBatchResponse response = new PartitionKeyRangeBatchResponse(arrayOperations.Length, batchresponse, MockCosmosUtil.Serializer);

            Assert.AreEqual(diagnostics, response.Diagnostics);
        }
        public void ToString_ReturnItemsToString()
        {
            ItemBatchOperationStatistics itemBatchOperationStatistics = new ItemBatchOperationStatistics();

            CosmosClientSideRequestStatistics cosmosClientSideRequestStatistics1 = new CosmosClientSideRequestStatistics();

            cosmosClientSideRequestStatistics1.ContactedReplicas.Add(new Uri("https://one.com"));
            PointOperationStatistics pointOperation1 = new PointOperationStatistics(
                activityId: Guid.NewGuid().ToString(),
                statusCode: HttpStatusCode.OK,
                subStatusCode: SubStatusCodes.Unknown,
                requestCharge: 0,
                errorMessage: string.Empty,
                method: HttpMethod.Get,
                requestUri: new Uri("http://localhost"),
                requestSessionToken: null,
                responseSessionToken: null,
                clientSideRequestStatistics: cosmosClientSideRequestStatistics1);

            CosmosClientSideRequestStatistics cosmosClientSideRequestStatistics2 = new CosmosClientSideRequestStatistics();

            cosmosClientSideRequestStatistics2.ContactedReplicas.Add(new Uri("https://two.com"));
            PointOperationStatistics pointOperation2 = new PointOperationStatistics(
                activityId: Guid.NewGuid().ToString(),
                statusCode: HttpStatusCode.OK,
                subStatusCode: SubStatusCodes.Unknown,
                requestCharge: 0,
                errorMessage: string.Empty,
                method: HttpMethod.Get,
                requestUri: new Uri("http://localhost"),
                requestSessionToken: null,
                responseSessionToken: null,
                clientSideRequestStatistics: cosmosClientSideRequestStatistics2);

            itemBatchOperationStatistics.AppendDiagnostics(pointOperation1);
            itemBatchOperationStatistics.AppendDiagnostics(pointOperation2);

            string toString = itemBatchOperationStatistics.ToString();

            Assert.IsTrue(toString.Contains(pointOperation1.ToString()));
            Assert.IsTrue(toString.Contains(pointOperation2.ToString()));
        }
예제 #4
0
        public void Complete_AddsCompleteTime()
        {
            ItemBatchOperationStatistics itemBatchOperationStatistics = new ItemBatchOperationStatistics();

            CosmosClientSideRequestStatistics cosmosClientSideRequestStatistics1 = new CosmosClientSideRequestStatistics();

            cosmosClientSideRequestStatistics1.ContactedReplicas.Add(new Uri("https://one.com"));
            PointOperationStatistics pointOperation1 = new PointOperationStatistics(Guid.NewGuid().ToString(), HttpStatusCode.OK, SubStatusCodes.Unknown, 0, string.Empty, HttpMethod.Get, new Uri("http://localhost"), cosmosClientSideRequestStatistics1);

            CosmosClientSideRequestStatistics cosmosClientSideRequestStatistics2 = new CosmosClientSideRequestStatistics();

            cosmosClientSideRequestStatistics2.ContactedReplicas.Add(new Uri("https://two.com"));
            PointOperationStatistics pointOperation2 = new PointOperationStatistics(Guid.NewGuid().ToString(), HttpStatusCode.OK, SubStatusCodes.Unknown, 0, string.Empty, HttpMethod.Get, new Uri("http://localhost"), cosmosClientSideRequestStatistics2);

            itemBatchOperationStatistics.AppendDiagnostics(pointOperation1);
            itemBatchOperationStatistics.AppendDiagnostics(pointOperation2);
            itemBatchOperationStatistics.Complete();

            Assert.IsTrue(itemBatchOperationStatistics.ToString().Contains("Completed at"));
        }
        public void ToResponseMessage_MapsProperties()
        {
            PointOperationStatistics pointOperationStatistics = new PointOperationStatistics(
                activityId: Guid.NewGuid().ToString(),
                statusCode: HttpStatusCode.OK,
                subStatusCode: SubStatusCodes.Unknown,
                responseTimeUtc: DateTime.UtcNow,
                requestCharge: 0,
                errorMessage: string.Empty,
                method: HttpMethod.Get,
                requestUri: "http://localhost",
                requestSessionToken: null,
                responseSessionToken: null);
            CosmosDiagnosticsContext context = new CosmosDiagnosticsContextCore();

            context.AddDiagnosticsInternal(pointOperationStatistics);

            TransactionalBatchOperationResult result = new TransactionalBatchOperationResult(HttpStatusCode.OK)
            {
                ResourceStream     = new MemoryStream(new byte[] { 0x41, 0x42 }, index: 0, count: 2, writable: false, publiclyVisible: true),
                ETag               = "1234",
                SubStatusCode      = SubStatusCodes.CompletingSplit,
                RetryAfter         = TimeSpan.FromSeconds(10),
                RequestCharge      = 4.3,
                DiagnosticsContext = context
            };

            ResponseMessage response = result.ToResponseMessage();

            Assert.AreEqual(result.ResourceStream, response.Content);
            Assert.AreEqual(result.SubStatusCode, response.Headers.SubStatusCode);
            Assert.AreEqual(result.RetryAfter, response.Headers.RetryAfter);
            Assert.AreEqual(result.StatusCode, response.StatusCode);
            Assert.AreEqual(result.RequestCharge, response.Headers.RequestCharge);
            string diagnostics = response.Diagnostics.ToString();

            Assert.IsNotNull(diagnostics);
            Assert.IsTrue(diagnostics.Contains(pointOperationStatistics.ActivityId));
        }
예제 #6
0
        public void ToString_ReturnItemsToString()
        {
            ItemBatchOperationStatistics itemBatchOperationStatistics = new ItemBatchOperationStatistics();

            CosmosClientSideRequestStatistics cosmosClientSideRequestStatistics1 = new CosmosClientSideRequestStatistics();

            cosmosClientSideRequestStatistics1.ContactedReplicas.Add(new Uri("https://one.com"));
            PointOperationStatistics pointOperation1 = new PointOperationStatistics(HttpStatusCode.OK, SubStatusCodes.Unknown, 0, string.Empty, HttpMethod.Get, new Uri("http://localhost"), cosmosClientSideRequestStatistics1);

            CosmosClientSideRequestStatistics cosmosClientSideRequestStatistics2 = new CosmosClientSideRequestStatistics();

            cosmosClientSideRequestStatistics2.ContactedReplicas.Add(new Uri("https://two.com"));
            PointOperationStatistics pointOperation2 = new PointOperationStatistics(HttpStatusCode.OK, SubStatusCodes.Unknown, 0, string.Empty, HttpMethod.Get, new Uri("http://localhost"), cosmosClientSideRequestStatistics2);

            itemBatchOperationStatistics.AppendDiagnostics(pointOperation1);
            itemBatchOperationStatistics.AppendDiagnostics(pointOperation2);

            string toString = itemBatchOperationStatistics.ToString();

            Assert.IsTrue(toString.Contains(pointOperation1.ToString()));
            Assert.IsTrue(toString.Contains(pointOperation2.ToString()));
        }
        public async Task DiagnosticsAreSetThroughResponseAsync()
        {
            List <BatchOperationResult> results = new List <BatchOperationResult>();

            ItemBatchOperation[] arrayOperations = new ItemBatchOperation[1];

            ItemBatchOperation operation = new ItemBatchOperation(OperationType.AddComputeGatewayRequestCharges, 0, "0");

            results.Add(
                new BatchOperationResult(HttpStatusCode.OK)
            {
                ResourceStream = new MemoryStream(new byte[] { 0x41, 0x42 }, index: 0, count: 2, writable: false, publiclyVisible: true),
                ETag           = operation.Id
            });

            arrayOperations[0] = operation;

            MemoryStream responseContent = await new BatchResponsePayloadWriter(results).GeneratePayloadAsync();

            SinglePartitionKeyServerBatchRequest batchRequest = await SinglePartitionKeyServerBatchRequest.CreateAsync(
                partitionKey : null,
                operations : new ArraySegment <ItemBatchOperation>(arrayOperations),
                maxBodyLength : 100,
                maxOperationCount : 1,
                serializer : new CosmosJsonDotNetSerializer(),
                cancellationToken : default(CancellationToken));

            CosmosDiagnostics diagnostics = new PointOperationStatistics(HttpStatusCode.OK, SubStatusCodes.Unknown, 0, string.Empty, HttpMethod.Get, new Uri("http://localhost"), new CosmosClientSideRequestStatistics());

            BatchResponse batchresponse = await BatchResponse.PopulateFromContentAsync(
                new ResponseMessage(HttpStatusCode.OK) { Content = responseContent, Diagnostics = diagnostics },
                batchRequest,
                new CosmosJsonDotNetSerializer());

            PartitionKeyRangeBatchResponse response = new PartitionKeyRangeBatchResponse(arrayOperations.Length, batchresponse, new CosmosJsonDotNetSerializer());

            Assert.AreEqual(diagnostics, response.Diagnostics);
        }
 public abstract TResult Visit(PointOperationStatistics pointOperationStatistics);
예제 #9
0
 public abstract void Visit(PointOperationStatistics pointOperationStatistics);