internal PartitionManager BuildPartitionManager() { CheckpointerObserverFactory <T> factory = new CheckpointerObserverFactory <T>(this.observerFactory, this.changeFeedProcessorOptions.CheckpointFrequency); PartitionSynchronizerCore synchronizer = new PartitionSynchronizerCore( this.monitoredContainer, this.documentServiceLeaseStoreManager.LeaseContainer, this.documentServiceLeaseStoreManager.LeaseManager, PartitionSynchronizerCore.DefaultDegreeOfParallelism, this.changeFeedProcessorOptions.QueryFeedMaxBatchSize); BootstrapperCore bootstrapper = new BootstrapperCore(synchronizer, this.documentServiceLeaseStoreManager.LeaseStore, BootstrapperCore.DefaultLockTime, BootstrapperCore.DefaultSleepTime); PartitionSupervisorFactoryCore <T> partitionSuperviserFactory = new PartitionSupervisorFactoryCore <T>( factory, this.documentServiceLeaseStoreManager.LeaseManager, new FeedProcessorFactoryCore <T>(this.monitoredContainer, this.changeFeedProcessorOptions, this.documentServiceLeaseStoreManager.LeaseCheckpointer, this.monitoredContainer.ClientContext.SerializerCore), this.changeFeedLeaseOptions); EqualPartitionsBalancingStrategy loadBalancingStrategy = new EqualPartitionsBalancingStrategy( this.instanceName, EqualPartitionsBalancingStrategy.DefaultMinLeaseCount, EqualPartitionsBalancingStrategy.DefaultMaxLeaseCount, this.changeFeedLeaseOptions.LeaseExpirationInterval); PartitionController partitionController = new PartitionControllerCore(this.documentServiceLeaseStoreManager.LeaseContainer, this.documentServiceLeaseStoreManager.LeaseManager, partitionSuperviserFactory, synchronizer); partitionController = new HealthMonitoringPartitionControllerDecorator(partitionController, new TraceHealthMonitor()); PartitionLoadBalancerCore partitionLoadBalancer = new PartitionLoadBalancerCore( partitionController, this.documentServiceLeaseStoreManager.LeaseContainer, loadBalancingStrategy, this.changeFeedLeaseOptions.LeaseAcquireInterval); return(new PartitionManagerCore(bootstrapper, partitionController, partitionLoadBalancer)); }
public async Task AddLease_ThrowsException_LeaseAddingContinues() { FailingPartitionController controller = new FailingPartitionController(); // long acquire interval to ensure that only 1 load balancing iteration is performed in a test run TimeSpan leaseAcquireInterval = TimeSpan.FromHours(1); PartitionLoadBalancerCore loadBalancer = new PartitionLoadBalancerCore(controller, this.leaseContainer, this.strategy, leaseAcquireInterval); Mock.Get(this.strategy) .Setup(s => s.SelectLeasesToTake(It.IsAny <IEnumerable <DocumentServiceLease> >())) .Returns(new[] { Mock.Of <DocumentServiceLease>(), Mock.Of <DocumentServiceLease>() }); Mock.Get(this.leaseContainer) .Setup(m => m.GetAllLeasesAsync()) .ReturnsAsync(new[] { Mock.Of <DocumentServiceLease>(), Mock.Of <DocumentServiceLease>() }); loadBalancer.Start(); await loadBalancer.StopAsync(); Mock.Get(this.strategy) .Verify(s => s.SelectLeasesToTake(It.IsAny <IEnumerable <DocumentServiceLease> >()), Times.Once); Mock.Get(this.leaseContainer) .Verify(m => m.GetAllLeasesAsync(), Times.Once); Assert.AreEqual(2, controller.HitCount); }