Example #1
0
            public async Task TestSplitAsync()
            {
                int numItems = 100;
                IDocumentContainer documentContainer = await this.CreateDocumentContainerAsync(numItems);

                IAsyncEnumerator <TryCatch <QueryPage> > enumerator = this.CreateEnumerator(documentContainer);

                (HashSet <string> parentIdentifiers, QueryState state) = await this.PartialDrainAsync(enumerator, numIterations : 3);

                // Split the partition
                await documentContainer.SplitAsync(new FeedRangePartitionKeyRange("0"), cancellationToken : default);

                // Try To read from the partition that is gone.
                await enumerator.MoveNextAsync();

                Assert.IsTrue(enumerator.Current.Failed);

                // Resume on the children using the parent continuaiton token
                HashSet <string> childIdentifiers = new HashSet <string>();

                await documentContainer.RefreshProviderAsync(NoOpTrace.Singleton, cancellationToken : default);

                List <FeedRangeEpk> ranges = await documentContainer.GetFeedRangesAsync(
                    trace : NoOpTrace.Singleton,
                    cancellationToken : default);
            public async Task TestSplitAsync()
            {
                int numItems = 100;
                IDocumentContainer inMemoryCollection = await this.CreateDocumentContainerAsync(numItems);

                IAsyncEnumerator <TryCatch <ReadFeedPage> > enumerator = this.CreateEnumerator(inMemoryCollection);

                (HashSet <string> parentIdentifiers, ReadFeedState state) = await this.PartialDrainAsync(enumerator, numIterations : 3);

                // Split the partition
                await inMemoryCollection.SplitAsync(new FeedRangePartitionKeyRange(partitionKeyRangeId : "0"), cancellationToken : default);

                // Try To read from the partition that is gone.
                await enumerator.MoveNextAsync();

                Assert.IsTrue(enumerator.Current.Failed);

                // Resume on the children using the parent continuaiton token
                HashSet <string> childIdentifiers = new HashSet <string>();

                foreach (int partitionKeyRangeId in new int[] { 1, 2 })
                {
                    PartitionRangePageAsyncEnumerable <ReadFeedPage, ReadFeedState> enumerable = new PartitionRangePageAsyncEnumerable <ReadFeedPage, ReadFeedState>(
                        range: new FeedRangePartitionKeyRange(partitionKeyRangeId: partitionKeyRangeId.ToString()),
                        state: state,
                        (range, state) => new ReadFeedPartitionRangeEnumerator(
                            inMemoryCollection,
                            feedRange: range,
                            pageSize: 10,
                            queryRequestOptions: default,
            public async Task TestSplitAsync(bool aggressivePrefetch, bool exercisePrefetch)
            {
                int numItems = 100;
                IDocumentContainer inMemoryCollection = await this.CreateDocumentContainerAsync(numItems);

                IAsyncEnumerator <TryCatch <ReadFeedPage> > enumerator = await this.CreateEnumeratorAsync(inMemoryCollection, aggressivePrefetch, exercisePrefetch);

                (HashSet <string> parentIdentifiers, ReadFeedState state) = await this.PartialDrainAsync(enumerator, numIterations : 3);

                // Split the partition
                await inMemoryCollection.SplitAsync(new FeedRangePartitionKeyRange(partitionKeyRangeId : "0"), cancellationToken : default);

                // Try To read from the partition that is gone.
                await enumerator.MoveNextAsync();

                Assert.IsTrue((aggressivePrefetch && exercisePrefetch) || enumerator.Current.Failed);

                // Resume on the children using the parent continuation token
                HashSet <string> childIdentifiers = new HashSet <string>();

                foreach (int partitionKeyRangeId in new int[] { 1, 2 })
                {
                    PartitionRangePageAsyncEnumerable <ReadFeedPage, ReadFeedState> enumerable = new PartitionRangePageAsyncEnumerable <ReadFeedPage, ReadFeedState>(
                        feedRangeState: new FeedRangeState <ReadFeedState>(
                            new FeedRangePartitionKeyRange(partitionKeyRangeId: partitionKeyRangeId.ToString()),
                            state),
                        (feedRangeState) => new ReadFeedPartitionRangeEnumerator(
                            inMemoryCollection,
                            feedRangeState: feedRangeState,
                            readFeedPaginationOptions: new ReadFeedPaginationOptions(pageSizeHint: 10),
                            cancellationToken: default),
                        trace: NoOpTrace.Singleton);

                    HashSet <string> resourceIdentifiers = await this.DrainFullyAsync(enumerable);

                    childIdentifiers.UnionWith(resourceIdentifiers);
                }

                Assert.AreEqual(numItems, parentIdentifiers.Count + childIdentifiers.Count);
            }