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 ChangeFeedIteratorCore_HandlesSplitsThroughPipeline() { int numItems = 100; IDocumentContainer documentContainer = await CreateDocumentContainerAsync(numItems); ChangeFeedIteratorCore changeFeedIteratorCore = new ChangeFeedIteratorCore( documentContainer, ChangeFeedMode.Incremental, new ChangeFeedRequestOptions(), ChangeFeedStartFrom.Beginning(), this.MockClientContext()); int seed = new Random().Next(); Random random = new Random(seed); int count = 0; while (changeFeedIteratorCore.HasMoreResults) { ResponseMessage responseMessage = await changeFeedIteratorCore.ReadNextAsync(); if (responseMessage.StatusCode == HttpStatusCode.NotModified) { break; } count += GetChanges(responseMessage.Content).Count; await documentContainer.RefreshProviderAsync(NoOpTrace.Singleton, cancellationToken : default); IReadOnlyList <FeedRangeInternal> ranges = await documentContainer.GetFeedRangesAsync(trace : NoOpTrace.Singleton, cancellationToken : default);
public async Task TestSplitAndMergeImplementationAsync(bool useState, bool allowSplits, bool allowMerges) { int numItems = 1000; IDocumentContainer inMemoryCollection = await this.CreateDocumentContainerAsync(numItems); IAsyncEnumerator <TryCatch <CrossFeedRangePage <ReadFeedPage, ReadFeedState> > > enumerator = this.CreateEnumerator(inMemoryCollection); HashSet <string> identifiers = new HashSet <string>(); Random random = new Random(); while (await enumerator.MoveNextAsync()) { TryCatch <CrossFeedRangePage <ReadFeedPage, ReadFeedState> > tryGetPage = enumerator.Current; tryGetPage.ThrowIfFailed(); IReadOnlyList <Record> records = this.GetRecordsFromPage(tryGetPage.Result); foreach (Record record in records) { identifiers.Add(record.Payload["pk"].ToString()); } if (useState) { if (tryGetPage.Result.State == null) { break; } enumerator = this.CreateEnumerator(inMemoryCollection, tryGetPage.Result.State); } if (random.Next() % 2 == 0) { if (allowSplits && (random.Next() % 2 == 0)) { // Split await inMemoryCollection.RefreshProviderAsync(NoOpTrace.Singleton, cancellationToken : default); List <FeedRangeEpk> ranges = await inMemoryCollection.GetFeedRangesAsync( trace : NoOpTrace.Singleton, cancellationToken : default);