Ejemplo n.º 1
0
        public async Task GettingGrainWithMultipleConstructorsActivesViaDefaultConstructor()
        {
            ISimpleGrain grain = this.GrainFactory.GetGrain <ISimpleGrain>(GetRandomGrainId(), grainClassNamePrefix: MultipleConstructorsSimpleGrain.MultipleConstructorsSimpleGrainPrefix);

            var actual = await grain.GetA();

            Assert.Equal(MultipleConstructorsSimpleGrain.ValueUsedByParameterlessConstructor, actual);
        }
Ejemplo n.º 2
0
        public void CastAsyncGrainRefCastFromSelf()
        {
            IAddressable grain = GrainClient.GrainFactory.GetGrain <ISimpleGrain>(random.Next(), SimpleGrain.SimpleGrainNamePrefix);;
            ISimpleGrain cast  = grain.AsReference <ISimpleGrain>();

            Task <int> successfulCallPromise = cast.GetA();

            successfulCallPromise.Wait();
            Assert.Equal(TaskStatus.RanToCompletion, successfulCallPromise.Status);
        }
Ejemplo n.º 3
0
        public void GetGrainStatistics_ActivationCounts_OrleansManagedGrains()
        {
            SimpleGrainStatistic[] stats = GetSimpleGrainStatistics("Before Create");
            Assert.IsTrue(stats.Length > 0, "Got some grain statistics: " + stats.Length);

            string grainType = typeof(SimpleGrain).FullName;

            Assert.AreEqual(0, stats.Count(s => s.GrainType == grainType), "No activation counter yet for grain: " + grainType);
            ISimpleGrain grain1 = GrainClient.GrainFactory.GetGrain <ISimpleGrain>(random.Next(), SimpleGrain.SimpleGrainNamePrefix);
            int          x      = grain1.GetA().Result; // Call grain method

            stats = GetSimpleGrainStatistics("After Invoke");
            Assert.AreEqual(1, stats.Count(s => s.GrainType == grainType), "Activation counter now exists for grain: " + grainType);
            SimpleGrainStatistic grainStats = stats.First(s => s.GrainType == grainType);

            Assert.AreEqual(1, grainStats.ActivationCount, "Activation count for grain after activation: " + grainType);
        }
Ejemplo n.º 4
0
        private static void TestGrainReferenceSerialization(int id, bool resolveBeforeSerialize, bool useJson)
        {
            // Make sure grain references serialize well through .NET serializer.
            var grain = GrainClient.GrainFactory.GetGrain <ISimpleGrain>(random.Next(), Grains.SimpleGrain.SimpleGrainNamePrefix);

            if (resolveBeforeSerialize)
            {
                grain.SetA(id).Wait(); //  Resolve GR
            }

            object other;

            if (useJson)
            {
                // Serialize + Deserialise through Json serializer
                other = NewtonsoftJsonSerialiseRoundtrip(grain);
            }
            else
            {
                // Serialize + Deserialise through .NET serializer
                other = DotNetSerialiseRoundtrip(grain);
            }

            if (!resolveBeforeSerialize)
            {
                grain.SetA(id).Wait(); //  Resolve GR
            }

            Assert.IsInstanceOfType(other, grain.GetType(), "Deserialized grain reference type = {0}", grain.GetType());
            ISimpleGrain otherGrain = other as ISimpleGrain;

            Assert.IsNotNull(otherGrain, "Other grain");
            Assert.AreEqual(grain, otherGrain, "Deserialized grain reference equality is preserved");
            int res = otherGrain.GetA().Result;

            Assert.AreEqual(id, res, "Returned values from call to deserialized grain reference");
        }