public async Task Controller_ShouldCopyParentLeaseProperties_IfPartitionSplitHappened()
        {
            //arrange
            var customProperties = new Dictionary <string, string> {
                { "key", "value" }
            };
            var    lease        = Mock.Of <ILease>(l => l.PartitionId == PartitionId && l.Properties == customProperties);
            var    synchronizer = Mock.Of <IPartitionSynchronizer>();
            ILease leaseChild1  = CreateMockLease();
            ILease leaseChild2  = CreateMockLease();

            Mock.Get(synchronizer)
            .Setup(s => s.SplitPartitionAsync(It.Is <ILease>(l => l.PartitionId == PartitionId && l.ContinuationToken == LastContinuationToken)))
            .ReturnsAsync(new[] { leaseChild1, leaseChild2 });

            var partitionSupervisor        = Mock.Of <IPartitionSupervisor>(o => o.RunAsync(It.IsAny <CancellationToken>()) == Task.FromException(new PartitionSplitException("message", LastContinuationToken)));
            var partitionSupervisorFactory = Mock.Of <IPartitionSupervisorFactory>(f => f.Create(lease) == partitionSupervisor);
            var leaseManager   = Mock.Of <ILeaseManager>(manager => manager.AcquireAsync(lease) == Task.FromResult(lease));
            var leaseContainer = Mock.Of <ILeaseContainer>();

            var sut = new PartitionController(leaseContainer, leaseManager, partitionSupervisorFactory, synchronizer);

            //act
            await sut.AddOrUpdateLeaseAsync(lease).ConfigureAwait(false);

            await sut.ShutdownAsync().ConfigureAwait(false);

            Mock.Get(leaseChild1)
            .VerifySet(l => l.Properties = customProperties, Times.Once);
            Mock.Get(leaseChild2)
            .VerifySet(l => l.Properties = customProperties, Times.Once);
        }
        public PartitionControllerTests()
        {
            this.lease = Mock.Of <DocumentServiceLease>();
            Mock.Get(this.lease)
            .Setup(l => l.CurrentLeaseToken)
            .Returns("partitionId");

            this.partitionProcessor         = MockPartitionProcessor();
            this.leaseRenewer               = MockRenewer();
            this.observer                   = Mock.Of <ChangeFeedObserver>();
            this.partitionSupervisorFactory = Mock.Of <PartitionSupervisorFactory>(f => f.Create(this.lease) == new PartitionSupervisorCore(this.lease, this.observer, this.partitionProcessor, this.leaseRenewer));

            this.leaseManager = Mock.Of <DocumentServiceLeaseManager>();
            Mock.Get(this.leaseManager).Reset(); // Reset implicit/by default setup of properties.
            Mock.Get(this.leaseManager)
            .Setup(manager => manager.AcquireAsync(this.lease))
            .ReturnsAsync(this.lease);
            Mock.Get(this.leaseManager)
            .Setup(manager => manager.ReleaseAsync(this.lease))
            .Returns(Task.CompletedTask);
            DocumentServiceLeaseContainer leaseContainer = Mock.Of <DocumentServiceLeaseContainer>();

            this.synchronizer = Mock.Of <PartitionSynchronizer>();
            this.sut          = new PartitionControllerCore(leaseContainer, this.leaseManager, this.partitionSupervisorFactory, this.synchronizer);
        }
