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 async Task RemoveProvidersAndVerify(List <string> streamProviderNames)
        {
            mgmtGrain = GrainClient.GrainFactory.GetGrain <IManagementGrain>(RuntimeInterfaceConstants.SYSTEM_MANAGEMENT_ID);
            List <string> names = fixture.HostedCluster.Primary.Silo.TestHook.GetStreamProviderNames().ToList();
            int           Count = names.Count;

            foreach (string name in streamProviderNames)
            {
                if (fixture.HostedCluster.ClusterConfiguration.Globals.ProviderConfigurations[ProviderCategoryConfiguration.STREAM_PROVIDER_CATEGORY_NAME].Providers.ContainsKey(name))
                {
                    fixture.HostedCluster.ClusterConfiguration.Globals.ProviderConfigurations[ProviderCategoryConfiguration.STREAM_PROVIDER_CATEGORY_NAME].Providers.Remove(name);
                }
            }

            SiloAddress[] address = new SiloAddress[1];
            address[0] = fixture.HostedCluster.Primary.Silo.SiloAddress;
            await mgmtGrain.UpdateStreamProviders(address, fixture.HostedCluster.ClusterConfiguration.Globals.ProviderConfigurations);

            names = fixture.HostedCluster.Primary.Silo.TestHook.GetStreamProviderNames().ToList();
            List <string> allSiloProviderNames = fixture.HostedCluster.Primary.Silo.TestHook.GetAllSiloProviderNames().ToList();

            Assert.Equal(Count - names.Count, streamProviderNames.Count);
            Assert.Equal(allSiloProviderNames.Count, names.Count);
            foreach (String name in streamProviderNames)
            {
                Assert.Equal(names.Contains(name), false);
            }
            foreach (String name in streamProviderNames)
            {
                Assert.Equal(allSiloProviderNames.Contains(name), false);
            }
        }
Beispiel #3
0
        public MetricsTrackerTelemetryConsumer(IProviderRuntime runtime)
        {
            try
            {
                Runtime = runtime;

                logger = Runtime.GetLogger(nameof(MetricsTrackerTelemetryConsumer));

                Configuration = new MetricsConfiguration();

                Counters       = new ConcurrentDictionary <string, long>();
                CounterHistory = new ConcurrentDictionary <string, ConcurrentQueue <long> >();

                Metrics       = new ConcurrentDictionary <string, double>();
                MetricHistory = new ConcurrentDictionary <string, ConcurrentQueue <double> >();

                TimeSpanMetrics       = new ConcurrentDictionary <string, TimeSpan>();
                TimeSpanMetricHistory = new ConcurrentDictionary <string, ConcurrentQueue <TimeSpan> >();

                Requests       = new ConcurrentDictionary <string, MeasuredRequest>();
                RequestHistory = new ConcurrentDictionary <string, ConcurrentQueue <MeasuredRequest> >();

                // start a message pump to give ourselves the right synchronization context
                // from which we can communicate with grains via normal grain references
                // TODO: don't start the pump until it's been requested
                StartMessagePump().Ignore();

                Management = Runtime.GrainFactory.GetGrain <IManagementGrain>(0);
            }
            catch (Exception ex)
            {
                logger.TrackException(ex);
                throw;
            }
        }
        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();
        }
Beispiel #5
0
        private async Task RemoveProvidersAndVerify(ICollection <string> streamProviderNames)
        {
            mgmtGrain = GrainClient.GrainFactory.GetGrain <IManagementGrain>(0);
            ICollection <string> names = await fixture.HostedCluster.Primary.TestHook.GetStreamProviderNames();

            int Count = names.Count;

            foreach (string name in streamProviderNames)
            {
                if (fixture.HostedCluster.ClusterConfiguration.Globals.ProviderConfigurations[ProviderCategoryConfiguration.STREAM_PROVIDER_CATEGORY_NAME].Providers.ContainsKey(name))
                {
                    fixture.HostedCluster.ClusterConfiguration.Globals.ProviderConfigurations[ProviderCategoryConfiguration.STREAM_PROVIDER_CATEGORY_NAME].Providers.Remove(name);
                }
            }

            SiloAddress[] address = new SiloAddress[1];
            address[0] = fixture.HostedCluster.Primary.SiloAddress;
            await mgmtGrain.UpdateStreamProviders(address, fixture.HostedCluster.ClusterConfiguration.Globals.ProviderConfigurations);

            names = await fixture.HostedCluster.Primary.TestHook.GetStreamProviderNames();

            ICollection <string> allSiloProviderNames = await fixture.HostedCluster.Primary.TestHook.GetAllSiloProviderNames();

            Assert.Equal(Count - names.Count, streamProviderNames.Count);
            Assert.Equal(allSiloProviderNames.Count, names.Count);
            foreach (String name in streamProviderNames)
            {
                Assert.DoesNotContain(name, names);;
            }
            foreach (String name in streamProviderNames)
            {
                Assert.DoesNotContain(name, allSiloProviderNames);
            }
        }
