public PartitionSupervisor(ILease lease, IChangeFeedObserver observer, IPartitionProcessor processor, ILeaseRenewer renewer) { this.lease = lease; this.observer = observer; this.processor = processor; this.renewer = renewer; }
public async Task AddLease_ShouldIgnorePartitionObserving_IfDuplicateLease() { await sut.AddOrUpdateLeaseAsync(lease).ConfigureAwait(false); IPartitionProcessor processorDuplicate = MockPartitionProcessor(); Mock.Get(partitionSupervisorFactory) .Setup(f => f.Create(lease)) .Returns(new PartitionSupervisor(lease, observer, processorDuplicate, leaseRenewer)); await sut.AddOrUpdateLeaseAsync(lease).ConfigureAwait(false); Mock.Get(leaseManager) .Verify(manager => manager.AcquireAsync(lease), Times.Once); Mock.Get(leaseManager) .Verify(manager => manager.UpdatePropertiesAsync(lease), Times.Once); Mock.Get(leaseManager) .Verify(manager => manager.ReleaseAsync(It.IsAny <ILease>()), Times.Never); Mock.Get(partitionProcessor) .Verify(p => p.RunAsync(It.IsAny <CancellationToken>()), Times.Once); Mock.Get(processorDuplicate) .Verify(p => p.RunAsync(It.IsAny <CancellationToken>()), Times.Never); }
public PartitionControllerTests() { lease = Mock.Of <ILease>(); Mock.Get(lease) .Setup(l => l.PartitionId) .Returns("partitionId"); partitionProcessor = MockPartitionProcessor(); leaseRenewer = MockRenewer(); observer = MockObserver(); partitionSupervisorFactory = Mock.Of <IPartitionSupervisorFactory>(f => f.Create(lease) == new PartitionSupervisor(lease, observer, partitionProcessor, leaseRenewer)); leaseManager = Mock.Of <ILeaseManager>(); Mock.Get(leaseManager).Reset(); // Reset implicit/by default setup of properties. Mock.Get(leaseManager) .Setup(manager => manager.AcquireAsync(lease)) .ReturnsAsync(lease); Mock.Get(leaseManager) .Setup(manager => manager.ReleaseAsync(lease)) .Returns(Task.CompletedTask); var leaseContainer = Mock.Of <ILeaseContainer>(); synchronizer = Mock.Of <IPartitionSynchronizer>(); sut = new PartitionController(leaseContainer, leaseManager, partitionSupervisorFactory, synchronizer); }
/// <summary> /// Initializes a new instance of the <see cref="PartitionPump"/> class. /// </summary> /// /// <param name="eventHubClient">The client used to interact with the Azure Event Hubs service.</param> /// <param name="consumerGroup">The name of the consumer group this partition pump is associated with. Events are read in the context of this group.</param> /// <param name="partitionId">The identifier of the Event Hub partition this partition pump is associated with. Events will be read only from this partition.</param> /// <param name="partitionProcessor">A partition processor used to process events and errors. Its implementation must be provided by the caller.</param> /// <param name="options">The set of options to use for this partition pump.</param> /// internal PartitionPump(EventHubClient eventHubClient, string consumerGroup, string partitionId, IPartitionProcessor partitionProcessor, EventProcessorOptions options) { InnerClient = eventHubClient; ConsumerGroup = consumerGroup; PartitionId = partitionId; PartitionProcessor = partitionProcessor; Options = options; }
public PartitionSupervisorTests() { lease = Mock.Of <ILease>(); Mock.Get(lease) .Setup(l => l.PartitionId) .Returns("partitionId"); leaseRenewer = Mock.Of <ILeaseRenewer>(); partitionProcessor = Mock.Of <IPartitionProcessor>(); observer = Mock.Of <IChangeFeedObserver>(); sut = new PartitionSupervisor(lease, observer, partitionProcessor, leaseRenewer); }
public async Task AddLease_ShouldRunObserver_IfSecondAdded() { var lease2 = Mock.Of <ILease>(); Mock.Get(lease2) .Setup(l => l.PartitionId) .Returns("partitionId2"); IPartitionProcessor partitionProcessor2 = MockPartitionProcessor(); Mock.Get(partitionSupervisorFactory) .Setup(f => f.Create(lease2)) .Returns(new PartitionSupervisor(lease2, observer, partitionProcessor2, leaseRenewer)); await sut.AddOrUpdateLeaseAsync(lease).ConfigureAwait(false); await sut.AddOrUpdateLeaseAsync(lease2).ConfigureAwait(false); Mock.Get(partitionProcessor2) .Verify(p => p.RunAsync(It.IsAny <CancellationToken>()), Times.Once); }
public PartitionControllerTests() { lease = Mock.Of <ILease>(); Mock.Get(lease) .Setup(l => l.PartitionId) .Returns("partitionId"); partitionProcessor = MockPartitionProcessor(); leaseRenewer = MockRenewer(); observer = MockObserver(); partitionSupervisorFactory = Mock.Of <IPartitionSupervisorFactory>(f => f.Create(lease) == new PartitionSupervisor(lease, observer, partitionProcessor, leaseRenewer)); leaseManager = Mock.Of <ILeaseManager>(); Mock.Get(leaseManager) .Setup(manager => manager.AcquireAsync(lease)) .ReturnsAsync(lease); Mock.Get(leaseManager) .Setup(manager => manager.ReleaseAsync(lease)) .Returns(Task.FromResult(false)); synchronizer = Mock.Of <IPartitionSynchronizer>(); sut = new PartitionController(leaseManager, partitionSupervisorFactory, synchronizer); }
public PartitionManager(TimeSpan partitionWindow, int partitions, IPartitionProcessor partitionProcessor) { this.partitions = partitions; this.partitionWindow = partitionWindow; this.q = Enumerable.Range(0, partitions).Select(x => new Partition()).ToArray(); }