Пример #1
0
        private static void WaitUntilServiceIsUp(SqlDServiceModel service)
        {
            var wait = new ManualResetEvent(false);

            using (var endPointMonitor = new EndPointMonitor(service.ToEndPoint()))
            {
                endPointMonitor.OnUp += (args) =>
                {
                    Log.Out.Info($"Child process {service.Host}:{service.Port}/{service.Database} is up!");
                    wait.Set();
                };

                try
                {
                    Log.Out.Info($"Waiting {Constants.END_POINT_UP_WAIT_FOR_TIMEOUT.TotalSeconds}s for child process {service.Host}:{service.Port}/{service.Database}");
                    wait.WaitOne(Constants.END_POINT_UP_WAIT_FOR_TIMEOUT);

                    var client = SqlDStart.NewClient().ConnectedTo(service.ToEndPoint());
                    if (!client.Ping(service.ToEndPoint()))
                    {
                        throw new ProcessStartFailedException($"Failed to launch child process {service.Host}:{service.Port}/{service.Database}");
                    }
                }
                catch (Exception err)
                {
                    Log.Out.Error($"Failed to start {service.Host}:{service.Port}/{service.Database} as a separate process");
                    Log.Out.Error(err.ToString());
                }
            }
        }
Пример #2
0
        public void ShouldBeAbleToStartASqlDConfiguration()
        {
            var sqlD = GetType().Assembly.SqlDGo(@"./Configuration/appsettings.tests.json");

            Assert.NotNull(sqlD);

            var registry = sqlD.Services.First(x => x.Name.Equals("localhost"));

            Assert.Contains("registry", registry.Tags);

            EndPointMonitor.WaitUntil(registry.ToEndPoint(), EndPointIs.Up);

            var master = sqlD.Services.First(x => x.Name.Equals("localhost"));

            Assert.Contains("master", master.Tags);

            EndPointMonitor.WaitUntil(master.ToEndPoint(), EndPointIs.Up);
        }
Пример #3
0
            public static void TearDown()
            {
                lock (Synchronise)
                {
                    RegistryClient.Dispose();
                    EndPointMonitor.WaitUntil(RegistryClient.EndPoint, EndPointIs.Down);

                    AlphaClient.Dispose();
                    EndPointMonitor.WaitUntil(AlphaClient.EndPoint, EndPointIs.Down);

                    BetaClient.Dispose();
                    EndPointMonitor.WaitUntil(BetaClient.EndPoint, EndPointIs.Down);

                    Free1Client.Dispose();
                    EndPointMonitor.WaitUntil(Free1Client.EndPoint, EndPointIs.Down);

                    Free2Client.Dispose();
                    EndPointMonitor.WaitUntil(Free2Client.EndPoint, EndPointIs.Down);
                }
            }
Пример #4
0
            public static void SetUp()
            {
                lock (Synchronise)
                {
                    RegistryClient = SqlDStart.NewClient().ConnectedTo(EndPoints.Registry);
                    EndPointMonitor.WaitUntil(RegistryClient.EndPoint, EndPointIs.Up);

                    AlphaClient = SqlDStart.NewClient().ConnectedTo(EndPoints.Alpha);
                    EndPointMonitor.WaitUntil(AlphaClient.EndPoint, EndPointIs.Up);

                    BetaClient = SqlDStart.NewClient().ConnectedTo(EndPoints.Beta);
                    EndPointMonitor.WaitUntil(BetaClient.EndPoint, EndPointIs.Up);

                    Free1Client = SqlDStart.NewClient().ConnectedTo(EndPoints.Free1);
                    EndPointMonitor.WaitUntil(Free1Client.EndPoint, EndPointIs.Up);

                    Free2Client = SqlDStart.NewClient().ConnectedTo(EndPoints.Free2);
                    EndPointMonitor.WaitUntil(Free2Client.EndPoint, EndPointIs.Up);
                }
            }
Пример #5
0
            public static void TearDown()
            {
                lock (Synchronise)
                {
                    RegistryListener.Dispose();
                    EndPointMonitor.WaitUntil(RegistryListener.EndPoint, EndPointIs.Down);

                    AlphaListener.Dispose();
                    EndPointMonitor.WaitUntil(AlphaListener.EndPoint, EndPointIs.Down);

                    BetaListener.Dispose();
                    EndPointMonitor.WaitUntil(BetaListener.EndPoint, EndPointIs.Down);

                    Free1Listener.Dispose();
                    EndPointMonitor.WaitUntil(Free1Listener.EndPoint, EndPointIs.Down);

                    Free2Listener.Dispose();
                    EndPointMonitor.WaitUntil(Free2Listener.EndPoint, EndPointIs.Down);
                }
            }
