コード例 #1
0
        public async Task TryCheckpoint_OnSuccess()
        {
            string          leaseToken      = Guid.NewGuid().ToString();
            string          continuation    = Guid.NewGuid().ToString();
            ResponseMessage responseMessage = new ResponseMessage(HttpStatusCode.OK);

            responseMessage.Headers.ContinuationToken = continuation;
            Mock <PartitionCheckpointer> checkpointer = new Mock <PartitionCheckpointer>();

            checkpointer.Setup(c => c.CheckpointPartitionAsync(It.Is <string>(s => s == continuation))).Returns(Task.CompletedTask);
            ChangeFeedObserverContextCore changeFeedObserverContextCore = new ChangeFeedObserverContextCore(leaseToken, responseMessage, checkpointer.Object);

            (bool isSuccess, Exception exception) = await changeFeedObserverContextCore.TryCheckpointAsync();

            Assert.IsTrue(isSuccess);
            Assert.IsNull(exception);
        }
コード例 #2
0
        public async Task TryCheckpoint_OnLeaseLost()
        {
            string          leaseToken      = Guid.NewGuid().ToString();
            string          continuation    = Guid.NewGuid().ToString();
            ResponseMessage responseMessage = new ResponseMessage(HttpStatusCode.OK);

            responseMessage.Headers.ContinuationToken = continuation;
            Mock <PartitionCheckpointer> checkpointer = new Mock <PartitionCheckpointer>();

            checkpointer.Setup(c => c.CheckpointPartitionAsync(It.Is <string>(s => s == continuation))).ThrowsAsync(new LeaseLostException());
            ChangeFeedObserverContextCore changeFeedObserverContextCore = new ChangeFeedObserverContextCore(leaseToken, responseMessage, checkpointer.Object);

            (bool isSuccess, Exception exception) = await changeFeedObserverContextCore.TryCheckpointAsync();

            Assert.IsFalse(isSuccess);
            Assert.IsNotNull(exception);
            Assert.AreEqual(HttpStatusCode.PreconditionFailed, (exception as CosmosException).StatusCode);
        }
コード例 #3
0
        public async Task TryCheckpoint_OnUnknownException()
        {
            NotImplementedException cosmosException = new NotImplementedException();
            string          leaseToken      = Guid.NewGuid().ToString();
            string          continuation    = Guid.NewGuid().ToString();
            ResponseMessage responseMessage = new ResponseMessage(HttpStatusCode.OK);

            responseMessage.Headers.ContinuationToken = continuation;
            Mock <PartitionCheckpointer> checkpointer = new Mock <PartitionCheckpointer>();

            checkpointer.Setup(c => c.CheckpointPartitionAsync(It.Is <string>(s => s == continuation))).ThrowsAsync(cosmosException);
            ChangeFeedObserverContextCore changeFeedObserverContextCore = new ChangeFeedObserverContextCore(leaseToken, responseMessage, checkpointer.Object);

            (bool isSuccess, Exception exception) = await changeFeedObserverContextCore.TryCheckpointAsync();

            Assert.IsFalse(isSuccess);
            Assert.IsNotNull(exception);
            Assert.ReferenceEquals(cosmosException, exception);
        }