Beispiel #6
0
        protected async Task <bool> CheckGrainCounts()
        {
#if USE_GENERICS
            string grainType = typeof(StreamReliabilityTestGrain <int>).FullName;
#else
            string grainType = typeof(StreamReliabilityTestGrain).FullName;
#endif
            IManagementGrain mgmtGrain = this.GrainFactory.GetGrain <IManagementGrain>(0);

            SimpleGrainStatistic[] grainStats = await mgmtGrain.GetSimpleGrainStatistics();

            output.WriteLine("Found grains " + Utils.EnumerableToString(grainStats));

            var grainLocs = grainStats.Where(gs => gs.GrainType == grainType).ToArray();

            Assert.True(grainLocs.Length > 0, "Found too few grains");
            Assert.True(grainLocs.Length <= 2, "Found too many grains " + grainLocs.Length);

            bool sameSilo = grainLocs.Length == 1;
            if (sameSilo)
            {
                StreamTestUtils.Assert_AreEqual(output, 2, grainLocs[0].ActivationCount, "Num grains on same Silo " + grainLocs[0].SiloAddress);
            }
            else
            {
                StreamTestUtils.Assert_AreEqual(output, 1, grainLocs[0].ActivationCount, "Num grains on Silo " + grainLocs[0].SiloAddress);
                StreamTestUtils.Assert_AreEqual(output, 1, grainLocs[1].ActivationCount, "Num grains on Silo " + grainLocs[1].SiloAddress);
            }
            return(sameSilo);
        }
Beispiel #7
0
        public static async Task <int> GetNumActivations(IEnumerable <IGrain> targets)
        {
            var grainIds = targets.Distinct().Where(t => t is GrainReference).Select(t => ((GrainReference)t).GrainId).ToArray();
            IManagementGrain systemManagement = GrainClient.GrainFactory.GetGrain <IManagementGrain>(RuntimeInterfaceConstants.SYSTEM_MANAGEMENT_ID);
            var tasks = grainIds.Select(g => systemManagement.GetGrainActivationCount(GrainReference.FromGrainId(g))).ToArray();
            await Task.WhenAll(tasks);

            return(tasks.Sum(t => t.Result));
        }
 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);
 }
        public static async Task <int> GetNumActivations(IEnumerable <IGrain> targets, IInternalGrainFactory grainFactory)
        {
            var grainIds = targets.Distinct().Where(t => t is GrainReference).Select(t => ((GrainReference)t).GrainId).ToArray();
            IManagementGrain systemManagement = grainFactory.GetGrain <IManagementGrain>(0);
            var tasks = grainIds.Select(g => systemManagement.GetGrainActivationCount((GrainReference)grainFactory.GetGrain(g))).ToArray();
            await Task.WhenAll(tasks);

            return(tasks.Sum(t => t.Result));
        }
        private static async Task PropigateStatisticsToCluster(IGrainFactory grainFactory)
        {
            // force the latched statistics to propigate throughout the cluster.
            IManagementGrain mgmtGrain =
                grainFactory.GetGrain <IManagementGrain>(0);

            var hosts = await mgmtGrain.GetHosts(true);

            var keys = hosts.Select(kvp => kvp.Key).ToArray();
            await mgmtGrain.ForceRuntimeStatisticsCollection(keys);
        }
