コード例 #1
0
        public async Task Run_ShouldThrow_IfObserverThrowsDocumentClientException()
        {
            // If the user code throws a DCE, we should bubble it up to stop the Observer and not treat it as a DCE from the Feed Query

            Mock.Get(documentQuery)
            .Reset();

            Mock.Get(documentQuery)
            .Setup(query => query.ExecuteNextAsync <Document>(It.Is <CancellationToken>(token => token == cancellationTokenSource.Token)))
            .ReturnsAsync(feedResponse)
            .Callback(() => cancellationTokenSource.Cancel());

            Mock.Get(observer)
            .Setup(feedObserver => feedObserver
                   .ProcessChangesAsync(It.IsAny <IChangeFeedObserverContext>(), It.IsAny <IReadOnlyList <Document> >(), It.IsAny <CancellationToken>()))
            .Throws(DocumentExceptionHelpers.CreateRequestRateTooLargeException());

            Exception exception = await Record.ExceptionAsync(() => sut.RunAsync(cancellationTokenSource.Token));

            Assert.IsAssignableFrom <ObserverException>(exception);
            Assert.IsAssignableFrom <DocumentClientException>(exception.InnerException);

            Mock.Get(documentQuery)
            .Verify(query => query.ExecuteNextAsync <Document>(It.Is <CancellationToken>(token => token == cancellationTokenSource.Token)), Times.Once);

            Mock.Get(observer)
            .Verify(feedObserver => feedObserver
                    .ProcessChangesAsync(
                        It.Is <IChangeFeedObserverContext>(context => context.PartitionKeyRangeId == processorSettings.PartitionKeyRangeId),
                        It.Is <IReadOnlyList <Document> >(list => list.SequenceEqual(documents)),
                        It.IsAny <CancellationToken>()),
                    Times.Once);
        }
        public async Task LockInitializationAsync_ShouldThrow_IfLockThrows()
        {
            var client = Mock.Of <IChangeFeedDocumentClient>();

            Mock.Get(client)
            .Setup(c => c.CreateDocumentAsync(It.IsAny <string>(), It.IsAny <object>()))
            .ThrowsAsync(DocumentExceptionHelpers.CreateRequestRateTooLargeException());

            var       leaseStore = new LeaseStore(client, collectionInfo, containerNamePrefix, leaseStoreCollectionLink);
            Exception exception  = await Record.ExceptionAsync(() => leaseStore.LockInitializationAsync(lockTime));

            Assert.IsAssignableFrom <DocumentClientException>(exception);
        }
コード例 #3
0
        public async Task MarkInitializedAsync_ShouldThrow_IfMarkerThrows()
        {
            var client = Mock.Of <IChangeFeedDocumentClient>();

            Mock.Get(client)
            .Setup(c => c.CreateDocumentAsync(It.IsAny <string>(), It.IsAny <object>(), null, false, default(CancellationToken)))
            .ThrowsAsync(DocumentExceptionHelpers.CreateRequestRateTooLargeException());

            var       leaseStore = new DocumentServiceLeaseStore(client, collectionInfo, containerNamePrefix, leaseCollectionLink, Mock.Of <IRequestOptionsFactory>());
            Exception exception  = await Record.ExceptionAsync(async() => await leaseStore.MarkInitializedAsync());

            Assert.IsAssignableFrom <DocumentClientException>(exception);
        }
コード例 #4
0
        public async Task ReleaseInitializationLockAsync_ShouldThrow_IfLockThrows()
        {
            var client = Mock.Of <IChangeFeedDocumentClient>();

            Mock.Get(client)
            .Setup(c => c.DeleteDocumentAsync(It.IsAny <Uri>(), It.IsAny <RequestOptions>(), default(CancellationToken)))
            .ThrowsAsync(DocumentExceptionHelpers.CreateRequestRateTooLargeException());

            var       leaseStore = new DocumentServiceLeaseStore(client, collectionInfo, containerNamePrefix, leaseCollectionLink, Mock.Of <IRequestOptionsFactory>());
            Exception exception  = await Record.ExceptionAsync(() => leaseStore.ReleaseInitializationLockAsync());

            Assert.IsAssignableFrom <DocumentClientException>(exception);
        }
コード例 #5
0
        public async Task Run_ShouldRetry_IfThrottled()
        {
            Mock.Get(documentQuery)
            .SetupSequence(query => query.ExecuteNextAsync <Document>(It.Is <CancellationToken>(token => token == cancellationTokenSource.Token)))
            .Throws(DocumentExceptionHelpers.CreateRequestRateTooLargeException())
            .ReturnsAsync(feedResponse);

            await Assert.ThrowsAsync <TaskCanceledException>(() => partitionProcessor.RunAsync(cancellationTokenSource.Token));

            Mock.Get(documentQuery)
            .Verify(query => query.ExecuteNextAsync <Document>(It.Is <CancellationToken>(token => token == cancellationTokenSource.Token)), Times.Exactly(2));

            Mock.Get(observer)
            .Verify(feedObserver => feedObserver
                    .ProcessChangesAsync(
                        It.Is <ChangeFeedObserverContext>(context => context.PartitionKeyRangeId == processorSettings.PartitionKeyRangeId),
                        It.Is <IReadOnlyList <Document> >(list => list.SequenceEqual(documents)),
                        It.IsAny <CancellationToken>()),
                    Times.Once);
        }
コード例 #6
0
        public async Task ProcessChangesAsync_ShouldThrow_IfObserverThrowsDocumentClientException()
        {
            Mock.Get(observer)
            .SetupSequence(feedObserver => feedObserver
                           .ProcessChangesAsync(It.IsAny <IChangeFeedObserverContext>(), It.IsAny <IReadOnlyList <Document> >(), It.IsAny <CancellationToken>()))
            .Throws(DocumentExceptionHelpers.CreateRequestRateTooLargeException());

            Exception exception = await Record.ExceptionAsync(() => observerWrapper.ProcessChangesAsync(this.changeFeedObserverContext, this.documents, cancellationTokenSource.Token));

            Assert.IsAssignableFrom <ObserverException>(exception);
            Assert.IsAssignableFrom <DocumentClientException>(exception.InnerException);

            Mock.Get(observer)
            .Verify(feedObserver => feedObserver
                    .ProcessChangesAsync(It.IsAny <IChangeFeedObserverContext>(),
                                         It.Is <IReadOnlyList <Document> >(list => list.SequenceEqual(documents)),
                                         It.IsAny <CancellationToken>()
                                         ),
                    Times.Once);
        }