Exemple #3
0
        private async Task <IPartitionManager> BuildPartitionManagerAsync(ILeaseManager leaseManager)
        {
            this.leaseDocumentClient = this.leaseDocumentClient ?? this.leaseCollectionLocation.CreateDocumentClient();

            DocumentCollection leaseCollection = await this.leaseDocumentClient.GetDocumentCollectionAsync(this.leaseCollectionLocation).ConfigureAwait(false);

            string leaseStoreCollectionLink = leaseCollection.SelfLink;

            string collectionSelfLink       = this.feedCollectionLocation.GetCollectionSelfLink();
            var    factory                  = new CheckpointerObserverFactory(this.observerFactory, this.changeFeedProcessorOptions.CheckpointFrequency);
            var    synchronizer             = new PartitionSynchronizer(this.feedDocumentClient, collectionSelfLink, leaseManager, this.changeFeedProcessorOptions.DegreeOfParallelism, this.changeFeedProcessorOptions.QueryPartitionsMaxBatchSize);
            var    leaseStore               = new LeaseStore(this.leaseDocumentClient, this.leaseCollectionLocation, this.GetLeasePrefix(), leaseStoreCollectionLink);
            var    bootstrapper             = new Bootstrapper(synchronizer, leaseStore, this.lockTime, this.sleepTime);
            var    partitionObserverFactory = new PartitionSupervisorFactory(
                factory,
                leaseManager,
                this.partitionProcessorFactory ?? new PartitionProcessorFactory(this.feedDocumentClient, this.changeFeedProcessorOptions, leaseManager, collectionSelfLink),
                this.changeFeedProcessorOptions);

            var partitionController = new PartitionController(leaseManager, partitionObserverFactory, synchronizer);

            if (this.loadBalancingStrategy == null)
            {
                this.loadBalancingStrategy = new EqualPartitionsBalancingStrategy(this.hostName, this.changeFeedProcessorOptions.MinPartitionCount, this.changeFeedProcessorOptions.MaxPartitionCount, this.changeFeedProcessorOptions.LeaseExpirationInterval);
            }

            var partitionLoadBalancer = new PartitionLoadBalancer(partitionController, leaseManager, this.loadBalancingStrategy, this.changeFeedProcessorOptions.LeaseAcquireInterval);

            return(new PartitionManager(bootstrapper, partitionController, partitionLoadBalancer));
        }
        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);
        }
        public async Task Controller_ShouldPassLastKnownContinuationTokenToSynchronizer_IfPartitionSplitHappened()
        {
            //arrange
            var lease        = Mock.Of <ILease>(l => l.PartitionId == PartitionId && l.ContinuationToken == InitialContinuationToken);
            var synchronizer = Mock.Of <IPartitionSynchronizer>();

            Mock.Get(synchronizer)
            .Setup(s => s.SplitPartitionAsync(It.Is <ILease>(l => l.PartitionId == PartitionId && l.ContinuationToken == LastContinuationToken)))
            .ReturnsAsync(new[] { CreateMockLease(), CreateMockLease() });

            var partitionSupervisor        = Mock.Of <IPartitionSupervisor>(o => o.RunAsync(It.IsAny <CancellationToken>()) == Task.FromException(new PartitionSplitException("message", LastContinuationToken)));
            var partitionSupervisorFactory = Mock.Of <IPartitionSupervisorFactory>(f => f.Create(lease) == partitionSupervisor);
            var leaseManager   = Mock.Of <ILeaseManager>(manager => manager.AcquireAsync(lease) == Task.FromResult(lease));
            var leaseContainer = Mock.Of <ILeaseContainer>();

            var sut = new PartitionController(leaseContainer, leaseManager, partitionSupervisorFactory, synchronizer);

            //act
            await sut.AddOrUpdateLeaseAsync(lease).ConfigureAwait(false);

            //assert
            await sut.ShutdownAsync().ConfigureAwait(false);

            Mock.Get(synchronizer).VerifyAll();
        }
        public async Task Controller_ShouldDeleteParentLease_IfChildLeaseAcquireThrows()
        {
            //arrange
            var    lease        = CreateMockLease(PartitionId);
            var    synchronizer = Mock.Of <IPartitionSynchronizer>();
            ILease leaseChild2  = CreateMockLease();

            Mock.Get(synchronizer)
            .Setup(s => s.SplitPartitionAsync(lease))
            .ReturnsAsync(new[] { CreateMockLease(), leaseChild2 });

            var partitionSupervisor        = Mock.Of <IPartitionSupervisor>(o => o.RunAsync(It.IsAny <CancellationToken>()) == Task.FromException(new PartitionSplitException("message", LastContinuationToken)));
            var partitionSupervisorFactory = Mock.Of <IPartitionSupervisorFactory>(f => f.Create(lease) == partitionSupervisor);
            var leaseManager = Mock.Of <ILeaseManager>(manager =>
                                                       manager.AcquireAsync(lease) == Task.FromResult(lease) &&
                                                       manager.AcquireAsync(leaseChild2) == Task.FromException <ILease>(new LeaseLostException())
                                                       );
            var leaseContainer = Mock.Of <ILeaseContainer>();

            var sut = new PartitionController(leaseContainer, leaseManager, partitionSupervisorFactory, synchronizer);

            //act
            await sut.AddOrUpdateLeaseAsync(lease).ConfigureAwait(false);

            //assert
            await sut.ShutdownAsync().ConfigureAwait(false);

            Mock.Get(leaseManager).Verify(manager => manager.DeleteAsync(lease), Times.Once);
        }
        public async Task Controller_ShouldIgnoreProcessingChildPartition_IfPartitionAlreadyAdded()
        {
            //arrange
            var    lease        = CreateMockLease(PartitionId);
            var    synchronizer = Mock.Of <IPartitionSynchronizer>();
            ILease leaseChild1  = CreateMockLease();
            ILease leaseChild2  = CreateMockLease();

            Mock.Get(synchronizer)
            .Setup(s => s.SplitPartitionAsync(It.Is <ILease>(l => l.PartitionId == PartitionId && l.ContinuationToken == LastContinuationToken)))
            .ReturnsAsync(new[] { leaseChild1, leaseChild2 });

            var partitionSupervisor  = Mock.Of <IPartitionSupervisor>(o => o.RunAsync(It.IsAny <CancellationToken>()) == Task.FromException(new PartitionSplitException("message", LastContinuationToken)));
            var partitionSupervisor1 = Mock.Of <IPartitionSupervisor>();

            Mock.Get(partitionSupervisor1).Setup(o => o.RunAsync(It.IsAny <CancellationToken>())).Returns <CancellationToken>(token => Task.Delay(TimeSpan.FromHours(1), token));
            var partitionSupervisor2 = Mock.Of <IPartitionSupervisor>();

            Mock.Get(partitionSupervisor2).Setup(o => o.RunAsync(It.IsAny <CancellationToken>())).Returns <CancellationToken>(token => Task.Delay(TimeSpan.FromHours(1), token));

            var partitionSupervisorFactory = Mock.Of <IPartitionSupervisorFactory>(f =>
                                                                                   f.Create(lease) == partitionSupervisor && f.Create(leaseChild1) == partitionSupervisor1 && f.Create(leaseChild2) == partitionSupervisor2);
            var leaseManager   = Mock.Of <ILeaseManager>(manager => manager.AcquireAsync(lease) == Task.FromResult(lease));
            var leaseContainer = Mock.Of <ILeaseContainer>();

            var sut = new PartitionController(leaseContainer, leaseManager, partitionSupervisorFactory, synchronizer);

            //act
            await sut.AddOrUpdateLeaseAsync(lease).ConfigureAwait(false);

            await sut.AddOrUpdateLeaseAsync(leaseChild2).ConfigureAwait(false);

            await sut.AddOrUpdateLeaseAsync(leaseChild2).ConfigureAwait(false);

            await sut.AddOrUpdateLeaseAsync(leaseChild2).ConfigureAwait(false);

            await sut.AddOrUpdateLeaseAsync(leaseChild2).ConfigureAwait(false);

            await sut.AddOrUpdateLeaseAsync(leaseChild2).ConfigureAwait(false);

            //assert
            await sut.ShutdownAsync().ConfigureAwait(false);

            Mock.Get(leaseManager)
            .Verify(manager => manager.AcquireAsync(leaseChild2), Times.Once);

            Mock.Get(leaseManager)
            .Verify(manager => manager.UpdatePropertiesAsync(leaseChild2), Times.Exactly(5));

            Mock.Get(partitionSupervisorFactory)
            .Verify(f => f.Create(leaseChild2), Times.Once);
        }