Beispiel #11
0
        private static void RunCommand(string command, string[] args)
        {
            var clientBuilder = new ClientBuilder().LoadConfiguration();

            using (client = (IInternalClusterClient)clientBuilder.Build())
            {
                client.Connect().Wait();
                systemManagement = client.GetGrain <IManagementGrain>(0);
                var options = args.Skip(1)
                              .Where(s => s.StartsWith("-"))
                              .Select(s => s.Substring(1).Split('='))
                              .ToDictionary(a => a[0].ToLowerInvariant(), a => a.Length > 1 ? a[1] : "");

                var restWithoutOptions = args.Skip(1).Where(s => !s.StartsWith("-")).ToArray();

                switch (command)
                {
                case "grainstats":
                    PrintSimpleGrainStatistics(restWithoutOptions);
                    break;

                case "fullgrainstats":
                    PrintGrainStatistics(restWithoutOptions);
                    break;

                case "collect":
                    CollectActivations(options, restWithoutOptions);
                    break;

                case "unregister":
                    var unregisterArgs = args.Skip(1).ToArray();
                    UnregisterGrain(unregisterArgs);
                    break;

                case "lookup":
                    var lookupArgs = args.Skip(1).ToArray();
                    LookupGrain(lookupArgs);
                    break;

                case "grainreport":
                    var grainReportArgs = args.Skip(1).ToArray();
                    GrainReport(grainReportArgs);
                    break;

                default:
                    PrintUsage();
                    break;
                }

                client.Close().Wait();
            }
        }
Beispiel #12
0
        protected void TestSilosStarted(int expected)
        {
            IManagementGrain mgmtGrain = GrainClient.GrainFactory.GetGrain <IManagementGrain>(1); // is nornally RuntimeInterfaceConstants.SYSTEM_MANAGEMENT_ID

            Dictionary <SiloAddress, SiloStatus> statuses = mgmtGrain.GetHosts(onlyActive: true).Result;

            foreach (var pair in statuses)
            {
                logger.Info("       ######## Silo {0}, status: {1}", pair.Key, pair.Value);
                Assert.Equal(
                    SiloStatus.Active,
                    pair.Value);
            }
            Assert.Equal(expected, statuses.Count);
        }
Beispiel #13
0
        private void TestSilosStarted(int expected)
        {
            IManagementGrain mgmtGrain = GrainFactory.GetGrain <IManagementGrain>(0);

            Dictionary <SiloAddress, SiloStatus> statuses = mgmtGrain.GetHosts(onlyActive: true).Result;

            foreach (var pair in statuses)
            {
                logger.Info("       ######## Silo {0}, status: {1}", pair.Key, pair.Value);
                Assert.Equal(
                    SiloStatus.Active,
                    pair.Value);
            }
            Assert.Equal(expected, statuses.Count);
        }
Beispiel #14
0
        private async Task <Dictionary <SiloHandle, int> > GetPerSiloActivationCounts()
        {
            string fullTypeName = "UnitTests.Grains.ActivationCountBasedPlacementTestGrain";

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

            SimpleGrainStatistic[] stats = await mgmtGrain.GetSimpleGrainStatistics();

            return(this.HostedCluster.GetActiveSilos()
                   .ToDictionary(
                       s => s,
                       s => stats
                       .Where(stat => stat.SiloAddress.Equals(s.SiloAddress) && stat.GrainType == fullTypeName)
                       .Select(stat => stat.ActivationCount).SingleOrDefault()));
        }
Beispiel #15
0
        public async Task PingOtherSiloAsync()
        {
            logger.Info("IEchoGrainAsync.PingOtherSilo");
            SiloAddress mySilo = Data.Address.Silo;

            IManagementGrain mgmtGrain = GrainFactory.GetGrain <IManagementGrain>(0);
            var silos = await mgmtGrain.GetHosts();

            SiloAddress siloAddress = silos.Where(pair => !pair.Key.Equals(mySilo)).Select(pair => pair.Key).First();

            logger.Info("Sending Ping to remote silo {0}", siloAddress);

            await GetSiloControlReference(siloAddress).Ping("PingOtherSilo-" + siloAddress);

            logger.Info("Ping reply received for {0}", siloAddress);
        }
Beispiel #16
0
        public override async Task OnActivateAsync()
        {
            await base.OnActivateAsync();

            _managementGrain = GrainFactory.GetGrain <IManagementGrain>(0);
            _logger          = GetLogger();
            CurrentStats     = new List <UpdateModel>();

            await Hydrate();

            var configTimerPeriods = ConfigurationManager.AppSettings["DashboardCollectorGrainTimerPeriods"];
            var timerPeriods       = configTimerPeriods?.Split(',').Select(int.Parse).ToArray() ?? new[] { 2, 6 };

            RegisterTimer(p => GetChanges(), null, TimeSpan.FromSeconds(timerPeriods[0]), TimeSpan.FromSeconds(timerPeriods[1]));
            await GrainFactory.GetGrain <IFilterGrain>(Guid.Empty).KeepAlive();
        }
