public async Task ChangeFeedIteratorCore_OfT_ReadAll() { int totalCount = 0; int firstRunTotal = 25; int batchSize = 25; await this.CreateRandomItems(this.Container, batchSize, randomPartitionKey : true); ContainerCore itemsCore = this.Container; FeedIterator <ToDoActivity> feedIterator = itemsCore.GetChangeFeedIterator <ToDoActivity>(changeFeedRequestOptions: new ChangeFeedRequestOptions() { StartTime = DateTime.MinValue.ToUniversalTime() }); string continuation = null; while (feedIterator.HasMoreResults) { FeedResponse <ToDoActivity> feedResponse = await feedIterator.ReadNextAsync(this.cancellationToken); totalCount += feedResponse.Count; continuation = feedResponse.ContinuationToken; } Assert.AreEqual(firstRunTotal, totalCount); int expectedFinalCount = 50; // Insert another batch of 25 and use the last FeedToken from the first cycle await this.CreateRandomItems(this.Container, batchSize, randomPartitionKey : true); FeedIterator <ToDoActivity> setIteratorNew = itemsCore.GetChangeFeedIterator <ToDoActivity>(continuationToken: continuation, changeFeedRequestOptions: new ChangeFeedRequestOptions() { StartTime = DateTime.MinValue.ToUniversalTime() }); while (setIteratorNew.HasMoreResults) { FeedResponse <ToDoActivity> feedResponse = await setIteratorNew.ReadNextAsync(this.cancellationToken); totalCount += feedResponse.Count; } Assert.AreEqual(expectedFinalCount, totalCount); }
public async Task ChangeFeedIteratorCore_PartitionKeyRangeId_OfT_ReadAll() { int totalDocuments = 200; await this.CreateRandomItems(this.LargerContainer, totalDocuments, randomPartitionKey : true); DocumentFeedResponse <Documents.PartitionKeyRange> ranges = await this.LargerContainer.ClientContext.DocumentClient.ReadPartitionKeyRangeFeedAsync(this.LargerContainer.LinkUri); List <FeedToken> tokens = new List <FeedToken>(ranges.Count); foreach (Documents.PartitionKeyRange range in ranges) { tokens.Add(new FeedTokenPartitionKeyRange(range.Id)); } ContainerCore itemsCore = this.LargerContainer; List <Task <int> > tasks = tokens.Select(token => Task.Run(async() => { int count = 0; FeedIterator <ToDoActivity> iteratorForToken = itemsCore.GetChangeFeedIterator <ToDoActivity>(token, changeFeedRequestOptions: new ChangeFeedRequestOptions() { StartTime = DateTime.MinValue.ToUniversalTime() }); while (iteratorForToken.HasMoreResults) { FeedResponse <ToDoActivity> feedResponse = await iteratorForToken.ReadNextAsync(this.cancellationToken); count += feedResponse.Count; } return(count); })).ToList(); await Task.WhenAll(tasks); int documentsRead = 0; foreach (Task <int> task in tasks) { documentsRead += task.Result; } Assert.AreEqual(totalDocuments, documentsRead); }
public async Task ChangeFeedIteratorCore_PartitionKey_OfT_ReadAll() { int totalCount = 0; int firstRunTotal = 25; int batchSize = 25; string pkToRead = "pkToRead"; string otherPK = "otherPK"; for (int i = 0; i < batchSize; i++) { await this.Container.CreateItemAsync(this.CreateRandomToDoActivity(pkToRead)); } for (int i = 0; i < batchSize; i++) { await this.Container.CreateItemAsync(this.CreateRandomToDoActivity(otherPK)); } ContainerCore itemsCore = this.Container; FeedIterator <ToDoActivity> feedIterator = itemsCore.GetChangeFeedIterator <ToDoActivity>(new PartitionKey(pkToRead), changeFeedRequestOptions: new ChangeFeedRequestOptions() { StartTime = DateTime.MinValue.ToUniversalTime() }); string continuation = null; while (feedIterator.HasMoreResults) { FeedResponse <ToDoActivity> feedResponse = await feedIterator.ReadNextAsync(this.cancellationToken); totalCount += feedResponse.Count; foreach (ToDoActivity toDoActivity in feedResponse) { Assert.AreEqual(pkToRead, toDoActivity.status); } continuation = feedResponse.ContinuationToken; } Assert.AreEqual(firstRunTotal, totalCount); int expectedFinalCount = 50; // Insert another batch of 25 and use the last FeedToken from the first cycle for (int i = 0; i < batchSize; i++) { await this.Container.CreateItemAsync(this.CreateRandomToDoActivity(pkToRead)); } FeedIterator <ToDoActivity> setIteratorNew = itemsCore.GetChangeFeedIterator <ToDoActivity>(continuationToken: continuation, changeFeedRequestOptions: new ChangeFeedRequestOptions() { StartTime = DateTime.MinValue.ToUniversalTime() }); while (setIteratorNew.HasMoreResults) { FeedResponse <ToDoActivity> feedResponse = await setIteratorNew.ReadNextAsync(this.cancellationToken); totalCount += feedResponse.Count; foreach (ToDoActivity toDoActivity in feedResponse) { Assert.AreEqual(pkToRead, toDoActivity.status); } } Assert.AreEqual(expectedFinalCount, totalCount); }