public void GetGrainStatistics_ActivationCounts_SelfManagedGrains() { SimpleGrainStatistic[] stats = GetSimpleGrainStatistics("Before Create"); Assert.IsTrue(stats.Length > 0, "Got some grain statistics: " + stats.Length); string grainType = typeof(TestGrain).FullName; Assert.AreEqual(0, stats.Count(s => s.GrainType == grainType), "No activation counter yet for grain: " + grainType); ITestGrain grain1 = GrainClient.GrainFactory.GetGrain <ITestGrain>(1); long x = grain1.GetKey().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); }
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); }
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); }
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); }
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); }
public void BasicActivation_Fail() { bool failed; long key = 0; try { // Key values of -2 are not allowed in this case ITestGrain fail = GrainClient.GrainFactory.GetGrain <ITestGrain>(-2); key = fail.GetKey().Result; failed = false; } catch (Exception e) { Assert.IsAssignableFrom <OrleansException>(e.GetBaseException()); failed = true; } if (!failed) { Assert.True(false, "Should have failed, but instead returned " + key); } }
public async Task BasicActivation_Fail() { bool failed; long key = 0; try { // Key values of -2 are not allowed in this case ITestGrain fail = this.GrainFactory.GetGrain <ITestGrain>(-2); key = await fail.GetKey(); failed = false; } catch (ArgumentException) { failed = true; } if (!failed) { Assert.True(false, "Should have failed, but instead returned " + key); } }