public async Task BootstrapProvider_Controllable()
        {
            string controllerName = ControllableBootstrapProviderName;
            string controllerType = typeof(ControllableBootstrapProvider).FullName;

            SiloHandle[] silos    = HostedCluster.GetActiveSilos().ToArray();
            int          numSilos = silos.Length;

            string           args      = "OneSetOfArgs";
            IManagementGrain mgmtGrain = GrainFactory.GetGrain <IManagementGrain>(0);

            object[] replies = await mgmtGrain.SendControlCommandToProvider(controllerType,
                                                                            controllerName,
                                                                            (int)ControllableBootstrapProvider.Commands.EchoArg,
                                                                            args);

            output.WriteLine("Got {0} replies {1}", replies.Length, Utils.EnumerableToString(replies));
            Assert.Equal(numSilos, replies.Length); //  "Expected to get {0} replies to command {1}", numSilos, command
            Assert.True(replies.All(reply => reply.ToString().Equals(args)), $"Got args {args}");

            args    = "DifferentSetOfArgs";
            replies = await mgmtGrain.SendControlCommandToProvider(controllerType,
                                                                   controllerName,
                                                                   (int)ControllableBootstrapProvider.Commands.EchoArg,
                                                                   args);

            output.WriteLine("Got {0} replies {1}", replies.Length, Utils.EnumerableToString(replies));
            Assert.Equal(numSilos, replies.Length); //  "Expected to get {0} replies to command {1}", numSilos, command
            Assert.True(replies.All(reply => reply.ToString().Equals(args)), $"Got args {args}");
        }
        private void SetErrorInjection(string providerName, ErrorInjectionPoint errorInjectionPoint)
        {
            IManagementGrain mgmtGrain = this.HostedCluster.GrainFactory.GetGrain <IManagementGrain>(0);

            mgmtGrain.SendControlCommandToProvider(typeof(ErrorInjectionStorageProvider).FullName,
                                                   providerName, (int)MockStorageProvider.Commands.SetErrorInjection, errorInjectionPoint).Wait();
        }
        private static async Task <bool> AgentManagerOwnCorrectAmountOfAgents(int expectedAgentCountMin, int expectedAgentCountMax, IManagementGrain mgmtGrain, bool assertIsTrue)
        {
            await Task.Delay(TimeSpan.FromSeconds(10));

            bool pass;

            try
            {
                object[] agentStarted = await mgmtGrain.SendControlCommandToProvider(typeof(PersistentStreamProvider).FullName, StreamProviderName, (int)PersistentStreamProviderCommand.GetNumberRunningAgents);

                int[] counts = agentStarted.Select(startedAgentInEachSilo => Convert.ToInt32(startedAgentInEachSilo)).ToArray();
                int   sum    = counts.Sum();
                pass = totalQueueCount == sum &&
                       counts.All(startedAgentInEachSilo => startedAgentInEachSilo <= expectedAgentCountMax && startedAgentInEachSilo >= expectedAgentCountMin);
                if (!pass && assertIsTrue)
                {
                    throw new OrleansException($"AgentManager doesn't own correct amount of agents: {string.Join(",", counts.Select(startedAgentInEachSilo => startedAgentInEachSilo.ToString()))}");
                }
            }
            catch
            {
                pass = false;
                if (assertIsTrue)
                {
                    throw;
                }
            }
            return(pass);
        }
 public static async Task SetErrorInjection(string providerName, ErrorInjectionBehavior errorInjectionBehavior, IGrainFactory grainFactory)
 {
     IManagementGrain mgmtGrain = grainFactory.GetGrain <IManagementGrain>(0);
     await mgmtGrain.SendControlCommandToProvider(
         typeof(ErrorInjectionStorageProvider).FullName,
         providerName,
         (int)Commands.SetErrorInjection,
         errorInjectionBehavior);
 }
Exemplo n.º 5
0
        public async Task BootstrapProvider_Controllable()
        {
            SiloHandle[] silos    = HostedCluster.GetActiveSilos().ToArray();
            int          numSilos = silos.Length;

            string controllerType = typeof(ControllableBootstrapProvider).FullName;
            string controllerName = "bootstrap4";

            int    command = 1;
            string args    = "CommandArgs";

            foreach (SiloHandle silo in silos)
            {
                IList <IBootstrapProvider> providers = silo.Silo.BootstrapProviders;
                output.WriteLine("Found {0} bootstrap providers in silo {1}: {2}",
                                 providers.Count, silo.Name, Utils.EnumerableToString(
                                     providers.Select(pr => pr.Name + "=" + pr.GetType().FullName)));

                Assert.AreEqual(4, providers.Count, "Found correct number of bootstrap providers");

                Assert.IsTrue(providers.Any(bp => bp.Name.Equals(controllerName)), "Name found");
                Assert.IsTrue(providers.Any(bp => bp.GetType().FullName.Equals(controllerType)), "Typefound");
            }

            IManagementGrain mgmtGrain = GrainFactory.GetGrain <IManagementGrain>(0);

            object[] replies = await mgmtGrain.SendControlCommandToProvider(controllerType, controllerName, command, args);

            output.WriteLine("Got {0} replies {1}", replies.Length, Utils.EnumerableToString(replies));
            Assert.AreEqual(numSilos, replies.Length, "Expected to get {0} replies to command {1}", numSilos, command);
            Assert.IsTrue(replies.All(reply => reply.ToString().Equals(command.ToString())), "Got command {0}", command);

            command += 1;
            replies  = await mgmtGrain.SendControlCommandToProvider(controllerType, controllerName, command, args);

            output.WriteLine("Got {0} replies {1}", replies.Length, Utils.EnumerableToString(replies));
            Assert.AreEqual(numSilos, replies.Length, "Expected to get {0} replies to command {1}", numSilos, command);
            Assert.IsTrue(replies.All(reply => reply.ToString().Equals(command.ToString())), "Got command {0}", command);
        }
