コード例 #1
0
        public async Task RetrierGetsCalledOn413_OnWrite()
        {
            IDocumentClientRetryPolicy retryPolicy1 = new BulkExecutionRetryPolicy(
                GetSplitEnabledContainer(),
                OperationType.Create,
                new ResourceThrottleRetryPolicy(1));

            IDocumentClientRetryPolicy retryPolicy2 = new BulkExecutionRetryPolicy(
                GetSplitEnabledContainer(),
                OperationType.Create,
                new ResourceThrottleRetryPolicy(1));

            ItemBatchOperation operation1 = this.CreateItemBatchOperation();
            ItemBatchOperation operation2 = this.CreateItemBatchOperation();

            operation1.AttachContext(new ItemBatchOperationContext(string.Empty, NoOpTrace.Singleton, retryPolicy1));
            operation2.AttachContext(new ItemBatchOperationContext(string.Empty, NoOpTrace.Singleton, retryPolicy2));

            Mock <BatchAsyncBatcherRetryDelegate> retryDelegate = new Mock <BatchAsyncBatcherRetryDelegate>();

            BatchAsyncBatcher batchAsyncBatcher = new BatchAsyncBatcher(2, 1000, MockCosmosUtil.Serializer, this.ExecutorWith413, retryDelegate.Object, BatchAsyncBatcherTests.MockClientContext());

            Assert.IsTrue(batchAsyncBatcher.TryAdd(operation1));
            Assert.IsTrue(batchAsyncBatcher.TryAdd(operation2));
            await batchAsyncBatcher.DispatchAsync(metric);

            retryDelegate.Verify(a => a(It.Is <ItemBatchOperation>(o => o == operation1), It.IsAny <CancellationToken>()), Times.Never);
            retryDelegate.Verify(a => a(It.Is <ItemBatchOperation>(o => o == operation2), It.IsAny <CancellationToken>()), Times.Never);
            retryDelegate.Verify(a => a(It.IsAny <ItemBatchOperation>(), It.IsAny <CancellationToken>()), Times.Never);
        }
コード例 #2
0
        public async Task RetrierGetsCalledOnCompletingPartitionMigration()
        {
            IDocumentClientRetryPolicy retryPolicy1 = new BulkExecutionRetryPolicy(
                GetSplitEnabledContainer(),
                OperationType.Read,
                new ResourceThrottleRetryPolicy(1));

            IDocumentClientRetryPolicy retryPolicy2 = new BulkExecutionRetryPolicy(
                GetSplitEnabledContainer(),
                OperationType.Read,
                new ResourceThrottleRetryPolicy(1));

            ItemBatchOperation operation1 = this.CreateItemBatchOperation();
            ItemBatchOperation operation2 = this.CreateItemBatchOperation();

            operation1.AttachContext(new ItemBatchOperationContext(string.Empty, retryPolicy1));
            operation2.AttachContext(new ItemBatchOperationContext(string.Empty, retryPolicy2));

            Mock <BatchAsyncBatcherRetryDelegate> retryDelegate = new Mock <BatchAsyncBatcherRetryDelegate>();

            BatchAsyncBatcher batchAsyncBatcher = new BatchAsyncBatcher(2, 1000, MockCosmosUtil.Serializer, this.ExecutorWithCompletingPartitionMigration, retryDelegate.Object);

            Assert.IsTrue(batchAsyncBatcher.TryAdd(operation1));
            Assert.IsTrue(batchAsyncBatcher.TryAdd(operation2));
            await batchAsyncBatcher.DispatchAsync(metric);

            retryDelegate.Verify(a => a(It.Is <ItemBatchOperation>(o => o == operation1), It.IsAny <CancellationToken>()), Times.Once);
            retryDelegate.Verify(a => a(It.Is <ItemBatchOperation>(o => o == operation2), It.IsAny <CancellationToken>()), Times.Once);
            retryDelegate.Verify(a => a(It.IsAny <ItemBatchOperation>(), It.IsAny <CancellationToken>()), Times.Exactly(2));
            Assert.IsNull(operation1.DiagnosticsContext, "Batch operations do not have diagnostics per operation");
            Assert.IsNull(operation2.DiagnosticsContext, "Batch operations do not have diagnostics per operation");
        }
