public async Task TestWithFixedLeaseContainer() { await NonPartitionedContainerHelper.CreateNonPartitionedContainer( this.database, "fixedLeases"); Container fixedLeasesContainer = this.cosmosClient.GetContainer(this.database.Id, "fixedLeases"); try { int partitionKey = 0; ManualResetEvent allDocsProcessed = new ManualResetEvent(false); int processedDocCount = 0; string accumulator = string.Empty; ChangeFeedProcessor processor = this.Container .GetChangeFeedProcessorBuilder("test", (ChangeFeedProcessorContext context, Stream stream, CancellationToken token) => { this.ValidateContext(context); IEnumerable <JObject> asEnumerable = CosmosFeedResponseSerializer.FromFeedResponseStream <JObject>(this.serializerCore, stream); processedDocCount += asEnumerable.Count(); foreach (JObject doc in asEnumerable) { accumulator += doc["id"].ToString() + "."; } if (processedDocCount == 10) { allDocsProcessed.Set(); } return(Task.CompletedTask); }) .WithInstanceName("random") .WithLeaseContainer(fixedLeasesContainer).Build(); // Start the processor, insert 1 document to generate a checkpoint await processor.StartAsync(); await Task.Delay(BaseChangeFeedClientHelper.ChangeFeedSetupTime); foreach (int id in Enumerable.Range(0, 10)) { await this.Container.CreateItemAsync <dynamic>(new { id = id.ToString(), pk = partitionKey }); } bool isStartOk = allDocsProcessed.WaitOne(10 * BaseChangeFeedClientHelper.ChangeFeedSetupTime); await processor.StopAsync(); Assert.IsTrue(isStartOk, "Timed out waiting for docs to process"); Assert.AreEqual("0.1.2.3.4.5.6.7.8.9.", accumulator); } finally { await fixedLeasesContainer.DeleteContainerAsync(); } }
private async Task <Container> CreateNonPartitionedContainerAsync( Microsoft.Azure.Cosmos.IndexingPolicy indexingPolicy = null) { string containerName = Guid.NewGuid().ToString() + "container"; await NonPartitionedContainerHelper.CreateNonPartitionedContainer( this.database, containerName, indexingPolicy == null?null : JsonConvert.SerializeObject(indexingPolicy)); return(this.database.GetContainer(containerName)); }