Exemplo n.º 6
0
        public async Task BootstrapProvider_Controllable()
        {
            SiloHandle[] silos          = HostedCluster.GetActiveSilos().ToArray();
            int          numSilos       = silos.Length;
            string       controllerType = typeof(ControllableBootstrapProvider).FullName;
            string       controllerName = BootstrapProviderName4;

            // check all providers are registered correctly
            foreach (SiloHandle silo in silos)
            {
                var providers = await this.HostedCluster.Client.GetTestHooks(silo).GetAllSiloProviderNames();

                Assert.Contains(BootstrapProviderName1, providers);
                Assert.Contains(BootstrapProviderName2, providers);
                Assert.Contains(BootstrapProviderName3, providers);
                Assert.Contains(BootstrapProviderName4, providers);
            }

            string           args      = "OneSetOfArgs";
            IManagementGrain mgmtGrain = GrainFactory.GetGrain <IManagementGrain>(0);

            object[] replies = await mgmtGrain.SendControlCommandToProvider(controllerType,
                                                                            controllerName, (int)ControllableBootstrapProvider.Commands.EchoArg, args);

            output.WriteLine("Got {0} replies {1}", replies.Length, Utils.EnumerableToString(replies));
            Assert.Equal(numSilos, replies.Length);  //  "Expected to get {0} replies to command {1}", numSilos, command
            Assert.True(replies.All(reply => reply.ToString().Equals(args)), $"Got args {args}");

            args    = "DifferentSetOfArgs";
            replies = await mgmtGrain.SendControlCommandToProvider(controllerType,
                                                                   controllerName, (int)ControllableBootstrapProvider.Commands.EchoArg, args);

            output.WriteLine("Got {0} replies {1}", replies.Length, Utils.EnumerableToString(replies));
            Assert.Equal(numSilos, replies.Length);  //  "Expected to get {0} replies to command {1}", numSilos, command
            Assert.True(replies.All(reply => reply.ToString().Equals(args)), $"Got args {args}");
        }
Exemplo n.º 7
0
        public async Task BootstrapProvider_Controllable()
        {
            SiloHandle[] silos    = HostedCluster.GetActiveSilos().ToArray();
            int          numSilos = silos.Length;

            string controllerType = typeof(ControllableBootstrapProvider).FullName;
            string controllerName = "bootstrap4";

            int    command = 1;
            string args    = "CommandArgs";

            foreach (SiloHandle silo in silos)
            {
                var providers = await silo.TestHook.GetAllSiloProviderNames();

                Assert.Contains("bootstrap1", providers);
                Assert.Contains("bootstrap2", providers);
                Assert.Contains("bootstrap3", providers);
                Assert.Contains("bootstrap4", providers);
            }

            IManagementGrain mgmtGrain = GrainFactory.GetGrain <IManagementGrain>(0);

            object[] replies = await mgmtGrain.SendControlCommandToProvider(controllerType, controllerName, command, args);

            output.WriteLine("Got {0} replies {1}", replies.Length, Utils.EnumerableToString(replies));
            Assert.Equal(numSilos, replies.Length);  //  "Expected to get {0} replies to command {1}", numSilos, command
            Assert.True(replies.All(reply => reply.ToString().Equals(command.ToString())), $"Got command {command}");

            command += 1;
            replies  = await mgmtGrain.SendControlCommandToProvider(controllerType, controllerName, command, args);

            output.WriteLine("Got {0} replies {1}", replies.Length, Utils.EnumerableToString(replies));
            Assert.Equal(numSilos, replies.Length);  //  "Expected to get {0} replies to command {1}", numSilos, command
            Assert.True(replies.All(reply => reply.ToString().Equals(command.ToString())), $"Got command {command}");
        }
Exemplo n.º 8
0
        private async Task <bool> IsBackPressureTriggered()
        {
            IManagementGrain mgmtGrain = this.fixture.HostedCluster.GrainFactory.GetGrain <IManagementGrain>(0);

            object[] replies = await mgmtGrain.SendControlCommandToProvider(typeof(EHStreamProviderWithCreatedCacheList).FullName,
                                                                            StreamProviderName, EHStreamProviderWithCreatedCacheList.AdapterFactory.IsCacheBackPressureTriggeredCommand, null);

            foreach (var re in replies)
            {
                if ((bool)re)
                {
                    return(true);
                }
            }
            return(false);
        }
        public static async Task <bool> AgentManagerOwnCorrectAmountOfAgents(int expectedAgentCountMin, int expectedAgentCountMax, IManagementGrain mgmtGrain, bool assertIsTrue)
        {
            await Task.Delay(TimeSpan.FromSeconds(10));

            try
            {
                if (assertIsTrue)
                {
                    throw new OrleansException($"AgentManager doesn't own correct amount of agents");
                }

                var agentStarted = await mgmtGrain.SendControlCommandToProvider(typeof(MemoryStreamProvider).FullName, StreamProviderName, (int)PersistentStreamProviderCommand.GetNumberRunningAgents);

                return(agentStarted.All(startedAgentInEachSilo => Convert.ToInt32(startedAgentInEachSilo) >= expectedAgentCountMin && Convert.ToInt32(startedAgentInEachSilo) <= expectedAgentCountMax));
            }
            catch { return(false); }
        }