public async Task FindActiveGrains_typed()
        {
            //IManagementGrain mgmtGrain = GrainClient.GrainFactory.GetGrain<IManagementGrain>(RuntimeInterfaceConstants.SYSTEM_MANAGEMENT_ID);
            //Catalog.GetGrainStatistics();
            // start a second silo and wait for it
            if (HostedCluster.SecondarySilos.Count == 0)
            {
                HostedCluster.StartAdditionalSilo();
                await HostedCluster.WaitForLivenessToStabilizeAsync();
            }

            // create grains
            output.WriteLine("creating and activating grains");
            var grain1 = GrainClient.GrainFactory.GetGrain <ISimpleGrain>(1);
            var grain2 = GrainClient.GrainFactory.GetGrain <ISimpleGrain>(2);
            var grain3 = GrainClient.GrainFactory.GetGrain <ISimpleGrain>(3);
            await grain1.GetA();

            await grain2.GetA();

            await grain3.GetA();

            //enumerate active grains
            output.WriteLine("\n\nour own grain statistics");
            IActiveGrainEnumeratorGrain enumGrain    = GrainClient.GrainFactory.GetGrain <IActiveGrainEnumeratorGrain>(0);
            IEnumerable <IGrain>        activeGrains = enumGrain.GetActiveGrains(typeof(ISimpleGrain)).Result;

            foreach (var entry in activeGrains)
            {
                output.WriteLine("guid = {0}", entry.GetPrimaryKey());
            }

            Assert.Equal(3, activeGrains.AsQueryable().Count());
        }
Esempio n. 2
0
        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.");
        }
Esempio n. 3
0
 public EchoTaskGrainTests(DefaultClusterFixture fixture)
     : base(fixture)
 {
     if (HostedCluster.SecondarySilos.Count == 0)
     {
         HostedCluster.StartAdditionalSilo();
         HostedCluster.WaitForLivenessToStabilizeAsync().Wait();
     }
 }
Esempio n. 4
0
        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."
        }
Esempio n. 5
0
        public async Task GetDetailedHosts()
        {
            if (HostedCluster.SecondarySilos.Count == 0)
            {
                HostedCluster.StartAdditionalSilo();
                await HostedCluster.WaitForLivenessToStabilizeAsync();
            }

            var numberOfActiveSilos = 1 + HostedCluster.SecondarySilos.Count; // Primary + secondaries
            var siloStatuses        = mgmtGrain.GetDetailedHosts(true).Result;

            Assert.NotNull(siloStatuses);
            Assert.Equal(numberOfActiveSilos, siloStatuses.Length);
        }
Esempio n. 6
0
        public async Task GetHosts()
        {
            if (HostedCluster.SecondarySilos.Count == 0)
            {
                HostedCluster.StartAdditionalSilo();
                await HostedCluster.WaitForLivenessToStabilizeAsync();
            }

            var numberOfActiveSilos = 1 + HostedCluster.SecondarySilos.Count; // Primary + secondaries
            Dictionary <SiloAddress, SiloStatus> siloStatuses = mgmtGrain.GetHosts(true).Result;

            Assert.IsNotNull(siloStatuses, "Got some silo statuses");
            Assert.AreEqual(numberOfActiveSilos, siloStatuses.Count, "Number of silo statuses");
        }
        public async Task Test_Indexing_IndexLookup3()
        {
            //await GrainClient.GrainFactory.DropAllIndexes<IPlayerGrain>();

            if (HostedCluster.SecondarySilos.Count == 0)
            {
                HostedCluster.StartAdditionalSilo();
                await HostedCluster.WaitForLivenessToStabilizeAsync();
            }

            IPlayer2Grain p1 = GrainClient.GrainFactory.GetGrain <IPlayer2Grain>(1);
            await p1.SetLocation("Seattle");

            //bool isLocIndexCreated = await GrainClient.GrainFactory.CreateAndRegisterIndex<HashIndexSingleBucketInterface<string, IPlayerGrain>, PlayerLocIndexGen>("__GetLocation");
            //Assert.IsTrue(isLocIndexCreated);

            IPlayer2Grain p2 = GrainClient.GrainFactory.GetGrain <IPlayer2Grain>(2);
            IPlayer2Grain p3 = GrainClient.GrainFactory.GetGrain <IPlayer2Grain>(3);

            await p2.SetLocation("Seattle");

            await p3.SetLocation("San Fransisco");

            IndexInterface <string, IPlayer2Grain> locIdx = GrainClient.GrainFactory.GetIndex <string, IPlayer2Grain>("__Location");

            while (!await locIdx.IsAvailable())
            {
                Thread.Sleep(50);
            }

            output.WriteLine("Before check 1");
            Assert.Equal(2, await IndexingTestUtils.CountPlayersStreamingIn <IPlayer2Grain, Player2Properties>("Seattle", output, DELAY_UNTIL_INDEXES_ARE_UPDATED_LAZILY));

            await p2.Deactivate();

            await Task.Delay(DELAY_UNTIL_INDEXES_ARE_UPDATED_LAZILY);

            output.WriteLine("Before check 2");
            Assert.Equal(1, await IndexingTestUtils.CountPlayersStreamingIn <IPlayer2Grain, Player2Properties>("Seattle", output, DELAY_UNTIL_INDEXES_ARE_UPDATED_LAZILY));

            p2 = GrainClient.GrainFactory.GetGrain <IPlayer2Grain>(2);
            output.WriteLine("Before check 3");
            Assert.Equal("Seattle", await p2.GetLocation());

            output.WriteLine("Before check 4");
            Assert.Equal(2, await IndexingTestUtils.CountPlayersStreamingIn <IPlayer2Grain, Player2Properties>("Seattle", output, DELAY_UNTIL_INDEXES_ARE_UPDATED_LAZILY));
            output.WriteLine("Done.");
        }
