public async Task StartFromBeginingTestAsync() { IDocumentContainer documentContainer = await this.CreateDocumentContainerAsync(numItems : 10); List <FeedRangeEpk> ranges = await documentContainer.GetFeedRangesAsync(NoOpTrace.Singleton, cancellationToken : default); // Should get back the all the documents inserted so far ChangeFeedState resumeState; { TryCatch <ChangeFeedPage> monadicChangeFeedPage = await documentContainer.MonadicChangeFeedAsync( ChangeFeedState.Beginning(), ranges[0], pageSize : int.MaxValue, trace : NoOpTrace.Singleton, cancellationToken : default); Assert.IsTrue(monadicChangeFeedPage.Succeeded); resumeState = monadicChangeFeedPage.Result.State; } // No more changes left { TryCatch <ChangeFeedPage> monadicChangeFeedPage = await documentContainer.MonadicChangeFeedAsync( resumeState, ranges[0], pageSize : 10, trace : NoOpTrace.Singleton, cancellationToken : default); Assert.IsTrue(monadicChangeFeedPage.Succeeded); Assert.IsTrue(monadicChangeFeedPage.Result is ChangeFeedNotModifiedPage); } }
public async Task Tracing() { List <CosmosObject> documents = new List <CosmosObject>(); for (int i = 0; i < 250; i++) { documents.Add(CosmosObject.Parse($"{{\"pk\" : {i} }}")); } IDocumentContainer documentContainer = await CreateDocumentContainerAsync(documents); IQueryPipelineStage pipelineStage = await CreatePipelineAsync(documentContainer, "SELECT * FROM c", pageSize : 10); Trace rootTrace; int numTraces = (await documentContainer.GetFeedRangesAsync(NoOpTrace.Singleton, default)).Count; using (rootTrace = Trace.GetRootTrace("Cross Partition Query")) { while (await pipelineStage.MoveNextAsync(rootTrace)) { TryCatch <QueryPage> tryGetQueryPage = pipelineStage.Current; tryGetQueryPage.ThrowIfFailed(); numTraces++; } } Assert.AreEqual(numTraces, rootTrace.Children.Count); }
protected override Task <IAsyncEnumerator <TryCatch <OrderByQueryPage> > > CreateEnumeratorAsync( IDocumentContainer documentContainer, bool aggressivePrefetch = false, bool exercisePrefetch = false, QueryState state = null, CancellationToken cancellationToken = default) { List <FeedRangeEpk> ranges = documentContainer.GetFeedRangesAsync( trace: NoOpTrace.Singleton, cancellationToken: cancellationToken).Result; Assert.AreEqual(1, ranges.Count); IAsyncEnumerator <TryCatch <OrderByQueryPage> > enumerator = new TracingAsyncEnumerator <TryCatch <OrderByQueryPage> >( new OrderByQueryPartitionRangePageAsyncEnumerator( queryDataSource: documentContainer, sqlQuerySpec: new Cosmos.Query.Core.SqlQuerySpec("SELECT * FROM c"), feedRangeState: new FeedRangeState <QueryState>(ranges[0], state), partitionKey: null, queryPaginationOptions: new QueryPaginationOptions(pageSizeHint: 10), filter: "filter", cancellationToken: cancellationToken), NoOpTrace.Singleton); return(Task.FromResult(enumerator)); }
public async Task EmptyContainerTestAsync() { IDocumentContainer documentContainer = await this.CreateDocumentContainerAsync(numItems : 0); List <FeedRangeEpk> ranges = await documentContainer.GetFeedRangesAsync(NoOpTrace.Singleton, cancellationToken : default); TryCatch <ChangeFeedPage> monadicChangeFeedPage = await documentContainer.MonadicChangeFeedAsync( feedRangeState : new FeedRangeState <ChangeFeedState>(ranges[0], ChangeFeedState.Beginning()), changeFeedPaginationOptions : new ChangeFeedPaginationOptions(ChangeFeedMode.Incremental, pageSizeHint: 10), trace : NoOpTrace.Singleton, cancellationToken : default);
public async Task EmptyContainerTestAsync() { IDocumentContainer documentContainer = await this.CreateDocumentContainerAsync(numItems : 0); List <FeedRangeEpk> ranges = await documentContainer.GetFeedRangesAsync(NoOpTrace.Singleton, cancellationToken : default); TryCatch <ChangeFeedPage> monadicChangeFeedPage = await documentContainer.MonadicChangeFeedAsync( ChangeFeedState.Beginning(), ranges[0], pageSize : 10, trace : NoOpTrace.Singleton, cancellationToken : default); Assert.IsTrue(monadicChangeFeedPage.Succeeded); Assert.IsTrue(monadicChangeFeedPage.Result is ChangeFeedNotModifiedPage); }
public override IAsyncEnumerator <TryCatch <OrderByQueryPage> > CreateEnumerator( IDocumentContainer documentContainer, QueryState state = null, CancellationToken cancellationToken = default) { List <FeedRangeEpk> ranges = documentContainer.GetFeedRangesAsync( trace: NoOpTrace.Singleton, cancellationToken: cancellationToken).Result; Assert.AreEqual(1, ranges.Count); return(new OrderByQueryPartitionRangePageAsyncEnumerator( queryDataSource: documentContainer, sqlQuerySpec: new Cosmos.Query.Core.SqlQuerySpec("SELECT * FROM c"), feedRangeState: new FeedRangeState <QueryState>(ranges[0], state), partitionKey: null, queryPaginationOptions: new QueryPaginationOptions(pageSizeHint: 10), filter: "filter", cancellationToken: cancellationToken)); }
private static async Task RunTest(AggressivePrefetchTestCase testCase) { CancellationTokenSource cts = new CancellationTokenSource(Timeout); int maxConcurrency = Convert.ToInt32(Math.Pow(2, testCase.PartitionCount)); using MockDocumentContainer monadicDocumentContainer = new MockDocumentContainer( partitionKeyDefinition: FullPipelineTests.partitionKeyDefinition, continuationCount: testCase.ContinuationCount, maxConcurrency: maxConcurrency, cancellationToken: cts.Token); IDocumentContainer documentContainer = await FullPipelineTests.CreateDocumentContainerAsync( Documents, monadicDocumentContainer, testCase.PartitionCount); IReadOnlyList <FeedRangeEpk> feedRanges = await documentContainer.GetFeedRangesAsync(NoOpTrace.Singleton, cts.Token); Assert.AreEqual(maxConcurrency, feedRanges.Count); Task <List <CosmosElement> > resultTask = FullPipelineTests.DrainWithoutStateAsync( testCase.Query, documentContainer, pageSize: 10); for (int i = 0; i < testCase.ContinuationCount; i++) { while (monadicDocumentContainer.CountWaiters < maxConcurrency && !cts.IsCancellationRequested) { await Task.Delay(PollingInterval); } monadicDocumentContainer.Release(maxConcurrency); } IReadOnlyList <CosmosElement> actualDocuments = await resultTask; actualDocuments.Should().HaveCount(1); actualDocuments.First().Should().Be(testCase.ExpectedDocument); }