Beispiel #17
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);
        }
Beispiel #18
0
        private static void RunCommand(string command, string[] args)
        {
            GrainClient.Initialize();

            systemManagement = GrainClient.GrainFactory.GetGrain <IManagementGrain>(RuntimeInterfaceConstants.SYSTEM_MANAGEMENT_ID);
            Dictionary <string, string> options = args.Skip(1)
                                                  .Where(s => s.StartsWith("-"))
                                                  .Select(s => s.Substring(1).Split('='))
                                                  .ToDictionary(a => a[0].ToLowerInvariant(), a => a.Length > 1 ? a[1] : "");

            var restWithoutOptions = args.Skip(1).Where(s => !s.StartsWith("-")).ToArray();

            switch (command)
            {
            case "grainstats":
                PrintSimpleGrainStatistics(restWithoutOptions);
                break;

            case "fullgrainstats":
                PrintGrainStatistics(restWithoutOptions);
                break;

            case "collect":
                CollectActivations(options, restWithoutOptions);
                break;

            case "unregister":
                var unregisterArgs = args.Skip(1).ToArray();
                UnregisterGrain(unregisterArgs);
                break;

            case "lookup":
                var lookupArgs = args.Skip(1).ToArray();
                LookupGrain(lookupArgs);
                break;

            case "grainreport":
                var grainReportArgs = args.Skip(1).ToArray();
                GrainReport(grainReportArgs);
                break;

            default:
                PrintUsage();
                break;
            }
        }
Beispiel #19
0
        private static void RunCommand(string command, string[] args)
        {
            GrainClient.Initialize();

            systemManagement = GrainClient.GrainFactory.GetGrain<IManagementGrain>(RuntimeInterfaceConstants.SYSTEM_MANAGEMENT_ID);
            Dictionary<string, string> options = args.Skip(1)
                .Where(s => s.StartsWith("-"))
                .Select(s => s.Substring(1).Split('='))
                .ToDictionary(a => a[0].ToLowerInvariant(), a => a.Length > 1 ? a[1] : "");

            var restWithoutOptions = args.Skip(1).Where(s => !s.StartsWith("-")).ToArray();

            switch (command)
            {
                case "grainstats":
                    PrintSimpleGrainStatistics(restWithoutOptions);
                    break;

                case "fullgrainstats":
                    PrintGrainStatistics(restWithoutOptions);
                    break;

                case "collect":
                    CollectActivations(options, restWithoutOptions);
                    break;

                case "unregister":
                    var unregisterArgs = args.Skip(1).ToArray();
                    UnregisterGrain(unregisterArgs);
                    break;

                case "lookup":
                    var lookupArgs = args.Skip(1).ToArray();
                    LookupGrain(lookupArgs);
                    break;

                case "grainreport":
                    var grainReportArgs = args.Skip(1).ToArray();
                    GrainReport(grainReportArgs);
                    break;

                default:
                    PrintUsage();
                    break;
            }
        }
Beispiel #20
0
        protected async Task Do_Liveness_OracleTest_1()
        {
            Console.WriteLine("DeploymentId= {0}", DeploymentId);

            SiloHandle silo3 = StartAdditionalSilo();

            IManagementGrain mgmtGrain = GrainClient.GrainFactory.GetGrain <IManagementGrain>(RuntimeInterfaceConstants.SYSTEM_MANAGEMENT_ID);

            Dictionary <SiloAddress, SiloStatus> statuses = await mgmtGrain.GetHosts(false);

            foreach (var pair in statuses)
            {
                Console.WriteLine("       ######## Silo {0}, status: {1}", pair.Key, pair.Value);
                Assert.AreEqual(SiloStatus.Active, pair.Value);
            }
            Assert.AreEqual(3, statuses.Count);

            IPEndPoint address = silo3.Endpoint;

            Console.WriteLine("About to stop {0}", address);
            StopSilo(silo3);

            // TODO: Should we be allowing time for changes to percolate?

            Console.WriteLine("----------------");

            statuses = await mgmtGrain.GetHosts(false);

            foreach (var pair in statuses)
            {
                Console.WriteLine("       ######## Silo {0}, status: {1}", pair.Key, pair.Value);
                IPEndPoint silo = pair.Key.Endpoint;
                if (silo.Equals(address))
                {
                    Assert.IsTrue(pair.Value.Equals(SiloStatus.ShuttingDown) ||
                                  pair.Value.Equals(SiloStatus.Stopping) ||
                                  pair.Value.Equals(SiloStatus.Dead),
                                  "SiloStatus for {0} should now be ShuttingDown or Stopping or Dead instead of {1}",
                                  silo, pair.Value);
                }
                else
                {
                    Assert.AreEqual(SiloStatus.Active, pair.Value, "SiloStatus for {0}", silo);
                }
            }
        }