Exemple #8
0
    // Start is called before the first frame update
    void Start()
    {
        model        = GetComponent <Manivelle>();
        view         = GetComponent <ManivelleView>();
        p_controller = GameObject.FindObjectOfType <PartitionController>();
        illustration = GameObject.FindObjectOfType <Illustration>();
        illustration.SetTrans(p_controller.GetBorneLim());
        illustration.SetWait(waitingTime);

        model.SetMaxCrank(p_controller.GetBorneLim());
        source = GameObject.Find("Main Camera").GetComponent <AudioSource>();

        auto_button.gameObject.SetActive(false);
    }
        private IPartitionManager BuildPartitionManager(ILeaseStoreManager leaseStoreManager)
        {
            string feedCollectionSelfLink = this.feedCollectionLocation.GetCollectionSelfLink();
            var    factory      = new CheckpointerObserverFactory(this.observerFactory, this.changeFeedProcessorOptions.CheckpointFrequency);
            var    synchronizer = new PartitionSynchronizer(
                this.feedDocumentClient,
                feedCollectionSelfLink,
                leaseStoreManager,
                leaseStoreManager,
                this.changeFeedProcessorOptions.DegreeOfParallelism,
                this.changeFeedProcessorOptions.QueryPartitionsMaxBatchSize);
            var bootstrapper = new Bootstrapper(synchronizer, leaseStoreManager, this.lockTime, this.sleepTime);
            var partitionSuperviserFactory = new PartitionSupervisorFactory(
                factory,
                leaseStoreManager,
                this.partitionProcessorFactory ?? new PartitionProcessorFactory(this.feedDocumentClient, this.changeFeedProcessorOptions, leaseStoreManager, feedCollectionSelfLink),
                this.changeFeedProcessorOptions);

            if (this.loadBalancingStrategy == null)
            {
                this.loadBalancingStrategy = new EqualPartitionsBalancingStrategy(
                    this.HostName,
                    this.changeFeedProcessorOptions.MinPartitionCount,
                    this.changeFeedProcessorOptions.MaxPartitionCount,
                    this.changeFeedProcessorOptions.LeaseExpirationInterval);
            }

            IPartitionController partitionController = new PartitionController(leaseStoreManager, leaseStoreManager, partitionSuperviserFactory, synchronizer);

            if (this.healthMonitor == null)
            {
                this.healthMonitor = new TraceHealthMonitor();
            }

            partitionController = new HealthMonitoringPartitionControllerDecorator(partitionController, this.healthMonitor);
            var partitionLoadBalancer = new PartitionLoadBalancer(
                partitionController,
                leaseStoreManager,
                this.loadBalancingStrategy,
                this.changeFeedProcessorOptions.LeaseAcquireInterval);

            return(new PartitionManager(bootstrapper, partitionController, partitionLoadBalancer));
        }
