private static async Task <IRemainingWorkEstimator> CreateEstimatorAsync(string uri, string key, string collection) { IChangeFeedDocumentClient dbClient = new ChangeFeedDocumentClient(new DocumentClient(new Uri(uri), key)); var builder = new ChangeFeedProcessorBuilder() .WithHostName("console_app_host") .WithFeedCollection(new DocumentCollectionInfo() { Uri = new Uri(uri), MasterKey = key, CollectionName = collection, DatabaseName = DbName }) .WithLeaseCollection(new DocumentCollectionInfo() { CollectionName = $"{collection}.Lease.ConsoleApp", DatabaseName = DbName, Uri = new Uri(uri), MasterKey = key }) .WithFeedDocumentClient(dbClient) .WithLeaseDocumentClient(dbClient); return(await builder.BuildEstimatorAsync()); }
private static async Task <IChangeFeedProcessor> RunChangeFeedProcessorAsync(string uri, string key, string collection) { IChangeFeedDocumentClient dbClient = new ChangeFeedDocumentClient(new DocumentClient(new Uri(uri), key)); dbClient = new QoSMeteringChangeFeedDocumentClient(dbClient, new QoSMeteringReporter()); var builder = new ChangeFeedProcessorBuilder() .WithObserver <ConsoleObserver>() .WithHostName("console_app_host") .WithFeedCollection(new DocumentCollectionInfo() { Uri = new Uri(uri), MasterKey = key, CollectionName = collection, DatabaseName = DbName }) .WithLeaseCollection(new DocumentCollectionInfo() { CollectionName = $"{collection}.Lease.ConsoleApp", DatabaseName = DbName, Uri = new Uri(uri), MasterKey = key }) .WithFeedDocumentClient(dbClient) .WithLeaseDocumentClient(dbClient); var processor = await builder.BuildAsync(); var estimator = await builder.BuildEstimatorAsync(); await processor.StartAsync().ConfigureAwait(false); return(processor); }
public async Task BuildEstimatorThrowsWhenNoneOfLeaseCollectionInfoOrLeaseStoreManagerSpecified() { var builder = new ChangeFeedProcessorBuilder() .WithHostName("host") .WithFeedCollection(CollectionInfo) .WithObserverFactory(Mock.Of <IChangeFeedObserverFactory>()); await Assert.ThrowsAsync <InvalidOperationException>(async() => await builder.BuildEstimatorAsync()); }
public async Task BuildEstimatorWhenOnlyLeaseStoreManagerSpecified() { var builder = new ChangeFeedProcessorBuilder() .WithHostName("host") .WithFeedCollection(CollectionInfo) .WithFeedDocumentClient(CreateMockDocumentClient()) .WithObserverFactory(Mock.Of <IChangeFeedObserverFactory>()) .WithLeaseStoreManager(Mock.Of <ILeaseStoreManager>()); await builder.BuildEstimatorAsync(); }
public static IRemainingWorkEstimator GetRemainingWorkEstimator( DocumentClient monitoredCollectionClient, DocumentClient leaseCollectionClient) { if (remainingWorkEstimator == null) { // Pull the Connection string from the environment, Environment.GetEnvironmentVariable will read the local.settings.json file or the deployed Function App configuration CosmosDBConnectionString cosmosDBConnectionString = new CosmosDBConnectionString(Environment.GetEnvironmentVariable("CosmosDB")); remainingWorkEstimator = new Lazy <IRemainingWorkEstimator>(() => { var builder = new ChangeFeedProcessorBuilder() .WithHostName("monitor") // Can be a random name .WithProcessorOptions(new ChangeFeedProcessorOptions() { LeasePrefix = Environment.GetEnvironmentVariable("MonitoredDatabaseLeasePrefix") }) .WithFeedCollection(new DocumentCollectionInfo() { Uri = cosmosDBConnectionString.ServiceEndpoint, MasterKey = cosmosDBConnectionString.AuthKey, CollectionName = Environment.GetEnvironmentVariable("MonitoredCollection"), DatabaseName = Environment.GetEnvironmentVariable("MonitoredDatabase") }) .WithLeaseCollection(new DocumentCollectionInfo() { Uri = cosmosDBConnectionString.ServiceEndpoint, MasterKey = cosmosDBConnectionString.AuthKey, CollectionName = "leases", DatabaseName = Environment.GetEnvironmentVariable("MonitoredDatabase") }) .WithFeedDocumentClient(monitoredCollectionClient) .WithLeaseDocumentClient(leaseCollectionClient); return(builder.BuildEstimatorAsync().Result); }); } return(remainingWorkEstimator.Value); }
private async Task <IRemainingWorkEstimator> GetWorkEstimatorAsync() { if (_workEstimatorBuilder == null) { _workEstimatorBuilder = new ChangeFeedProcessorBuilder() .WithHostName(this._hostName) .WithFeedDocumentClient(this._monitoredCosmosDBService.GetClient()) .WithLeaseDocumentClient(this._leasesCosmosDBService.GetClient()) .WithFeedCollection(this._monitorCollection) .WithLeaseCollection(this._leaseCollection) .WithProcessorOptions(this._processorOptions) .WithHealthMonitor(this._healthMonitor) .WithObserverFactory(this); } if (_workEstimator == null) { _workEstimator = await _workEstimatorBuilder.BuildEstimatorAsync(); } return(_workEstimator); }
public async Task BuildEstimatorThrowsWhenLeaseCollectionPartitionedNotById() { SetupBuilderForPartitionedLeaseCollection("/not_id"); await Assert.ThrowsAsync <ArgumentException>(async() => await builder.BuildEstimatorAsync()); }