Beispiel #21
0
        public static async Task <int> GetActivationCount(string fullTypeName)
        {
            int result = 0;

            IManagementGrain mgmtGrain = GrainClient.GrainFactory.GetGrain <IManagementGrain>(RuntimeInterfaceConstants.SYSTEM_MANAGEMENT_ID);

            SimpleGrainStatistic[] stats = await mgmtGrain.GetSimpleGrainStatistics();

            foreach (var stat in stats)
            {
                if (stat.GrainType == fullTypeName)
                {
                    result += stat.ActivationCount;
                }
            }
            return(result);
        }
Beispiel #22
0
        public static async Task <int> GetActivationCount(IGrainFactory grainFactory, string fullTypeName)
        {
            int result = 0;

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

            SimpleGrainStatistic[] stats = await mgmtGrain.GetSimpleGrainStatistics();

            foreach (var stat in stats)
            {
                if (stat.GrainType == fullTypeName)
                {
                    result += stat.ActivationCount;
                }
            }
            return(result);
        }
        public async Task RequestContext_ActivityId_DynamicChange_Server()
        {
            Guid activityId  = Guid.NewGuid();
            Guid activityId2 = Guid.NewGuid();

            const string PropagateActivityIdConfigKey = @"/OrleansConfiguration/Defaults/Tracing/@PropagateActivityId";
            var          changeConfig = new Dictionary <string, string>();

            IManagementGrain mgmtGrain = GrainClient.GrainFactory.GetGrain <IManagementGrain>(RuntimeInterfaceConstants.SYSTEM_MANAGEMENT_ID);

            IRequestContextTestGrain grain = GrainClient.GrainFactory.GetGrain <IRequestContextTestGrain>(GetRandomGrainId());

            Trace.CorrelationManager.ActivityId = activityId;
            Guid result = await grain.E2EActivityId();

            Assert.AreEqual(activityId, result, "E2E ActivityId #1 not propagated correctly");
            RequestContext.Clear();

            changeConfig[PropagateActivityIdConfigKey] = Boolean.FalseString;
            output.WriteLine("Set {0}={1}", PropagateActivityIdConfigKey, changeConfig[PropagateActivityIdConfigKey]);
            await mgmtGrain.UpdateConfiguration(null, changeConfig, null);

            Trace.CorrelationManager.ActivityId = activityId2;
            result = await grain.E2EActivityId();

            Assert.AreNotEqual(activityId2, result, "E2E ActivityId #2 should not have been propagated");
            Assert.AreEqual(Guid.Empty, result, "E2E ActivityId #2 should not have been propagated");
            RequestContext.Clear();

            changeConfig[PropagateActivityIdConfigKey] = Boolean.TrueString;
            output.WriteLine("Set {0}={1}", PropagateActivityIdConfigKey, changeConfig[PropagateActivityIdConfigKey]);
            await mgmtGrain.UpdateConfiguration(null, changeConfig, null);

            Trace.CorrelationManager.ActivityId = activityId2;
            result = await grain.E2EActivityId();

            Assert.AreEqual(activityId2, result, "E2E ActivityId #2 should have been propagated");
            RequestContext.Clear();

            Trace.CorrelationManager.ActivityId = activityId;
            result = await grain.E2EActivityId();

            Assert.AreEqual(activityId, result, "E2E ActivityId #1 not propagated correctly after #2");
            RequestContext.Clear();
        }