Esempio n. 8
0
        public async Task Test_Indexing_IndexLookup3()
        {
            //await GrainClient.GrainFactory.DropAllIndexes<IPlayerGrain>();

            if (HostedCluster.SecondarySilos.Count == 0)
            {
                HostedCluster.StartAdditionalSilo();
                await HostedCluster.WaitForLivenessToStabilizeAsync();
            }

            IPlayer2GrainNonFaultTolerant p1 = GrainClient.GrainFactory.GetGrain <IPlayer2GrainNonFaultTolerant>(1);
            await p1.SetLocation("Seattle");

            //bool isLocIndexCreated = await GrainClient.GrainFactory.CreateAndRegisterIndex<HashIndexSingleBucketInterface<string, IPlayerGrain>, PlayerLocIndexGen>("__GetLocation");
            //Assert.IsTrue(isLocIndexCreated);

            IPlayer2GrainNonFaultTolerant p2 = GrainClient.GrainFactory.GetGrain <IPlayer2GrainNonFaultTolerant>(2);
            IPlayer2GrainNonFaultTolerant p3 = GrainClient.GrainFactory.GetGrain <IPlayer2GrainNonFaultTolerant>(3);

            await p2.SetLocation("Seattle");

            await p3.SetLocation("San Fransisco");

            IndexInterface <string, IPlayer2GrainNonFaultTolerant> locIdx = GrainClient.GrainFactory.GetIndex <string, IPlayer2GrainNonFaultTolerant>("__Location");

            while (!await locIdx.IsAvailable())
            {
                Thread.Sleep(50);
            }

            Assert.Equal(2, await IndexingTestUtils.CountPlayersStreamingIn <IPlayer2GrainNonFaultTolerant, Player2PropertiesNonFaultTolerant>("Seattle", output));

            await p2.Deactivate();

            Thread.Sleep(1000);

            Assert.Equal(1, await IndexingTestUtils.CountPlayersStreamingIn <IPlayer2GrainNonFaultTolerant, Player2PropertiesNonFaultTolerant>("Seattle", output));

            p2 = GrainClient.GrainFactory.GetGrain <IPlayer2GrainNonFaultTolerant>(2);
            Assert.Equal("Seattle", await p2.GetLocation());

            Assert.Equal(2, await IndexingTestUtils.CountPlayersStreamingIn <IPlayer2GrainNonFaultTolerant, Player2PropertiesNonFaultTolerant>("Seattle", output));
        }
        private async Task RestartSiloAfterCheckpointTestRunner(string streamNamespace, int streamCount, int eventsInStream)
        {
            List<Guid> streamGuids = Enumerable.Range(0, streamCount).Select(_ => Guid.NewGuid()).ToList();
            try
            {
                await GenerateEvents(streamNamespace, streamGuids, eventsInStream, 0);
                await TestingUtils.WaitUntilAsync(assertIsTrue => CheckCounters(streamNamespace, streamCount, eventsInStream, assertIsTrue), TimeSpan.FromSeconds(60));

                HostedCluster.RestartSilo(HostedCluster.SecondarySilos[0]);
                await HostedCluster.WaitForLivenessToStabilizeAsync();

                await GenerateEvents(streamNamespace, streamGuids, eventsInStream, 0);
                await TestingUtils.WaitUntilAsync(assertIsTrue => CheckCounters(streamNamespace, streamCount, eventsInStream * 2, assertIsTrue), TimeSpan.FromSeconds(90));
            }
            finally
            {
                var reporter = this.GrainFactory.GetGrain<IGeneratedEventReporterGrain>(GeneratedStreamTestConstants.ReporterId);
                reporter.Reset().Ignore();
            }
        }