private async Task DeactivateOnIdle_NonExistentActivation_Runner(int forwardCount) { var builder = new TestClusterBuilder(2); builder.AddClientBuilderConfigurator <ClientConfigurator>(); builder.AddSiloBuilderConfigurator <SiloConfigurator>(); builder.Properties["MaxForwardCount"] = forwardCount.ToString(); Initialize(builder); ICollectionTestGrain grain = await PickGrainInNonPrimary(); output.WriteLine("About to make a 1st GetAge() call."); TimeSpan age = await grain.GetAge(); output.WriteLine(age.ToString()); await grain.DeactivateSelf(); await Task.Delay(3000); var thrownException = await Record.ExceptionAsync(() => grain.GetAge()); Assert.Null(thrownException); output.WriteLine("\nThe 1st call after DeactivateSelf has NOT thrown any exception as expected, since forwardCount is {0}.\n", forwardCount); }
private async Task <ICollectionTestGrain> PickGrainInNonPrimary() { for (int i = 0; i < 500; i++) { if (i % 30 == 29) { await Task.Delay(1000); // give some extra time to stabilize if it can't find a suitable grain } // Create grain such that: // Its directory owner is not the Gateway silo. This way Gateway will use its directory cache. // Its activation is located on the non Gateway silo as well. ICollectionTestGrain grain = this.testCluster.GrainFactory.GetGrain <ICollectionTestGrain>(i); GrainId grainId = ((GrainReference)await grain.GetGrainReference()).GrainId; SiloAddress primaryForGrain = (await TestUtils.GetDetailedGrainReport(this.testCluster.InternalGrainFactory, grainId, this.testCluster.Primary)).PrimaryForGrain; if (primaryForGrain.Equals(this.testCluster.Primary.SiloAddress)) { continue; } string siloHostingActivation = await grain.GetRuntimeInstanceId(); if (this.testCluster.Primary.SiloAddress.ToLongString().Equals(siloHostingActivation)) { continue; } this.output.WriteLine("\nCreated grain with key {0} whose primary directory owner is silo {1} and which was activated on silo {2}\n", i, primaryForGrain.ToLongString(), siloHostingActivation); return(grain); } Assert.True(testCluster.GetActiveSilos().Count() > 1, "This logic requires at least 1 non-primary active silo"); Assert.True(false, "Could not find a grain that activates on a non-primary silo, and has the partition be also managed by a non-primary silo"); return(null); }
private async Task <ICollectionTestGrain> PickGrain() { for (int i = 0; i < 100; i++) { // Create grain such that: // Its directory owner is not the Gateway silo. This way Gateway will use its directory cache. // Its activation is located on the non Gateway silo as well. ICollectionTestGrain grain = GrainClient.GrainFactory.GetGrain <ICollectionTestGrain>(i); GrainId grainId = ((GrainReference)await grain.GetGrainReference()).GrainId; SiloAddress primaryForGrain = (await TestUtils.GetDetailedGrainReport(grainId, testCluster.Primary)).PrimaryForGrain; if (primaryForGrain.Equals(testCluster.Primary.SiloAddress)) { continue; } string siloHostingActivation = await grain.GetRuntimeInstanceId(); if (testCluster.Primary.SiloAddress.ToLongString().Equals(siloHostingActivation)) { continue; } logger.Info("\nCreated grain with key {0} whose primary directory owner is silo {1} and which was activated on silo {2}\n", i, primaryForGrain.ToLongString(), siloHostingActivation); return(grain); } return(null); }
public void CollectionTest_GrainId_TypeCode() { ICollectionTestGrain g1 = GrainClient.GrainFactory.GetGrain <ICollectionTestGrain>(1); GrainId id1 = ((GrainReference)g1).GrainId; UniqueKey k1 = id1.Key; Console.WriteLine("GrainId={0} UniqueKey={1} PK={2} KeyType={3} IdCategory={4}", id1, k1, id1.GetPrimaryKeyLong(), k1.IdCategory, k1.BaseTypeCode); Assert.IsTrue(id1.IsGrain, "GrainReference should be for a grain"); Assert.AreEqual(UniqueKey.Category.Grain, k1.IdCategory, "GrainId should be for self-managed type"); Assert.AreEqual(1, k1.PrimaryKeyToLong(), "Encoded primary key should match"); Assert.AreEqual(1381240679, k1.BaseTypeCode, "Encoded type code data should match"); }
public void CollectionTest_GrainId_TypeCode() { var g1Key = GetRandomGrainId(); ICollectionTestGrain g1 = this.GrainFactory.GetGrain <ICollectionTestGrain>(g1Key); GrainId id1 = ((GrainReference)g1).GrainId; UniqueKey k1 = id1.Key; output.WriteLine("GrainId={0} UniqueKey={1} PK={2} KeyType={3} IdCategory={4}", id1, k1, id1.GetPrimaryKeyLong(), k1.IdCategory, k1.BaseTypeCode); Assert.True(id1.IsGrain, "GrainReference should be for a grain"); Assert.Equal(UniqueKey.Category.Grain, k1.IdCategory); // "GrainId should be for self-managed type" Assert.Equal(g1Key, k1.PrimaryKeyToLong()); // "Encoded primary key should match" Assert.Equal(1381240679, k1.BaseTypeCode); // "Encoded type code data should match" }
private async Task DeactivateOnIdle_NonExistentActivation_Runner(int forwardCount) { var builder = new TestClusterBuilder(2); builder.ConfigureLegacyConfiguration(legacy => { legacy.ClusterConfiguration.Globals.MaxForwardCount = forwardCount; // For this test we only want to talk to the primary legacy.ClientConfiguration.Gateways.RemoveAt(1); if (forwardCount == 0) { // Disable reminder service for this test: when the secondary silo starts it may // not see right away the activation from the primary silo. This request should be forwarded // to the correct activation, but since we deactivate forwarding, the secondary silo will // fail to start... legacy.ClusterConfiguration.Globals.ReminderServiceType = GlobalConfiguration.ReminderServiceProviderType.Disabled; } }); Initialize(builder); ICollectionTestGrain grain = await PickGrainInNonPrimary(); output.WriteLine("About to make a 1st GetAge() call."); TimeSpan age = await grain.GetAge(); output.WriteLine(age.ToString()); await grain.DeactivateSelf(); await Task.Delay(3000); // ReSharper disable once PossibleNullReferenceException var thrownException = await Record.ExceptionAsync(() => grain.GetAge()); if (forwardCount != 0) { Assert.Null(thrownException); output.WriteLine("\nThe 1st call after DeactivateSelf has NOT thrown any exception as expected, since forwardCount is {0}.\n", forwardCount); } else { Assert.NotNull(thrownException); Assert.IsType <OrleansMessageRejectionException>(thrownException); Assert.Contains("Non-existent activation", thrownException.Message); output.WriteLine("\nThe 1st call after DeactivateSelf has thrown Non-existent activation exception as expected, since forwardCount is {0}.\n", forwardCount); // Try sending agan now and see it was fixed. await grain.GetAge(); } }
private async Task DeactivateOnIdle_NonExistentActivation_Runner(int forwardCount) { var options = new TestClusterOptions(2); options.ClusterConfiguration.Globals.MaxForwardCount = forwardCount; options.ClusterConfiguration.Defaults.Generation = 13; // For this test we only want to talk to the primary options.ClientConfiguration.Gateways.RemoveAt(1); Initialize(options); ICollectionTestGrain grain = await PickGrain(); Assert.NotNull(grain); logger.Info("About to make a 1st GetAge() call."); TimeSpan age = await grain.GetAge(); logger.Info(age.ToString()); await grain.DeactivateSelf(); Thread.Sleep(3000); // ReSharper disable once PossibleNullReferenceException var thrownException = await Record.ExceptionAsync(() => grain.GetAge()); if (forwardCount != 0) { Assert.Null(thrownException); logger.Info("\nThe 1st call after DeactivateSelf has NOT thrown any exception as expected, since forwardCount is {0}.\n", forwardCount); } else { Assert.NotNull(thrownException); Assert.IsType <OrleansException>(thrownException); Assert.Contains("Non-existent activation", thrownException.Message); logger.Info("\nThe 1st call after DeactivateSelf has thrown Non-existent activation exception as expected, since forwardCount is {0}.\n", forwardCount); // Try sending agan now and see it was fixed. await grain.GetAge(); } }
private async Task DeactivateOnIdle_NonExistentActivation_Runner(int forwardCount) { var builder = new TestClusterBuilder(2); builder.AddClientBuilderConfigurator <ClientConfigurator>(); builder.AddSiloBuilderConfigurator <SiloConfigurator>(); builder.Properties["MaxForwardCount"] = forwardCount.ToString(); Initialize(builder); ICollectionTestGrain grain = await PickGrainInNonPrimary(); output.WriteLine("About to make a 1st GetAge() call."); TimeSpan age = await grain.GetAge(); output.WriteLine(age.ToString()); await grain.DeactivateSelf(); await Task.Delay(3000); // ReSharper disable once PossibleNullReferenceException var thrownException = await Record.ExceptionAsync(() => grain.GetAge()); if (forwardCount != 0) { Assert.Null(thrownException); output.WriteLine("\nThe 1st call after DeactivateSelf has NOT thrown any exception as expected, since forwardCount is {0}.\n", forwardCount); } else { Assert.NotNull(thrownException); Assert.IsType <OrleansMessageRejectionException>(thrownException); Assert.Contains("Non-existent activation", thrownException.Message); output.WriteLine("\nThe 1st call after DeactivateSelf has thrown Non-existent activation exception as expected, since forwardCount is {0}.\n", forwardCount); // Try sending agan now and see it was fixed. await grain.GetAge(); } }
public Task SetOther(ICollectionTestGrain other) { Logger().Info("SetOther."); this.other = other; return TaskDone.Done; }
public Task SetOther(ICollectionTestGrain other) { Logger().Info("SetOther."); this.other = other; return(Task.CompletedTask); }
public Task SetOther(ICollectionTestGrain other) { Logger().Info("SetOther."); this.other = other; return(TaskDone.Done); }