Beispiel #24
0
        public async Task RequestContext_ActivityId_CM_DynamicChange_Server()
        {
            Guid activityId  = Guid.NewGuid();
            Guid activityId2 = Guid.NewGuid();

            const string PropagateActivityIdConfigKey = @"/OrleansConfiguration/Defaults/Tracing/@PropagateActivityId";
            var          changeConfig = new Dictionary <string, string>();

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

            IRequestContextTestGrain grain = this.fixture.GrainFactory.GetGrain <IRequestContextTestGrain>(GetRandomGrainId());

            RequestContextTestUtils.SetActivityId(activityId);
            Guid result = await grain.E2EActivityId();

            Assert.Equal(activityId, result);   // "E2E ActivityId #1 not propagated correctly"
            RequestContext.Clear();

            changeConfig[PropagateActivityIdConfigKey] = Boolean.FalseString;
            output.WriteLine("Set {0}={1}", PropagateActivityIdConfigKey, changeConfig[PropagateActivityIdConfigKey]);
            await mgmtGrain.UpdateConfiguration(null, changeConfig, null);

            RequestContextTestUtils.SetActivityId(activityId2);
            result = await grain.E2EActivityId();

            Assert.NotEqual(activityId2, result); // "E2E ActivityId #2 should not have been propagated"
            Assert.Equal(Guid.Empty, result);     // "E2E ActivityId #2 should not have been propagated"
            RequestContext.Clear();

            changeConfig[PropagateActivityIdConfigKey] = Boolean.TrueString;
            output.WriteLine("Set {0}={1}", PropagateActivityIdConfigKey, changeConfig[PropagateActivityIdConfigKey]);
            await mgmtGrain.UpdateConfiguration(null, changeConfig, null);

            RequestContextTestUtils.SetActivityId(activityId2);
            result = await grain.E2EActivityId();

            Assert.Equal(activityId2, result);   // "E2E ActivityId #2 should have been propagated"
            RequestContext.Clear();

            RequestContextTestUtils.SetActivityId(activityId);
            result = await grain.E2EActivityId();

            Assert.Equal(activityId, result);   // "E2E ActivityId #1 not propagated correctly after #2"
            RequestContext.Clear();
        }
Beispiel #25
0
        protected async Task Do_Liveness_OracleTest_1()
        {
            output.WriteLine("ClusterId= {0}", this.HostedCluster.Options.ClusterId);

            SiloHandle silo3 = this.HostedCluster.StartAdditionalSilo();

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

            Dictionary <SiloAddress, SiloStatus> statuses = await mgmtGrain.GetHosts(false);

            foreach (var pair in statuses)
            {
                output.WriteLine("       ######## Silo {0}, status: {1}", pair.Key, pair.Value);
                Assert.Equal(SiloStatus.Active, pair.Value);
            }
            Assert.Equal(3, statuses.Count);

            IPEndPoint address = silo3.SiloAddress.Endpoint;

            output.WriteLine("About to stop {0}", address);
            this.HostedCluster.StopSilo(silo3);

            // TODO: Should we be allowing time for changes to percolate?

            output.WriteLine("----------------");

            statuses = await mgmtGrain.GetHosts(false);

            foreach (var pair in statuses)
            {
                output.WriteLine("       ######## Silo {0}, status: {1}", pair.Key, pair.Value);
                IPEndPoint silo = pair.Key.Endpoint;
                if (silo.Equals(address))
                {
                    Assert.True(pair.Value == SiloStatus.ShuttingDown ||
                                pair.Value == SiloStatus.Stopping ||
                                pair.Value == SiloStatus.Dead,
                                string.Format("SiloStatus for {0} should now be ShuttingDown or Stopping or Dead instead of {1}", silo, pair.Value));
                }
                else
                {
                    Assert.Equal(SiloStatus.Active, pair.Value);
                }
            }
        }
Beispiel #26
0
        public async Task PingClusterMemberAsync()
        {
            logger.Info("IEchoGrainAsync.PingClusterMemberAsync");
            SiloAddress mySilo = Data.Address.Silo;

            IManagementGrain mgmtGrain = GrainFactory.GetGrain <IManagementGrain>(RuntimeInterfaceConstants.SYSTEM_MANAGEMENT_ID);
            var silos = await mgmtGrain.GetHosts();

            SiloAddress siloAddress = silos.Where(pair => !pair.Key.Equals(mySilo)).Select(pair => pair.Key).First();

            logger.Info("Sending Ping to remote silo {0}", siloAddress);

            var oracle = InsideRuntimeClient.Current.InternalGrainFactory.GetSystemTarget <IMembershipService>(Constants.MembershipOracleId, siloAddress);

            await oracle.Ping(1);

            logger.Info("Ping reply received for {0}", siloAddress);
        }
