/// <summary> /// Asynchronously registers the observer factory implementation with the host. /// This method also starts the host and enables it to start participating in the partition distribution process. /// </summary> /// <param name="factory">Implementation of your application-specific event observer factory.</param> /// <returns>A task indicating that the <see cref="ChangeFeedEventHost" /> instance has started.</returns> public async Task RegisterObserverFactoryAsync(IChangeFeedObserverFactory factory) { this.builder.WithObserverFactory(new ChangeFeedObserverFactoryAdapter(factory)); await this.CreateHost().ConfigureAwait(false); await this.processor.StartAsync().ConfigureAwait(false); }
public PartitionSupervisorFactory( IChangeFeedObserverFactory observerFactory, ILeaseManager leaseManager, ILeaseCheckpointer leaseCheckpointer, ICheckpointPartitionProcessorFactory partitionProcessorFactory, ChangeFeedProcessorOptions options) { if (observerFactory == null) { throw new ArgumentNullException(nameof(observerFactory)); } if (leaseManager == null) { throw new ArgumentNullException(nameof(leaseManager)); } if (leaseCheckpointer == null) { throw new ArgumentNullException(nameof(leaseCheckpointer)); } if (options == null) { throw new ArgumentNullException(nameof(options)); } if (partitionProcessorFactory == null) { throw new ArgumentNullException(nameof(partitionProcessorFactory)); } this.observerFactory = observerFactory; this.leaseManager = leaseManager; this.leaseCheckpointer = leaseCheckpointer; this.changeFeedProcessorOptions = options; this.partitionProcessorFactory = partitionProcessorFactory; }
/// <summary> /// Asynchronously registers the observer factory implementation with the host. /// This method also starts the host and enables it to start participating in the partition distribution process. /// </summary> /// <param name="factory">Implementation of your application-specific event observer factory.</typeparam> /// <returns>A task indicating that the <see cref="DocumentDB.ChangeFeedProcessor.ChangeFeedEventHost" /> instance has started.</returns> public async Task RegisterObserverFactoryAsync(IChangeFeedObserverFactory factory) { if (factory == null) { throw new ArgumentNullException("factory"); } this.observerFactory = factory; await this.StartAsync(); }
/// <summary> /// Initializes a new instance of the <see cref="CheckpointerObserverFactory"/> class. /// </summary> /// <param name="observerFactory">Instance of Observer Factory</param> /// <param name="checkpointFrequency">Defined <see cref="CheckpointFrequency"/></param> public CheckpointerObserverFactory(IChangeFeedObserverFactory observerFactory, CheckpointFrequency checkpointFrequency) { if (observerFactory == null) { throw new ArgumentNullException(nameof(observerFactory)); } if (checkpointFrequency == null) { throw new ArgumentNullException(nameof(checkpointFrequency)); } this.observerFactory = observerFactory; this.checkpointFrequency = checkpointFrequency; }
/// <summary>Asynchronously shuts down the host instance. This method maintains the leases on all partitions currently held, and enables each /// host instance to shut down cleanly by invoking the method with object.</summary> /// <returns>A task that indicates the host instance has stopped.</returns> public async Task UnregisterObserversAsync() { await this.StopAsync(ChangeFeedObserverCloseReason.Shutdown); this.observerFactory = null; }
/// <summary> /// Asynchronously registers the observer factory implementation with the host. /// This method also starts the host and enables it to start participating in the partition distribution process. /// </summary> /// <param name="factory">Implementation of your application-specific event observer factory.</typeparam> /// <returns>A task indicating that the <see cref="DocumentDB.ChangeFeedProcessor.ChangeFeedEventHost" /> instance has started.</returns> public async Task RegisterObserverFactoryAsync(IChangeFeedObserverFactory factory) { this.observerFactory = factory; await this.StartAsync(); }
/// <summary>Asynchronously registers the observer interface implementation with the host. /// This method also starts the host and enables it to start participating in the partition distribution process.</summary> /// <typeparam name="T">Implementation of your application-specific event observer.</typeparam> /// <returns>A task indicating that the <see cref="DocumentDB.ChangeFeedProcessor.ChangeFeedEventHost" /> instance has started.</returns> public async Task RegisterObserverAsync <T>() where T : IChangeFeedObserver, new() { this.observerFactory = new ChangeFeedObserverFactory <T>(); await this.StartAsync(); }
public ChangeFeedProcessorTests() { var leaseQueryMock = new Mock <IDocumentQuery <Document> >(); var leaseDocumentClient = Mock.Of <IChangeFeedDocumentClient>(); Mock.Get(leaseDocumentClient) .Setup(c => c.CreateDocumentQuery <Document>(collectionLink, It.Is <SqlQuerySpec>(spec => spec.QueryText == "SELECT * FROM c WHERE STARTSWITH(c.id, @PartitionLeasePrefix)" && spec.Parameters.Count == 1 && spec.Parameters[0].Name == "@PartitionLeasePrefix" && (string)spec.Parameters[0].Value == storeNamePrefix + ".." ), null)) .Returns(leaseQueryMock.As <IQueryable <Document> >().Object); leaseQueryMock .Setup(q => q.HasMoreResults) .Returns(false); Mock.Get(leaseDocumentClient) .Setup(ex => ex.ReadDatabaseAsync(It.IsAny <Uri>(), It.IsAny <RequestOptions>())) .ReturnsAsync(new ResourceResponse <Database>(database)); Mock.Get(leaseDocumentClient) .Setup(ex => ex.ReadDocumentCollectionAsync(It.IsAny <Uri>(), It.IsAny <RequestOptions>())) .ReturnsAsync(new ResourceResponse <DocumentCollection>(collection)); var documents = new List <Document> { }; var feedResponse = Mock.Of <IFeedResponse <Document> >(); Mock.Get(feedResponse) .Setup(response => response.Count) .Returns(documents.Count); Mock.Get(feedResponse) .Setup(response => response.GetEnumerator()) .Returns(documents.GetEnumerator()); var documentQuery = Mock.Of <IChangeFeedDocumentQuery <Document> >(); Mock.Get(documentQuery) .Setup(query => query.HasMoreResults) .Returns(false); Mock.Get(documentQuery) .Setup(query => query.ExecuteNextAsync <Document>(It.IsAny <CancellationToken>())) .ReturnsAsync(() => feedResponse) .Callback(cancellationTokenSource.Cancel); var documentClient = Mock.Of <IChangeFeedDocumentClient>(); Mock.Get(documentClient) .Setup(ex => ex.CreateDocumentChangeFeedQuery(It.IsAny <string>(), It.IsAny <ChangeFeedOptions>())) .Callback((string s, ChangeFeedOptions o) => this.createDocumentChangeFeedQueryCallback(s, o)) .Returns(documentQuery); Mock.Get(documentClient) .Setup(ex => ex.ReadDatabaseAsync(It.IsAny <Uri>(), It.IsAny <RequestOptions>())) .ReturnsAsync(new ResourceResponse <Database>(database)); Mock.Get(documentClient) .Setup(ex => ex.ReadDocumentCollectionAsync(It.IsAny <Uri>(), It.IsAny <RequestOptions>())) .ReturnsAsync(new ResourceResponse <DocumentCollection>(collection)); this.lease = Mock.Of <ILease>(); Mock.Get(this.lease) .Setup(l => l.PartitionId) .Returns("partitionId"); var leaseStore = Mock.Of <ILeaseStore>(); this.leaseStoreManager = Mock.Of <ILeaseStoreManager>(); Mock.Get(this.leaseStoreManager) .Setup(store => store.IsInitializedAsync()) .ReturnsAsync(true); Mock.Get(this.leaseStoreManager) .Setup(manager => manager.AcquireAsync(lease)) .ReturnsAsync(lease); Mock.Get(this.leaseStoreManager) .Setup(manager => manager.ReleaseAsync(lease)) .Returns(Task.CompletedTask); this.builder .WithHostName("someHost") .WithFeedDocumentClient(documentClient) .WithFeedCollection(collectionInfo) .WithProcessorOptions(new ChangeFeedProcessorOptions()) .WithLeaseStoreManager(leaseStoreManager) .WithLeaseCollection(collectionInfo) .WithLeaseDocumentClient(leaseDocumentClient); this.observer = Mock.Of <IChangeFeedObserver>(); Mock.Get(observer) .Setup(feedObserver => feedObserver .ProcessChangesAsync(It.IsAny <ChangeFeedObserverContext>(), It.IsAny <IReadOnlyList <Document> >(), It.IsAny <CancellationToken>())) .Returns(Task.CompletedTask) .Callback(cancellationTokenSource.Cancel); Mock.Get(observer) .Setup(observer => observer.OpenAsync(It.IsAny <ChangeFeedObserverContext>())) .Returns(Task.CompletedTask); this.observerFactory = Mock.Of <IChangeFeedObserverFactory>(); Mock.Get(observerFactory) .Setup(observer => observer.CreateObserver()) .Returns(observer); }
#pragma warning restore CS0618 // Type or member is obsolete #pragma warning disable CS0618 // Type or member is obsolete internal ChangeFeedObserverFactoryAdapter(IChangeFeedObserverFactory factory) #pragma warning restore CS0618 // Type or member is obsolete { this.factory = factory ?? throw new ArgumentNullException(nameof(factory)); }