Пример #6
0
            public static void SetUp()
            {
                lock (Synchronise)
                {
                    RegistryListener = SqlDStart.NewListener().Hosting(typeof(SqlDStart).Assembly, SqlDStart.NewId(), SqlDStart.NewId(), SqlDPragmaModel.Default, EndPoints.Registry);
                    EndPointMonitor.WaitUntil(RegistryListener.EndPoint, EndPointIs.Up);

                    AlphaListener = SqlDStart.NewListener().Hosting(typeof(SqlDStart).Assembly, SqlDStart.NewId(), SqlDStart.NewId(), SqlDPragmaModel.Default, EndPoints.Alpha);
                    EndPointMonitor.WaitUntil(AlphaListener.EndPoint, EndPointIs.Up);

                    BetaListener = SqlDStart.NewListener().Hosting(typeof(SqlDStart).Assembly, SqlDStart.NewId(), SqlDStart.NewId(), SqlDPragmaModel.Default, EndPoints.Beta);
                    EndPointMonitor.WaitUntil(BetaListener.EndPoint, EndPointIs.Up);

                    Free1Listener = SqlDStart.NewListener().Hosting(typeof(SqlDStart).Assembly, SqlDStart.NewId(), SqlDStart.NewId(), SqlDPragmaModel.Default, EndPoints.Free1, EndPoints.Free2);
                    EndPointMonitor.WaitUntil(Free1Listener.EndPoint, EndPointIs.Up);

                    Free2Listener = SqlDStart.NewListener().Hosting(typeof(SqlDStart).Assembly, SqlDStart.NewId(), SqlDStart.NewId(), SqlDPragmaModel.Default, EndPoints.Free2);
                    EndPointMonitor.WaitUntil(Free2Listener.EndPoint, EndPointIs.Up);
                }
            }
Пример #7
0
        public void ShouldBeAbleToDetectListenerUpDownEvents()
        {
            EndPointMonitor freeEndPointMonitor2 = null;

            try
            {
                var free2IsUp = false;

                freeEndPointMonitor2 = new EndPointMonitor(WellKnown.EndPoints.Free2);

                freeEndPointMonitor2.OnUp   += args => free2IsUp = true;
                freeEndPointMonitor2.OnDown += args => free2IsUp = false;

                freeEndPointMonitor2.WaitUntil(Constants.END_POINT_UP_WAIT_FOR_TIMEOUT, EndPointIs.Up);
                freeEndPointMonitor2.DoEvents();

                Assert.That(free2IsUp, Is.True);
            }
            finally
            {
                freeEndPointMonitor2?.Dispose();
            }
        }
Пример #8
0
        public void ShouldBeAbleToLaunchServiceInASeparateProcess()
        {
            R.GetOrAdd(WellKnown.Listeners.AlphaListener.EndPoint);

            var service = new SqlDServiceModel()
            {
                Name     = "separate-process",
                Database = SqlDStart.NewId(),
                Port     = WellKnown.EndPoints.Free2.Port - 100,
                Host     = WellKnown.EndPoints.Free2.Host,
                Pragma   = SqlDPragmaModel.Default
            };

            using (var process = SqlD.Process.Service.Start(typeof(StartTests).Assembly, service))
            {
                var wait = new ManualResetEvent(false);
                using (var endPointMonitor = new EndPointMonitor(service.ToEndPoint()))
                {
                    endPointMonitor.OnUp += (args) => wait.Set();
                    wait.WaitOne(TimeSpan.FromSeconds(30));
                }
                process.Kill();
            }
        }
Пример #9
0
        private static void SqlD(SqlDConfiguration cfg, Assembly startAssembly)
        {
            if (cfg == null)
            {
                Log.Out.Warn($"Configuration is null, are you sure this is what you intended?");
                return;
            }

            if (!cfg.Enabled)
            {
                return;
            }

            foreach (var registry in cfg.Registries)
            {
                Registry.GetOrAdd(registry.ToEndPoint());
            }

            var registryEndPoints = cfg.Registries.Select(x => x.ToEndPoint()).ToList();
            var serviceEndPointsThatAreRegistries    = cfg.Services.Where(x => registryEndPoints.Contains(x.ToEndPoint())).ToList();
            var serviceEndPointsThatAreNotRegistries = cfg.Services.Where(x => !registryEndPoints.Contains(x.ToEndPoint())).ToList();

            foreach (var service in serviceEndPointsThatAreRegistries)
            {
                try
                {
                    var client = NewClient(withRetries: false).ConnectedTo(service.ToEndPoint());
                    if (client.Ping())
                    {
                        Log.Out.Warn($"Skipping the start of registry service '{service.ToEndPoint()}', already up!");
                        continue;
                    }

                    if (cfg.ProcessModel.Distributed)
                    {
                        ChildProcesses.Add(Process.Service.Start(startAssembly, service));
                        EndPointMonitor.WaitUntil(service.ToEndPoint(), EndPointIs.Up);
                    }
                    else
                    {
                        var listener = NewListener().Hosting(startAssembly, service.Name, service.Database, service.Pragma, service.ToEndPoint(), service.ForwardingTo.Select(x => x.ToEndPoint()).ToArray());
                        service.AddListener(listener);
                        EndPointMonitor.WaitUntil(service.ToEndPoint(), EndPointIs.Up);
                        Registry.Register(listener, string.Join(",", service.Tags));
                    }
                }
                catch (Exception err)
                {
                    Console.WriteLine(err.ToString());
                    throw;
                }
            }

            foreach (var service in serviceEndPointsThatAreNotRegistries)
            {
                try
                {
                    var client = NewClient(withRetries: false).ConnectedTo(service.ToEndPoint());
                    if (client.Ping())
                    {
                        Log.Out.Warn($"Skipping the start of sql service '{service.ToEndPoint()}', already up!");
                        continue;
                    }

                    if (cfg.ProcessModel.Distributed)
                    {
                        ChildProcesses.Add(Process.Service.Start(startAssembly, service));
                    }
                    else
                    {
                        var listener = NewListener().Hosting(startAssembly, service.Name, service.Database, service.Pragma, service.ToEndPoint(), service.ForwardingTo.Select(x => x.ToEndPoint()).ToArray());
                        service.AddListener(listener);
                        Registry.Register(listener, string.Join(",", service.Tags));
                    }
                }
                catch (Exception err)
                {
                    Console.WriteLine(err.ToString());
                    throw;
                }
            }
        }