Beispiel #27
0
        public async Task PingClusterMemberAsync()
        {
            logger.Info("IEchoGrainAsync.PingClusterMemberAsync");
            SiloAddress mySilo = Data.Address.Silo;

            IManagementGrain mgmtGrain = GrainFactory.GetGrain <IManagementGrain>(0);
            var silos = await mgmtGrain.GetHosts();

            SiloAddress siloAddress = silos.Where(pair => !pair.Key.Equals(mySilo)).Select(pair => pair.Key).First();

            logger.Info("Sending Ping to remote silo {0}", siloAddress);

            var oracle = this.internalGrainFactory.GetSystemTarget <IMembershipService>(Constants.MembershipServiceType, siloAddress);

            await oracle.Ping(1);

            logger.Info("Ping reply received for {0}", siloAddress);
        }
Beispiel #28
0
        protected void TestSilosStarted(int expected)
        {
            IManagementGrain mgmtGrain = GrainClient.GrainFactory.GetGrain <IManagementGrain>(RuntimeInterfaceConstants.SYSTEM_MANAGEMENT_ID);

            Dictionary <SiloAddress, SiloStatus> statuses = mgmtGrain.GetHosts(onlyActive: true).Result;

            foreach (var pair in statuses)
            {
                Console.WriteLine("       ######## Silo {0}, status: {1}", pair.Key, pair.Value);
                Assert.AreEqual(
                    SiloStatus.Active,
                    pair.Value,
                    "Failed to confirm start of {0} silos ({1} confirmed).",
                    pair.Value,
                    SiloStatus.Active);
            }
            Assert.AreEqual(expected, statuses.Count);
        }
Beispiel #29
0
        private async Task AddProvidersAndVerify(ICollection <string> streamProviderNames)
        {
            mgmtGrain = GrainClient.GrainFactory.GetGrain <IManagementGrain>(0);
            ICollection <string> names = await fixture.HostedCluster.Primary.TestHook.GetStreamProviderNames();

            IDictionary <string, bool> hasNewProvider = new Dictionary <string, bool>();

            int count = names.Count;

            SiloAddress[] address = new SiloAddress[1];
            address[0] = fixture.HostedCluster.Primary.SiloAddress;
            await mgmtGrain.UpdateStreamProviders(address, fixture.HostedCluster.ClusterConfiguration.Globals.ProviderConfigurations);

            names = await fixture.HostedCluster.Primary.TestHook.GetStreamProviderNames();

            ICollection <string> allSiloProviderNames = await fixture.HostedCluster.Primary.TestHook.GetAllSiloProviderNames();

            Assert.Equal(names.Count - count, streamProviderNames.Count);
            Assert.Equal(allSiloProviderNames.Count, names.Count);
            foreach (string name in names)
            {
                if (streamProviderNames.Contains(name))
                {
                    Assert.DoesNotContain(name, hasNewProvider.Keys);
                    hasNewProvider[name] = true;
                }
            }

            Assert.Equal(hasNewProvider.Count, streamProviderNames.Count);

            hasNewProvider.Clear();
            foreach (String name in allSiloProviderNames)
            {
                if (streamProviderNames.Contains(name))
                {
                    Assert.DoesNotContain(name, hasNewProvider.Keys);
                    hasNewProvider[name] = true;
                }
            }
            Assert.Equal(hasNewProvider.Count, streamProviderNames.Count);
        }