コード例 #3
0
        public async Task RetriesOn413_OnWrite()
        {
            IDocumentClientRetryPolicy retryPolicy = new BulkExecutionRetryPolicy(
                Mock.Of <ContainerInternal>(),
                OperationType.Create,
                new ResourceThrottleRetryPolicy(1));

            TransactionalBatchOperationResult result = new TransactionalBatchOperationResult(HttpStatusCode.RequestEntityTooLarge);
            ShouldRetryResult shouldRetryResult      = await retryPolicy.ShouldRetryAsync(result.ToResponseMessage(), default);

            Assert.IsFalse(shouldRetryResult.ShouldRetry);
        }
コード例 #4
0
        public async Task RetriesOn429()
        {
            IDocumentClientRetryPolicy retryPolicy = new BulkExecutionRetryPolicy(
                Mock.Of <ContainerInternal>(),
                OperationType.Read,
                new ResourceThrottleRetryPolicy(1));

            TransactionalBatchOperationResult result = new TransactionalBatchOperationResult((HttpStatusCode)StatusCodes.TooManyRequests);
            ShouldRetryResult shouldRetryResult      = await retryPolicy.ShouldRetryAsync(result.ToResponseMessage(), default);

            Assert.IsTrue(shouldRetryResult.ShouldRetry);
        }
コード例 #5
0
        public async Task NotRetryOnSuccess()
        {
            IDocumentClientRetryPolicy retryPolicy = new BulkExecutionRetryPolicy(
                Mock.Of <ContainerInternal>(),
                OperationType.Read,
                new ResourceThrottleRetryPolicy(1));

            TransactionalBatchOperationResult result = new TransactionalBatchOperationResult(HttpStatusCode.OK);
            ShouldRetryResult shouldRetryResult      = await retryPolicy.ShouldRetryAsync(result.ToResponseMessage(), default);

            Assert.IsFalse(shouldRetryResult.ShouldRetry);
        }
コード例 #6
0
        public async Task ShouldRetry_WithPolicy_On413_OnWrite()
        {
            IDocumentClientRetryPolicy retryPolicy = new BulkExecutionRetryPolicy(
                Mock.Of <ContainerInternal>(),
                OperationType.Create,
                new ResourceThrottleRetryPolicy(1));
            TransactionalBatchOperationResult result = new TransactionalBatchOperationResult(HttpStatusCode.RequestEntityTooLarge);
            ItemBatchOperation operation             = new ItemBatchOperation(OperationType.Create, 0, Cosmos.PartitionKey.Null);

            operation.AttachContext(new ItemBatchOperationContext(string.Empty, retryPolicy));
            ShouldRetryResult shouldRetryResult = await operation.Context.ShouldRetryAsync(result, default);

            Assert.IsFalse(shouldRetryResult.ShouldRetry);
        }
コード例 #7
0
        public async Task ShouldRetry_WithPolicy_On429()
        {
            IDocumentClientRetryPolicy retryPolicy = new BulkExecutionRetryPolicy(
                Mock.Of <ContainerInternal>(),
                OperationType.Read,
                new ResourceThrottleRetryPolicy(1));
            TransactionalBatchOperationResult result = new TransactionalBatchOperationResult((HttpStatusCode)StatusCodes.TooManyRequests);
            ItemBatchOperation operation             = new ItemBatchOperation(OperationType.Create, 0, Cosmos.PartitionKey.Null);

            operation.AttachContext(new ItemBatchOperationContext(string.Empty, NoOpTrace.Singleton, retryPolicy));
            ShouldRetryResult shouldRetryResult = await operation.Context.ShouldRetryAsync(result, default);

            Assert.IsTrue(shouldRetryResult.ShouldRetry);
        }
