public async Task StandByFeedIterator_EmptyBeginning() { int totalCount = 0; int expectedDocuments = 5; string lastcontinuation = string.Empty; Documents.Routing.Range <string> previousRange = null; Documents.Routing.Range <string> currentRange = null; int pkRangesCount = (await this.Container.ClientContext.DocumentClient.ReadPartitionKeyRangeFeedAsync(this.Container.LinkUri)).Count; int visitedPkRanges = 0; ContainerCore itemsCore = (ContainerCore)this.Container; FeedIterator feedIterator = itemsCore.GetStandByFeedIterator(); while (feedIterator.HasMoreResults) { using (ResponseMessage responseMessage = await feedIterator.ReadNextAsync(this.cancellationToken)) { lastcontinuation = responseMessage.Headers.ContinuationToken; Assert.AreEqual(responseMessage.ContinuationToken, responseMessage.Headers.ContinuationToken); List <CompositeContinuationToken> deserializedToken = JsonConvert.DeserializeObject <List <CompositeContinuationToken> >(lastcontinuation); currentRange = deserializedToken[0].Range; if (responseMessage.IsSuccessStatusCode) { Collection <ToDoActivity> response = TestCommon.Serializer.FromStream <CosmosFeedResponseUtil <ToDoActivity> >(responseMessage.Content).Data; totalCount += response.Count; } else { if (visitedPkRanges == 0) { await this.CreateRandomItems(this.Container, expectedDocuments, randomPartitionKey : true); } } if (visitedPkRanges == pkRangesCount && responseMessage.StatusCode == System.Net.HttpStatusCode.NotModified) { break; } if (!currentRange.Equals(previousRange)) { visitedPkRanges++; } previousRange = currentRange; } } Assert.AreEqual(expectedDocuments, totalCount); }
public async Task StandByFeedIterator() { int totalCount = 0; string lastcontinuation = string.Empty; int firstRunTotal = 25; int batchSize = 25; Documents.Routing.Range <string> previousRange = null; Documents.Routing.Range <string> currentRange = null; int pkRangesCount = (await this.Container.ClientContext.DocumentClient.ReadPartitionKeyRangeFeedAsync(this.Container.LinkUri)).Count; int visitedPkRanges = 0; await this.CreateRandomItems(batchSize, randomPartitionKey : true); ContainerCore itemsCore = (ContainerCore)this.Container; FeedIterator feedIterator = itemsCore.GetStandByFeedIterator(requestOptions: new ChangeFeedRequestOptions() { StartTime = DateTime.MinValue }); while (feedIterator.HasMoreResults) { using (ResponseMessage responseMessage = await feedIterator.ReadNextAsync(this.cancellationToken)) { lastcontinuation = responseMessage.Headers.Continuation; List <CompositeContinuationToken> deserializedToken = JsonConvert.DeserializeObject <List <CompositeContinuationToken> >(lastcontinuation); currentRange = deserializedToken[0].Range; Assert.AreEqual(pkRangesCount, deserializedToken.Count); if (responseMessage.IsSuccessStatusCode) { Collection <ToDoActivity> response = new CosmosJsonSerializerCore().FromStream <CosmosFeedResponseUtil <ToDoActivity> >(responseMessage.Content).Data; totalCount += response.Count; } if (!currentRange.Equals(previousRange)) { visitedPkRanges++; } if (visitedPkRanges == pkRangesCount && responseMessage.StatusCode == System.Net.HttpStatusCode.NotModified) { break; } previousRange = currentRange; } } Assert.AreEqual(firstRunTotal, totalCount); int expectedFinalCount = 50; previousRange = null; currentRange = null; visitedPkRanges = 0; // Insert another batch of 25 and use the last continuation token from the first cycle await this.CreateRandomItems(batchSize, randomPartitionKey : true); FeedIterator setIteratorNew = itemsCore.GetStandByFeedIterator(lastcontinuation); while (setIteratorNew.HasMoreResults) { using (ResponseMessage responseMessage = await setIteratorNew.ReadNextAsync(this.cancellationToken)) { lastcontinuation = responseMessage.Headers.Continuation; currentRange = JsonConvert.DeserializeObject <List <CompositeContinuationToken> >(lastcontinuation)[0].Range; if (responseMessage.IsSuccessStatusCode) { Collection <ToDoActivity> response = new CosmosJsonSerializerCore().FromStream <CosmosFeedResponseUtil <ToDoActivity> >(responseMessage.Content).Data; totalCount += response.Count; } if (!currentRange.Equals(previousRange)) { visitedPkRanges++; } if (visitedPkRanges == pkRangesCount && responseMessage.StatusCode == System.Net.HttpStatusCode.NotModified) { break; } previousRange = currentRange; } } Assert.AreEqual(expectedFinalCount, totalCount); }