OperationResult OnUseActor(UseActor msg, IOperationContext context)
 {
     _actor = GrainClient.GrainFactory.GetGrain<ITestGrain>(msg.ActorName);
     return OperationResult.Success;
 }
Пример #2
0
 public Task CreateProxy(long key)
 {
     proxy = GrainFactory.GetGrain<ITestGrain>(key);
     return TaskDone.Done;
 }
 public override Task OnActivateAsync()
 {
     logger = GetLogger();
     grain = GrainFactory.GetGrain<ITestGrain>(1);
     logger.Info("OnActivateAsync");
     grain = GrainFactory.GetGrain<ITestGrain>(1);
     return TaskDone.Done;
 }
Пример #4
0
        // check that one can send messages from within extensions.
        public Task <string> CheckExtension_2()
        {
            ITestGrain g = this.grainFactory.GetGrain <ITestGrain>(24);

            return(g.GetLabel());
        }
Пример #5
0
 public HelloWorldController(IGrainFactory client)
 {
     _client    = client;
     _grain     = _client.GetGrain <IHelloWorld>(0);
     _testGrain = _client.GetGrain <ITestGrain>(0);
 }
Пример #6
0
 public Task CreateProxy(long key)
 {
     proxy = GrainFactory.GetGrain <ITestGrain>(key);
     return(TaskDone.Done);
 }
Пример #7
0
        private async Task MissingActivation_Runner(int grainId, bool doLazyDeregistration)
        {
            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();
            }

            // Disable retries in this case, to make test more predictable.
            testCluster.Primary.TestHook.SetMaxForwardCount_ForTesting(0);
            testCluster.SecondarySilos[0].TestHook.SetMaxForwardCount_ForTesting(0);

            var lazyDeregistrationDelay = doLazyDeregistration ? TimeSpan.FromSeconds(2) : TimeSpan.FromMilliseconds(-1);

            testCluster.Primary.TestHook.SetDirectoryLazyDeregistrationDelay_ForTesting(lazyDeregistrationDelay);
            testCluster.SecondarySilos[0].TestHook.SetDirectoryLazyDeregistrationDelay_ForTesting(lazyDeregistrationDelay);

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

            Assert.Equal(1, primaryActivation + secondaryActivation);

            // If we try again, we shouldn't find any
            primaryActivation   = testCluster.Primary.TestHook.UnregisterGrainForTesting(grain);
            secondaryActivation = testCluster.SecondarySilos[0].TestHook.UnregisterGrainForTesting(grain);
            Assert.Equal(0, primaryActivation + secondaryActivation);


            if (doLazyDeregistration)
            {
                // Wait a bit
                TimeSpan pause = lazyDeregistrationDelay.Multiply(2);
                logger.Info("Pausing for {0} because DoLazyDeregistration=True", pause);
                Thread.Sleep(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 (doLazyDeregistration)
            {
                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.");
            }
        }