コード例 #8
0
        public async Task RetriesOnSplits()
        {
            IDocumentClientRetryPolicy retryPolicy = new BulkExecutionRetryPolicy(
                GetSplitEnabledContainer(),
                OperationType.Read,
                new ResourceThrottleRetryPolicy(1));

            TransactionalBatchOperationResult result = new TransactionalBatchOperationResult(HttpStatusCode.Gone)
            {
                SubStatusCode = SubStatusCodes.PartitionKeyRangeGone
            };
            ShouldRetryResult shouldRetryResult = await retryPolicy.ShouldRetryAsync(result.ToResponseMessage(), default);

            Assert.IsTrue(shouldRetryResult.ShouldRetry);
        }
コード例 #9
0
        public async Task ShouldRetry_WithPolicy_OnCompletingPartitionMigration()
        {
            IDocumentClientRetryPolicy retryPolicy = new BulkExecutionRetryPolicy(
                GetSplitEnabledContainer(),
                OperationType.Read,
                new ResourceThrottleRetryPolicy(1));
            TransactionalBatchOperationResult result = new TransactionalBatchOperationResult(HttpStatusCode.Gone)
            {
                SubStatusCode = SubStatusCodes.CompletingPartitionMigration
            };
            ItemBatchOperation operation = new ItemBatchOperation(OperationType.Create, 0, Cosmos.PartitionKey.Null);

            operation.AttachContext(new ItemBatchOperationContext(string.Empty, retryPolicy));
            ShouldRetryResult shouldRetryResult = await operation.Context.ShouldRetryAsync(result, default);

            Assert.IsTrue(shouldRetryResult.ShouldRetry);
        }
コード例 #10
0
        public async Task TraceIsJoinedOnCompletionWithRetry()
        {
            IDocumentClientRetryPolicy retryPolicy = new BulkExecutionRetryPolicy(
                Mock.Of <ContainerInternal>(),
                OperationType.Read,
                new ResourceThrottleRetryPolicy(1));

            Trace rootTrace = Trace.GetRootTrace(name: "RootTrace");

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

            // Start with the base trace
            ItemBatchOperationContext batchAsyncOperationContext = new ItemBatchOperationContext(Guid.NewGuid().ToString(), rootTrace, retryPolicy);

            operation.AttachContext(batchAsyncOperationContext);

            // Simulate a retry scenario that should append to the context traces
            Trace retryTrace = Trace.GetRootTrace(name: "TransportTrace");
            TransactionalBatchOperationResult retryResult = new TransactionalBatchOperationResult(HttpStatusCode.TooManyRequests)
            {
                Trace = retryTrace
            };
            ShouldRetryResult shouldRetryResult = await batchAsyncOperationContext.ShouldRetryAsync(retryResult, default);

            Assert.IsTrue(shouldRetryResult.ShouldRetry);

            // Simulate the completion that should append to the context traces
            Trace transportTrace = Trace.GetRootTrace(name: "TransportTrace");
            TransactionalBatchOperationResult result = new TransactionalBatchOperationResult(HttpStatusCode.OK)
            {
                Trace = transportTrace
            };

            batchAsyncOperationContext.Complete(null, result);

            Assert.AreEqual(result, await batchAsyncOperationContext.OperationTask);
            Assert.AreEqual(2, result.Trace.Children.Count, "The final trace should have the initial trace, plus the retries, plus the final trace");
            Assert.AreEqual(rootTrace, result.Trace, "The first trace child should be the initial root");
            Assert.AreEqual(retryTrace, result.Trace.Children[0], "The second trace child should be the one from the retry");
            Assert.AreEqual(transportTrace, result.Trace.Children[1], "The third trace child should be the one from the final result");
        }