public async Task StartFromTimeAsync(bool useContinuations)
        {
            int numItems = 100;
            IDocumentContainer documentContainer = await CreateDocumentContainerAsync(numItems);
            CrossPartitionChangeFeedAsyncEnumerator enumerator = CrossPartitionChangeFeedAsyncEnumerator.Create(
                documentContainer,
                new CrossFeedRangeState<ChangeFeedState>(
                    new FeedRangeState<ChangeFeedState>[]
                    {
                        new FeedRangeState<ChangeFeedState>(FeedRangeEpk.FullRange, ChangeFeedState.Time(DateTime.UtcNow))
                    }),
                ChangeFeedPaginationOptions.Default,
                cancellationToken: default);

            for (int i = 0; i < numItems; i++)
            {
                // Insert an item
                CosmosObject item = CosmosObject.Parse($"{{\"pk\" : {i} }}");
                while (true)
                {
                    TryCatch<Record> monadicCreateRecord = await documentContainer.MonadicCreateItemAsync(item, cancellationToken: default);
                    if (monadicCreateRecord.Succeeded)
                    {
                        break;
                    }
                }
            }

            (int globalCount, double _) = await (useContinuations
                ? DrainWithUntilNotModifiedWithContinuationTokens(documentContainer, enumerator)
                : DrainUntilNotModifedAsync(enumerator));

            Assert.AreEqual(numItems, globalCount);
        }
Beispiel #2
0
        public static ChangeFeedCrossFeedRangeState CreateFromTime(DateTime dateTimeUtc, FeedRange feedRange)
        {
            if (!(feedRange is FeedRangeInternal feedRangeInternal))
            {
                throw new ArgumentException($"{nameof(feedRange)} needs to be a {nameof(FeedRangeInternal)}.");
            }

            return(new ChangeFeedCrossFeedRangeState(
                       new List <FeedRangeState <ChangeFeedState> >()
            {
                new FeedRangeState <ChangeFeedState>(feedRangeInternal, ChangeFeedState.Time(dateTimeUtc))
            }));
        }
Beispiel #3
0
        public void Time()
        {
            DateTime                   startTime     = DateTime.MinValue.ToUniversalTime();
            ChangeFeedState            time          = ChangeFeedState.Time(startTime);
            CosmosElement              cosmosElement = ChangeFeedStateCosmosElementSerializer.ToCosmosElement(time);
            TryCatch <ChangeFeedState> monadicState  = ChangeFeedStateCosmosElementSerializer.MonadicFromCosmosElement(cosmosElement);

            Assert.IsTrue(monadicState.Succeeded);
            if (!(monadicState.Result is ChangeFeedStateTime stateTime))
            {
                Assert.Fail();
                return;
            }

            Assert.AreEqual(stateTime.StartTime, startTime);
        }