Exemple #10
0
        public async Task Controller_ShouldKeepParentLease_IfSplitThrows()
        {
            //arrange
            var lease                      = CreateMockLease(PartitionId);
            var synchronizer               = Mock.Of <IPartitionSynchronizer>(s => s.SplitPartitionAsync(lease) == Task.FromException <IEnumerable <ILease> >(new InvalidOperationException()));
            var partitionSupervisor        = Mock.Of <IPartitionSupervisor>(o => o.RunAsync(It.IsAny <CancellationToken>()) == Task.FromException(new PartitionSplitException("message", LastContinuationToken)));
            var partitionSupervisorFactory = Mock.Of <IPartitionSupervisorFactory>(f => f.Create(lease) == partitionSupervisor);
            var leaseManager               = Mock.Of <ILeaseManager>();

            var sut = new PartitionController(leaseManager, partitionSupervisorFactory, synchronizer);

            //act
            await sut.AddOrUpdateLeaseAsync(lease).ConfigureAwait(false);

            //assert
            await sut.ShutdownAsync().ConfigureAwait(false);

            Mock.Get(leaseManager).Verify(manager => manager.DeleteAsync(lease), Times.Never);
        }
    // Use this for initialization
    void Start()
    {
        poBoxKey            = null;
        partitionController = GameObject.FindGameObjectWithTag("GameController").GetComponent <PartitionController> ();
//		pauseController = GameObject.FindGameObjectWithTag ("GameController").GetComponent<PauseController> ();
        clonePosition = new Vector2(
            this.gameObject.transform.position.x,
            this.gameObject.transform.position.y + CLONE_DISTANCE_Y);


        fractionLabel.Disable();

//		playerData = GameObject.FindGameObjectWithTag ("PlayerData").GetComponent<PlayerData> ();
//		FractionsReference.Instance ().UpdateValidDenominators ();

        if (validDenominators == null)
        {
            Debug.Log("<color=red>Start Error</color>");
        }
    }
        public PartitionControllerSplitTests()
        {
            lease = Mock.Of <ILease>();
            Mock.Get(lease)
            .Setup(l => l.PartitionId)
            .Returns("partitionId");

            leaseChild = Mock.Of <ILease>();
            Mock.Get(leaseChild)
            .Setup(l => l.PartitionId)
            .Returns("childPartitionId");

            leaseChild2 = Mock.Of <ILease>();
            Mock.Get(leaseChild2)
            .Setup(l => l.PartitionId)
            .Returns("childPartitionId2");

            var partitionSupervisor = Mock.Of <IPartitionSupervisor>();

            Mock.Get(partitionSupervisor)
            .Setup(o => o.RunAsync(It.IsAny <CancellationToken>()))
            .ThrowsAsync(new PartitionSplitException("lastContinuation"));

            partitionSupervisorFactory = Mock.Of <IPartitionSupervisorFactory>(f => f.Create(lease) == partitionSupervisor);

            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 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 HealthMonitoringPartitionControllerDecorator(PartitionController inner, HealthMonitor monitor)
 {
     this.inner   = inner ?? throw new ArgumentNullException(nameof(inner));
     this.monitor = monitor ?? throw new ArgumentNullException(nameof(monitor));
 }