Beispiel #1
0
        static void Main(string[] args)
        {
            var options = new Options();
            if (CommandLine.Parser.Default.ParseArguments(args, options))
            {
                Bluepath.Log.DistributedMemoryHost = options.RedisHost;
                Bluepath.Log.WriteInfoToConsole = false;
                var bluepathListener = new BluepathListener(options.Ip, options.Port);
                using (var serviceDiscoveryClient
                    = new CentralizedDiscovery.Client.CentralizedDiscovery(
                        new ServiceUri(options.CentralizedDiscoveryURI, BindingType.BasicHttpBinding),
                        bluepathListener
                        )
                      )
                {
                    using (var connectionManager = new ConnectionManager(
                            remoteService: null,
                            listener: bluepathListener,
                            serviceDiscovery: serviceDiscoveryClient,
                            serviceDiscoveryPeriod: TimeSpan.FromSeconds(30)))
                    {
                        System.Threading.Thread.Sleep(1500);
                        var scheduler = new ThreadNumberScheduler(connectionManager);

                        if (options.IsSlave == 0)
                        {
                            Log.TraceMessage(Log.Activity.Custom, "Running master");
                            //RunRedisTest(options);
                            RunTest(connectionManager, scheduler, options);
                        }
                        else
                        {
                            Log.TraceMessage(Log.Activity.Custom, "Running slave");
                        }

                        Console.WriteLine("Press <Enter> to stop the service.");
                        Console.ReadLine();
                    }
                }
            }
        }
        public void ConnectionManagerAddsNewServicesFromRemoteServiceDiscovery()
        {
            var serviceDiscoveryHost = new CentralizedDiscovery.CentralizedDiscoveryListener("localhost", 30000);
            var bluepathListener1 = new Bluepath.Services.BluepathListener("localhost", 30001);
            var bluepathListener2 = new Bluepath.Services.BluepathListener("localhost", 30002);
            var bluepathListener3 = new Bluepath.Services.BluepathListener("localhost", 30003);
            try
            {
                using (var serviceDiscoveryClient1
                    = new CentralizedDiscovery.Client.CentralizedDiscovery(serviceDiscoveryHost.MasterUri, bluepathListener1))
                {
                    using (var serviceDiscoveryClient2
                        = new CentralizedDiscovery.Client.CentralizedDiscovery(serviceDiscoveryHost.MasterUri, bluepathListener2))
                    {
                        var connectionManager = new Bluepath.Services.ConnectionManager(remoteService: null,
                            listener: bluepathListener1,
                            serviceDiscovery: serviceDiscoveryClient1,
                            serviceDiscoveryPeriod: new TimeSpan(days: 0, hours: 0, minutes: 0, seconds: 0, milliseconds: 100));
                        TestHelpers.RepeatUntilTrue(() => connectionManager.RemoteServices.Count() == 1, times: 10);

                        connectionManager.RemoteServices.Count().ShouldBe(1);
                        using (var serviceDiscoveryClient3
                            = new CentralizedDiscovery.Client.CentralizedDiscovery(serviceDiscoveryHost.MasterUri, bluepathListener3))
                        {
                            TestHelpers.RepeatUntilTrue(() => connectionManager.RemoteServices.Count() == 2, times: 10);
                            connectionManager.RemoteServices.Count().ShouldBe(2);
                        }

                    }
                }
            }
            finally
            {
                serviceDiscoveryHost.Stop();
                bluepathListener1.Stop();
                bluepathListener2.Stop();
                bluepathListener3.Stop();
            }
        }
        public void CentralizedDiscoveryProvidesInformationAboutLoadOfTheNodes()
        {
            var serviceDiscoveryHost = new CentralizedDiscovery.CentralizedDiscoveryListener("localhost", 41000);
            var bluepathListener1 = new Bluepath.Services.BluepathListener("localhost", 41001);
            var bluepathListener2 = new Bluepath.Services.BluepathListener("localhost", 41002);
            try
            {
                using (var serviceDiscoveryClient1
                    = new CentralizedDiscovery.Client.CentralizedDiscovery(serviceDiscoveryHost.MasterUri, bluepathListener1))
                {
                    using (var serviceDiscoveryClient2
                        = new CentralizedDiscovery.Client.CentralizedDiscovery(serviceDiscoveryHost.MasterUri, bluepathListener2))
                    {
                        var connectionManager = new Bluepath.Services.ConnectionManager(
                            remoteService: null,
                            listener: bluepathListener1,
                            serviceDiscovery: serviceDiscoveryClient1);
                        var scheduler = new ThreadNumberScheduler(connectionManager);
                        TestHelpers.RepeatUntilTrue(() => connectionManager.RemoteServices.Count() == 1, times: 10);

                        connectionManager.RemoteServices.Count().ShouldBe(1);

                        // TODO: Review this test
                        var testMethod = new Func<int, int, int>(
                        (a, b) =>
                        {
                            Thread.Sleep(100);
                            return a + b;
                        });

                        var thread = DistributedThread.Create(
                            testMethod,
                            connectionManager,
                            scheduler,
                            DistributedThread.ExecutorSelectionMode.RemoteOnly
                            );
                        thread.Start(4, 5);

                        var performanceStatistics = serviceDiscoveryClient1.GetPerformanceStatistics();

                        performanceStatistics.Count.ShouldBe(2);
                        performanceStatistics.ElementAt(0).Key.Address.ShouldNotBeSameAs(performanceStatistics.ElementAt(1).Key.Address);
                        performanceStatistics.ElementAt(0).Value.NumberOfTasks[ExecutorState.NotStarted].ShouldBe(0);
                        performanceStatistics.ElementAt(0).Value.NumberOfTasks[ExecutorState.Running].ShouldBeLessThanOrEqualTo(1);
                        performanceStatistics.ElementAt(1).Value.NumberOfTasks[ExecutorState.Running].ShouldBeLessThanOrEqualTo(1);

                        if (performanceStatistics.ElementAt(0).Value.NumberOfTasks[ExecutorState.Running] > 0
                            && performanceStatistics.ElementAt(1).Value.NumberOfTasks[ExecutorState.Running] > 0)
                        {
                            Assert.Fail("One task was scheduled but two are reported to be running.");
                        }

                        (performanceStatistics.ElementAt(0).Value.NumberOfTasks[ExecutorState.Running]
                            + performanceStatistics.ElementAt(1).Value.NumberOfTasks[ExecutorState.Running]).ShouldBe(1);
                        performanceStatistics.ElementAt(0).Value.NumberOfTasks[ExecutorState.Finished].ShouldBe(0);
                        performanceStatistics.ElementAt(0).Value.NumberOfTasks[ExecutorState.Faulted].ShouldBe(0);

                        thread.Join();
                    }
                }
            }
            finally
            {
                serviceDiscoveryHost.Stop();
                bluepathListener1.Stop();
                bluepathListener2.Stop();
            }
        }
        public void ConnectionManagerFetchesServicesFromRemoteServiceDiscovery()
        {
            var serviceDiscoveryHost = new CentralizedDiscovery.CentralizedDiscoveryListener("localhost", 20000);
            var bluepathListener1 = new Bluepath.Services.BluepathListener("localhost", 20001);
            var bluepathListener2 = new Bluepath.Services.BluepathListener("localhost", 20002);
            try
            {
                using (var serviceDiscoveryClient1
                    = new CentralizedDiscovery.Client.CentralizedDiscovery(serviceDiscoveryHost.MasterUri, bluepathListener1))
                {
                    using (var serviceDiscoveryClient2
                        = new CentralizedDiscovery.Client.CentralizedDiscovery(serviceDiscoveryHost.MasterUri, bluepathListener2))
                    {
                        var connectionManager = new Bluepath.Services.ConnectionManager(remoteService: null,
                            listener: bluepathListener1,
                            serviceDiscovery: serviceDiscoveryClient1);
                        TestHelpers.RepeatUntilTrue(() => connectionManager.RemoteServices.Count() == 1, times: 10);

                        connectionManager.RemoteServices.Count().ShouldBe(1);
                    }
                }
            }
            finally
            {
                serviceDiscoveryHost.Stop();
                bluepathListener1.Stop();
                bluepathListener2.Stop();
            }
        }
 private static void PrepareDLINQEnviroment(out BluepathListener listener1, out BluepathListener listener2, out ConnectionManager connectionManager)
 {
     listener1 = new BluepathListener("127.0.0.1", StartPort);
     listener2 = new BluepathListener("127.0.0.1", StartPort + 1);
     var availableServices = new Dictionary<ServiceUri, PerformanceStatistics>()
         {
             {listener1.CallbackUri, new PerformanceStatistics()
             {
                 NumberOfTasks = new Dictionary<Bluepath.Executor.ExecutorState, int>()
                 {
                     {Bluepath.Executor.ExecutorState.Faulted, 0},
                     {Bluepath.Executor.ExecutorState.Finished, 0},
                     {Bluepath.Executor.ExecutorState.NotStarted, 0},
                     {Bluepath.Executor.ExecutorState.Running, 0},
                 }
             }},
             {listener2.CallbackUri, new PerformanceStatistics()
             {
                 NumberOfTasks = new Dictionary<Bluepath.Executor.ExecutorState, int>()
                 {
                     {Bluepath.Executor.ExecutorState.Faulted, 0},
                     {Bluepath.Executor.ExecutorState.Finished, 0},
                     {Bluepath.Executor.ExecutorState.NotStarted, 0},
                     {Bluepath.Executor.ExecutorState.Running, 0},
                 }
             }},
         };
     connectionManager = new ConnectionManager(availableServices, listener1);
 }
Beispiel #6
0
        public static BluepathListener InitializeDefaultListener(string ip, int? port = null)
        {
            if (BluepathListener.defaultListener != null)
            {
                throw new Exception("There is already one default listener defined. Stop the current one before initializing new instance.");
            }

            var listener = new BluepathListener(ip, port);
            BluepathListener.Default = listener;
            return listener;
        }