public async Task StandByFeedIterator_NoFetchNext() { int pkRangesCount = (await this.Container.ClientContext.DocumentClient.ReadPartitionKeyRangeFeedAsync(this.Container.LinkUri)).Count; int expected = 25; int iterations = 0; await this.CreateRandomItems(this.Container, expected, randomPartitionKey : true); ContainerInternal itemsCore = this.Container; string continuationToken = null; int count = 0; while (true) { StandByFeedIteratorRequestOptions requestOptions = new StandByFeedIteratorRequestOptions() { StartTime = DateTime.MinValue }; using FeedIterator feedIterator = itemsCore.GetStandByFeedIterator(continuationToken, requestOptions: requestOptions); using (ResponseMessage responseMessage = await feedIterator.ReadNextAsync(this.cancellationToken)) { continuationToken = responseMessage.Headers.ContinuationToken; Assert.AreEqual(responseMessage.ContinuationToken, responseMessage.Headers.ContinuationToken); if (responseMessage.IsSuccessStatusCode) { Collection <ToDoActivity> response = TestCommon.SerializerCore.FromStream <CosmosFeedResponseUtil <ToDoActivity> >(responseMessage.Content).Data; count += response.Count; } } if (count > expected) { Assert.Fail($"{count} does not equal {expected}"); } if (count.Equals(expected)) { break; } if (iterations++ > pkRangesCount) { Assert.Fail("Feed does not contain all elements even after looping through PK ranges. Either the continuation is not moving forward or there is some state problem."); } } }
internal override Task <ResponseMessage> NextResultSetDelegateAsync( string continuationToken, string partitionKeyRangeId, int?maxItemCount, StandByFeedIteratorRequestOptions options, CancellationToken cancellationToken) { if (this.Iteration++ == 0) { ResponseMessage httpResponse = new ResponseMessage(System.Net.HttpStatusCode.Gone); httpResponse.Headers.Add(Documents.WFConstants.BackendHeaders.SubStatus, ((uint)Documents.SubStatusCodes.PartitionKeyRangeGone).ToString(CultureInfo.InvariantCulture)); return(Task.FromResult(httpResponse)); } return(Task.FromResult(new ResponseMessage(System.Net.HttpStatusCode.NotModified))); }
internal StandByFeedIteratorCore( CosmosClientContext clientContext, ContainerInternal container, string continuationToken, int?maxItemCount, StandByFeedIteratorRequestOptions options) { if (container == null) { throw new ArgumentNullException(nameof(container)); } this.clientContext = clientContext; this.container = container; this.changeFeedOptions = options; this.maxItemCount = maxItemCount; this.continuationToken = continuationToken; }
internal virtual Task <ResponseMessage> NextResultSetDelegateAsync( string continuationToken, string partitionKeyRangeId, int?maxItemCount, StandByFeedIteratorRequestOptions options, ITrace trace, CancellationToken cancellationToken) { string resourceUri = this.container.LinkUri; return(this.clientContext.ProcessResourceOperationAsync <ResponseMessage>( resourceUri: resourceUri, resourceType: Documents.ResourceType.Document, operationType: Documents.OperationType.ReadFeed, requestOptions: options, containerInternal: this.container, requestEnricher: request => { if (!string.IsNullOrWhiteSpace(continuationToken)) { // On REST level, change feed is using IfNoneMatch/ETag instead of continuation request.Headers.IfNoneMatch = continuationToken; } if (maxItemCount.HasValue) { request.Headers.PageSize = maxItemCount.Value.ToString(CultureInfo.InvariantCulture); } if (!string.IsNullOrEmpty(partitionKeyRangeId)) { request.PartitionKeyRangeId = new PartitionKeyRangeIdentity(partitionKeyRangeId); } }, responseCreator: response => response, partitionKey: null, streamPayload: null, diagnosticsContext: null, trace: trace, cancellationToken: cancellationToken)); }
internal CosmosChangeFeedResultSetIteratorCoreMock( ContainerInternal container, string continuationToken, int?maxItemCount, StandByFeedIteratorRequestOptions options) : base( clientContext: container.ClientContext, container: container, continuationToken: continuationToken, maxItemCount: maxItemCount, options: options) { List <CompositeContinuationToken> compositeContinuationTokens = new List <CompositeContinuationToken>() { new CompositeContinuationToken() { Token = null, Range = new Documents.Routing.Range <string>("A", "B", true, false) } }; string serialized = JsonConvert.SerializeObject(compositeContinuationTokens); this.compositeContinuationToken = StandByFeedContinuationToken.CreateAsync("containerRid", serialized, (string containerRid, Documents.Routing.Range <string> ranges, bool forceRefresh) => { IReadOnlyList <Documents.PartitionKeyRange> filteredRanges = new List <Documents.PartitionKeyRange>() { new Documents.PartitionKeyRange() { MinInclusive = "A", MaxExclusive = "B", Id = "0" } }; if (forceRefresh) { this.HasCalledForceRefresh = true; } return(Task.FromResult(filteredRanges)); }).Result; }