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 IfCannotAcquireRetry() { Mock <PartitionSynchronizer> synchronizer = new Mock <PartitionSynchronizer>(); synchronizer.Setup(s => s.CreateMissingLeasesAsync()).Returns(Task.CompletedTask); Mock <DocumentServiceLeaseStore> leaseStore = new Mock <DocumentServiceLeaseStore>(); leaseStore.Setup(l => l.IsInitializedAsync()).ReturnsAsync(false); leaseStore.SetupSequence(l => l.AcquireInitializationLockAsync(It.IsAny <TimeSpan>())) .ReturnsAsync(false) .ReturnsAsync(true); leaseStore.Setup(l => l.MarkInitializedAsync()).Returns(Task.CompletedTask); leaseStore.Setup(l => l.ReleaseInitializationLockAsync()).ReturnsAsync(true); TimeSpan lockTime = TimeSpan.FromSeconds(1); TimeSpan sleepTime = TimeSpan.FromSeconds(1); BootstrapperCore bootstrapper = new BootstrapperCore(synchronizer.Object, leaseStore.Object, lockTime, sleepTime); await bootstrapper.InitializeAsync(); Mock.Get(leaseStore.Object) .Verify(store => store.IsInitializedAsync(), Times.Exactly(2)); Mock.Get(leaseStore.Object) .Verify(store => store.AcquireInitializationLockAsync(It.IsAny <TimeSpan>()), Times.Exactly(2)); Mock.Get(leaseStore.Object) .Verify(store => store.MarkInitializedAsync(), Times.Once); Mock.Get(synchronizer.Object) .Verify(store => store.CreateMissingLeasesAsync(), Times.Once); Mock.Get(leaseStore.Object) .Verify(store => store.ReleaseInitializationLockAsync(), Times.Once); }
public static void Shutdown() { lock (_LockObject) { if (_BootstrapperCore != null) { _BootstrapperCore.Shutdown(); } _BootstrapperCore = null; } }
public static IBootstrapperConfiguration Create() { lock (_LockObject) { if (_BootstrapperCore != null) { throw new InvalidOperationException("Cannot Create Bootstrapper more than once"); } _BootstrapperCore = new BootstrapperCore(); return(_BootstrapperCore); } }