Ejemplo n.º 1
0
        private async Task MissingActivation_Runner(int grainId, TimeSpan lazyDeregistrationDelay)
        {
            logger.Info("\n\n\n SMissingActivation_Runner.\n\n\n");

            ITestGrain g = GrainClient.GrainFactory.GetGrain <ITestGrain>(grainId);
            await g.SetLabel("hello_" + grainId);

            var grain = ((GrainReference)await g.GetGrainReference()).GrainId;

            // Call again to make sure the grain is in all silo caches
            for (int i = 0; i < 10; i++)
            {
                var label = await g.GetLabel();
            }

            // Now we know that there's an activation; try both silos and deactivate it incorrectly
            int primaryActivation = await testCluster.Primary.TestHook.UnregisterGrainForTesting(grain);

            int secondaryActivation = await testCluster.SecondarySilos[0].TestHook.UnregisterGrainForTesting(grain);

            Assert.Equal(1, primaryActivation + secondaryActivation);

            // If we try again, we shouldn't find any
            primaryActivation = await testCluster.Primary.TestHook.UnregisterGrainForTesting(grain);

            secondaryActivation = await testCluster.SecondarySilos[0].TestHook.UnregisterGrainForTesting(grain);
            Assert.Equal(0, primaryActivation + secondaryActivation);


            if (lazyDeregistrationDelay > TimeSpan.Zero)
            {
                // Wait a bit
                TimeSpan pause = lazyDeregistrationDelay.Multiply(2);
                logger.Info($"Pausing for {0} because we are using lazy deregistration", pause);
                await Task.Delay(pause);
            }

            // Now send a message again; it should fail);
            var firstEx = await Assert.ThrowsAsync <OrleansException>(() => g.GetLabel());

            Assert.Contains("Non-existent activation", firstEx.Message);
            logger.Info("Got 1st Non-existent activation Exception, as expected.");

            // Try again; it should succeed or fail, based on doLazyDeregistration

            if (lazyDeregistrationDelay > TimeSpan.Zero)
            {
                var newLabel = await g.GetLabel();

                logger.Info("After 2nd call. newLabel = " + newLabel);
            }
            else
            {
                var secondEx = await Assert.ThrowsAsync <OrleansException>(() => g.GetLabel());

                logger.Info("Got 2nd exception - " + secondEx.GetBaseException().Message);
                Assert.True(secondEx.Message.Contains("duplicate activation") || secondEx.Message.Contains("Non-existent activation") ||
                            secondEx.Message.Contains("Forwarding failed"),
                            "2nd exception message: " + secondEx);
                logger.Info("Got 2nd exception, as expected.");
            }
        }