Beispiel #30
0
        public MetricsTrackerTelemetryConsumer(IProviderRuntime runtime, TaskScheduler taskScheduler)
        {
            try
            {
                Runtime       = runtime;
                TaskScheduler = taskScheduler;

                logger = Runtime.GetLogger(nameof(MetricsTrackerTelemetryConsumer));

                Configuration = new MetricsConfiguration();

                Counters       = new ConcurrentDictionary <string, long>();
                CounterHistory = new ConcurrentDictionary <string, ConcurrentQueue <long> >();

                Metrics       = new ConcurrentDictionary <string, double>();
                MetricHistory = new ConcurrentDictionary <string, ConcurrentQueue <double> >();

                TimeSpanMetrics       = new ConcurrentDictionary <string, TimeSpan>();
                TimeSpanMetricHistory = new ConcurrentDictionary <string, ConcurrentQueue <TimeSpan> >();

                Requests       = new ConcurrentDictionary <string, MeasuredRequest>();
                RequestHistory = new ConcurrentDictionary <string, ConcurrentQueue <MeasuredRequest> >();

                PreviousInterceptor = Runtime.GetInvokeInterceptor();

                // start a message pump to give ourselves the right synchronization context
                // from which we can communicate with grains via normal grain references
                // TODO: don't start the pump until it's been requested
                //StartMessagePump().Ignore();
                //Task.Factory.StartNew(() => StartMessagePump(), CancellationToken.None, TaskCreationOptions.None, TaskScheduler);
                var dispatchTask = Dispatch(() => StartMessagePump());

                Management = Runtime.GrainFactory.GetGrain <IManagementGrain>(0);
            }
            catch (Exception ex)
            {
                logger.TrackException(ex);
                throw;
            }
        }
        private async Task AddProvidersAndVerify(List <string> streamProviderNames)
        {
            mgmtGrain = GrainClient.GrainFactory.GetGrain <IManagementGrain>(RuntimeInterfaceConstants.SYSTEM_MANAGEMENT_ID);
            List <string> names = fixture.HostedCluster.Primary.Silo.TestHook.GetStreamProviderNames().ToList();

            IDictionary <string, bool> hasNewProvider = new Dictionary <string, bool>();

            int Count = names.Count;

            SiloAddress[] address = new SiloAddress[1];
            address[0] = fixture.HostedCluster.Primary.Silo.SiloAddress;
            await mgmtGrain.UpdateStreamProviders(address, fixture.HostedCluster.ClusterConfiguration.Globals.ProviderConfigurations);

            names = fixture.HostedCluster.Primary.Silo.TestHook.GetStreamProviderNames().ToList();
            List <string> allSiloProviderNames = fixture.HostedCluster.Primary.Silo.TestHook.GetAllSiloProviderNames().ToList();

            Assert.Equal(names.Count - Count, streamProviderNames.Count);
            Assert.Equal(allSiloProviderNames.Count, names.Count);
            foreach (string name in names)
            {
                if (streamProviderNames.Contains(name))
                {
                    Assert.Equal(hasNewProvider.ContainsKey(name), false);
                    hasNewProvider[name] = true;
                }
            }

            Assert.Equal(hasNewProvider.Count, streamProviderNames.Count);

            hasNewProvider.Clear();
            foreach (String name in allSiloProviderNames)
            {
                if (streamProviderNames.Contains(name))
                {
                    Assert.Equal(hasNewProvider.ContainsKey(name), false);
                    hasNewProvider[name] = true;
                }
            }
            Assert.Equal(hasNewProvider.Count, streamProviderNames.Count);
        }
 public void TestInitialize()
 {
     mgmtGrain = GrainClient.GrainFactory.GetGrain<IManagementGrain>(RuntimeInterfaceConstants.SYSTEM_MANAGEMENT_ID);
 }
Beispiel #33
0
 public void TestInitialize()
 {
     Console.WriteLine("TestInitialize - {0}", TestContext.TestName);
     StreamNamespace = StreamTestsConstants.StreamLifecycleTestsNamespace;
     mgmtGrain = GrainClient.GrainFactory.GetGrain<IManagementGrain>(RuntimeInterfaceConstants.SYSTEM_MANAGEMENT_ID);
 }
Beispiel #34
0
 public StreamLimitTests(ITestOutputHelper output)
 {
     this.output = output;
     StreamNamespace = StreamTestsConstants.StreamLifecycleTestsNamespace;
     mgmtGrain = GrainClient.GrainFactory.GetGrain<IManagementGrain>(0);
 }
 public ClientWrapper(string name, int gatewayport)
     : base(name, gatewayport)
 {
     systemManagement = GrainClient.GrainFactory.GetGrain<IManagementGrain>(RuntimeInterfaceConstants.SYSTEM_MANAGEMENT_ID);
 }
Beispiel #36
0
 public StreamLimitTests(ITestOutputHelper output)
 {
     this.output = output;
     StreamNamespace = StreamTestsConstants.StreamLifecycleTestsNamespace;
     mgmtGrain = GrainClient.GrainFactory.GetGrain<IManagementGrain>(RuntimeInterfaceConstants.SYSTEM_MANAGEMENT_ID);
 }