public async Task PreferLocalPlacementGrain_ShouldNotMigrateWhenOtherSiloKilled(string value) { await HostedCluster.WaitForLivenessToStabilizeAsync(); output.WriteLine("******************** Starting test ({0}) ********************", value); TestSilosStarted(2); foreach (SiloHandle silo in HostedCluster.GetActiveSilos()) { NodeConfiguration cfg = silo.Silo.LocalConfig; Assert.IsNotNull(cfg, "NodeConfiguration should be present for silo " + silo); output.WriteLine( "Silo {0} : Address = {1} Proxy gateway: {2}", cfg.SiloName, cfg.Endpoint, cfg.ProxyGatewayEndpoint); } IPEndPoint targetSilo; if (value == "Primary") { targetSilo = HostedCluster.Primary.Endpoint; } else { targetSilo = HostedCluster.Secondary.Endpoint; } Guid proxyKey; IRandomPlacementTestGrain proxy; IPEndPoint expected; do { proxyKey = Guid.NewGuid(); proxy = GrainFactory.GetGrain <IRandomPlacementTestGrain>(proxyKey); expected = await proxy.GetEndpoint(); } while (!targetSilo.Equals(expected)); output.WriteLine("Proxy grain was originally located on silo {0}", expected); Guid grainKey = proxyKey; await proxy.StartPreferLocalGrain(grainKey); IPreferLocalPlacementTestGrain grain = GrainFactory.GetGrain <IPreferLocalPlacementTestGrain>(grainKey); IPEndPoint actual = await grain.GetEndpoint(); output.WriteLine("PreferLocalPlacement grain was originally located on silo {0}", actual); Assert.AreEqual(expected, actual, "PreferLocalPlacement strategy should create activations on the local silo."); SiloHandle siloToKill = HostedCluster.GetActiveSilos().First(s => !s.Endpoint.Equals(expected)); output.WriteLine("Killing other silo {0} not hosting locally placed grain", siloToKill); HostedCluster.StopSilo(siloToKill); IPEndPoint newActual = await grain.GetEndpoint(); output.WriteLine("PreferLocalPlacement grain is now located on silo {0}", newActual); Assert.AreEqual(expected, newActual, "PreferLocalPlacement strategy should not move activations when other non-hosting silo fails."); }
public async Task PreferLocalPlacementGrain_ShouldMigrateWhenHostSiloKilled(string value) { await HostedCluster.WaitForLivenessToStabilizeAsync(); output.WriteLine("******************** Starting test ({0}) ********************", value); TestSilosStarted(2); foreach (SiloHandle silo in HostedCluster.GetActiveSilos()) { output.WriteLine( "Silo {0} : Address = {1} Proxy gateway: {2}", silo.Name, silo.SiloAddress, silo.GatewayAddress); } IPEndPoint targetSilo; if (value == "Primary") { targetSilo = HostedCluster.Primary.SiloAddress.Endpoint; } else { targetSilo = HostedCluster.SecondarySilos.First().SiloAddress.Endpoint; } Guid proxyKey; IRandomPlacementTestGrain proxy; IPEndPoint expected; do { proxyKey = Guid.NewGuid(); proxy = GrainFactory.GetGrain <IRandomPlacementTestGrain>(proxyKey); expected = await proxy.GetEndpoint(); } while (!targetSilo.Equals(expected)); output.WriteLine("Proxy grain was originally located on silo {0}", expected); Guid grainKey = proxyKey; await proxy.StartPreferLocalGrain(grainKey); IPreferLocalPlacementTestGrain grain = GrainFactory.GetGrain <IPreferLocalPlacementTestGrain>(grainKey); IPEndPoint actual = await grain.GetEndpoint(); output.WriteLine("PreferLocalPlacement grain was originally located on silo {0}", actual); Assert.Equal(expected, actual); // "PreferLocalPlacement strategy should create activations on the local silo." SiloHandle siloToKill = HostedCluster.GetActiveSilos().First(s => s.SiloAddress.Endpoint.Equals(expected)); output.WriteLine("Killing silo {0} hosting locally placed grain", siloToKill); HostedCluster.StopSilo(siloToKill); IPEndPoint newActual = await grain.GetEndpoint(); output.WriteLine("PreferLocalPlacement grain was recreated on silo {0}", newActual); Assert.NotEqual(expected, newActual); // "PreferLocalPlacement strategy should recreate activations on other silo if local fails." }