Exemplo n.º 1
0
        public void RunAsyncSlowCancellation()
        {
            Console.WriteLine("StatefulServiceLifeCycleTests - Test Method: RunAsyncSlowCancellation()");

            var serviceContext = TestMocksRepository.GetMockStatefulServiceContext();

            var testService = new RunAsyncSlowCancellationTestService(serviceContext);
            IStatefulServiceReplica testServiceReplica = new StatefulServiceReplicaAdapter(serviceContext, testService);

            var partition = new Mock <IStatefulServicePartition>();

            partition.SetupGet(p => p.WriteStatus).Returns(PartitionAccessStatus.Granted);
            partition.Setup(p => p.ReportPartitionHealth(It.IsAny <HealthInformation>()));

            testServiceReplica.OpenAsync(ReplicaOpenMode.New, partition.Object, CancellationToken.None).GetAwaiter().GetResult();

            Console.WriteLine(@"// U -> P");
            testServiceReplica.ChangeRoleAsync(ReplicaRole.Primary, CancellationToken.None).GetAwaiter().GetResult();

            CancellationTokenSource source = new CancellationTokenSource(10000);

            while (!testService.RunAsyncInvoked)
            {
                Task.Delay(100, source.Token).GetAwaiter().GetResult();
            }

            Console.WriteLine(@"// P -> S");
            testServiceReplica.ChangeRoleAsync(ReplicaRole.ActiveSecondary, CancellationToken.None).GetAwaiter().GetResult();

            partition.Verify(p => p.ReportFault(It.IsAny <FaultType>()), Times.Never());
            partition.Verify(p => p.ReportPartitionHealth(It.Is <HealthInformation>(hinfo => Utility.IsRunAsyncSlowCancellationHealthInformation(hinfo))), Times.AtLeastOnce);
        }
Exemplo n.º 2
0
        public void RunAsyncSlowCancellation()
        {
            Console.WriteLine("StatelessServiceLifeCycleTests - Test Method: RunAsyncSlowCancellation()");

            var serviceContext = TestMocksRepository.GetMockStatelessServiceContext();

            var testService = new RunAsyncSlowCancellationTestService(serviceContext);
            IStatelessServiceInstance testServiceReplica = new StatelessServiceInstanceAdapter(serviceContext, testService);

            var partition = new Mock <IStatelessServicePartition>();

            partition.Setup(p => p.ReportPartitionHealth(It.IsAny <HealthInformation>()));

            testServiceReplica.OpenAsync(partition.Object, CancellationToken.None).GetAwaiter().GetResult();

            CancellationTokenSource source = new CancellationTokenSource(10000);

            while (!testService.RunAsyncInvoked)
            {
                Task.Delay(100, source.Token).GetAwaiter().GetResult();
            }

            testServiceReplica.CloseAsync(CancellationToken.None).GetAwaiter().GetResult();

            partition.Verify(p => p.ReportFault(It.IsAny <FaultType>()), Times.Never());
            partition.Verify(p => p.ReportPartitionHealth(It.Is <HealthInformation>(hinfo => Utility.IsRunAsyncSlowCancellationHealthInformation(hinfo))), Times.AtLeastOnce);
        }