Exemple #1
0
        public async Task <string> DoSomething()
        {
            logger.LogInformation("DoSomething");
            var guid = Guid.NewGuid();
            await grain.SetLabel(guid.ToString());

            var label = await grain.GetLabel();

            if (string.IsNullOrEmpty(label))
            {
                throw new ArgumentException("Bad data: Null label returned");
            }
            return(RuntimeHelpers.GetHashCode(this).ToString("X"));
        }
        public async Task <string> DoSomething()
        {
            logger.Info("DoSomething");
            var guid = Guid.NewGuid();
            await grain.SetLabel(guid.ToString());

            var label = await grain.GetLabel();

            if (string.IsNullOrEmpty(label))
            {
                throw new ArgumentException("Bad data: Null label returned");
            }
            return(Data.ActivationId.ToString());
        }
        public void BasicActivation_ActivateAndUpdate()
        {
            ITestGrain g1 = GrainClient.GrainFactory.GetGrain <ITestGrain>(1);
            ITestGrain g2 = GrainClient.GrainFactory.GetGrain <ITestGrain>(2);

            Assert.AreEqual(1L, g1.GetPrimaryKeyLong());
            Assert.AreEqual(1L, g1.GetKey().Result);
            Assert.AreEqual("1", g1.GetLabel().Result);
            Assert.AreEqual(2L, g2.GetKey().Result);
            Assert.AreEqual("2", g2.GetLabel().Result);

            g1.SetLabel("one").Wait();
            Assert.AreEqual("one", g1.GetLabel().Result);
            Assert.AreEqual("2", g2.GetLabel().Result);

            ITestGrain g1a = GrainClient.GrainFactory.GetGrain <ITestGrain>(1);

            Assert.AreEqual("one", g1a.GetLabel().Result);
        }
Exemple #4
0
        public void BasicActivation_ULong_MaxValue()
        {
            ulong key1AsUlong = UInt64.MaxValue; // == -1L
            long  key1        = (long)key1AsUlong;

            ITestGrain g1 = GrainClient.GrainFactory.GetGrain <ITestGrain>(key1);

            Assert.Equal(key1, g1.GetPrimaryKeyLong());
            Assert.Equal((long)key1AsUlong, g1.GetPrimaryKeyLong());
            Assert.Equal(key1, g1.GetKey().Result);
            Assert.Equal(key1.ToString(CultureInfo.InvariantCulture), g1.GetLabel().Result);

            g1.SetLabel("MaxValue").Wait();
            Assert.Equal("MaxValue", g1.GetLabel().Result);

            ITestGrain g1a = GrainClient.GrainFactory.GetGrain <ITestGrain>((long)key1AsUlong);

            Assert.Equal("MaxValue", g1a.GetLabel().Result);
            Assert.Equal(key1, g1a.GetPrimaryKeyLong());
            Assert.Equal((long)key1AsUlong, g1a.GetKey().Result);
        }
Exemple #5
0
        public void BasicActivation_ActivateAndUpdate()
        {
            long       g1Key = GetRandomGrainId();
            long       g2Key = GetRandomGrainId();
            ITestGrain g1    = GrainClient.GrainFactory.GetGrain <ITestGrain>(g1Key);
            ITestGrain g2    = GrainClient.GrainFactory.GetGrain <ITestGrain>(g2Key);

            Assert.Equal(g1Key, g1.GetPrimaryKeyLong());
            Assert.Equal(g1Key, g1.GetKey().Result);
            Assert.Equal(g1Key.ToString(), g1.GetLabel().Result);
            Assert.Equal(g2Key, g2.GetKey().Result);
            Assert.Equal(g2Key.ToString(), g2.GetLabel().Result);

            g1.SetLabel("one").Wait();
            Assert.Equal("one", g1.GetLabel().Result);
            Assert.Equal(g2Key.ToString(), g2.GetLabel().Result);

            ITestGrain g1a = GrainClient.GrainFactory.GetGrain <ITestGrain>(g1Key);

            Assert.Equal("one", g1a.GetLabel().Result);
        }
Exemple #6
0
        public void BasicActivation_Long_MinValue()
        {
            long  key1        = Int64.MinValue;
            ulong key1AsUlong = (ulong)key1;

            ITestGrain g1 = this.GrainFactory.GetGrain <ITestGrain>(key1);

            Assert.Equal((long)key1AsUlong, g1.GetPrimaryKeyLong());
            Assert.Equal(key1, g1.GetPrimaryKeyLong());
            Assert.Equal(key1, g1.GetKey().Result);
            Assert.Equal(key1.ToString(CultureInfo.InvariantCulture), g1.GetLabel().Result);

            g1.SetLabel("MinValue").Wait();
            Assert.Equal("MinValue", g1.GetLabel().Result);

            ITestGrain g1a = this.GrainFactory.GetGrain <ITestGrain>((long)key1AsUlong);

            Assert.Equal("MinValue", g1a.GetLabel().Result);
            Assert.Equal(key1, g1a.GetPrimaryKeyLong());
            Assert.Equal((long)key1AsUlong, g1a.GetKey().Result);
        }
        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.");
            }
        }