예제 #1
0
        public async Task Start_With_2_MicroServices()
        {
            var host = TestsHelper.CreateTestHostWithServer();

            TestsHelper.CleanupFolders(host);

            var settings = host.Services.GetRequiredService <Palace.Configuration.PalaceSettings>();

            var starter = host.Services.GetRequiredService <Palace.Services.IStarter>();

            await starter.Start();

            starter.InstanciedServiceCount.Should().Be(0);

            await starter.CheckHealth();

            starter.InstanciedServiceCount.Should().Be(0);

            var msm = host.Services.GetRequiredService <Palace.Services.MicroServicesCollectionManager>();
            await msm.SynchronizeConfiguration(true);

            await msm.AddOrUpdateService(new Models.MicroServiceSettings
            {
                PackageFileName = "DemoSvc.zip",
                ServiceName     = "DemoSvc",
                MainAssembly    = "DemoSvc.dll",
                Arguments       = "--port 12346",
                AdminServiceUrl = "http://localhost:12346",
                PalaceApiKey    = "test"
            });

            await msm.AddOrUpdateService(new Models.MicroServiceSettings
            {
                PackageFileName = "DemoSvc2.zip",
                ServiceName     = "DemoSvc2",
                MainAssembly    = "DemoSvc.dll",
                Arguments       = "--port 12347",
                AdminServiceUrl = "http://localhost:12347",
                PalaceApiKey    = "test"
            });

            await starter.CheckUpdate();

            starter.InstanciedServiceCount.Should().Be(2);
            starter.RunningServiceCount.Should().Be(0);

            TestsHelper.PublishDemoProject(host);
            TestsHelper.PublishDemoProject(host, "DemoSvc2.zip");

            await starter.GetApplyAction();

            await starter.CheckUpdate();

            starter.InstanciedServiceCount.Should().Be(2);
            starter.RunningServiceCount.Should().Be(2);

            await starter.Stop();

            starter.InstanciedServiceCount.Should().Be(0);
        }
예제 #2
0
        public async Task Start_And_Remove_Service()
        {
            var host = TestsHelper.CreateTestHostWithServer(config => config.HostName = "Host1");

            TestsHelper.CleanupFolders(host);
            TestsHelper.PublishDemoProject(host);
            var starter = host.Services.GetRequiredService <Palace.Services.IStarter>();

            await starter.Start();

            await starter.CheckHealth();

            starter.InstanciedServiceCount.Should().Be(1);
            starter.RunningServiceCount.Should().Be(1);

            var collection = host.Services.GetRequiredService <Palace.Services.MicroServicesCollectionManager>();
            var list       = collection.GetList();

            list.First().MarkToDelete = true;

            await starter.CheckRemove();

            list = collection.GetList();
            list.Count().Should().Be(0);

            await starter.Stop();

            starter.InstanciedServiceCount.Should().Be(0);
        }
예제 #3
0
        public async Task Start_With_2_Hosts()
        {
            var host1 = TestsHelper.CreateTestHostWithServer(config => config.HostName = "Host1");

            TestsHelper.CleanupFolders(host1);
            TestsHelper.PublishDemoProject(host1);
            var starter1 = host1.Services.GetRequiredService <Palace.Services.IStarter>();

            var host2 = TestsHelper.CreateTestHostWithServer(config => config.HostName = "Host2");

            TestsHelper.CleanupFolders(host2);
            TestsHelper.PublishDemoProject(host2);
            var starter2 = host1.Services.GetRequiredService <Palace.Services.IStarter>();

            await starter1.Start();

            await starter2.Start();

            await starter1.CheckHealth();

            await starter2.CheckHealth();

            starter1.InstanciedServiceCount.Should().Be(1);
            starter1.RunningServiceCount.Should().Be(1);
            starter2.InstanciedServiceCount.Should().Be(1);
            starter2.RunningServiceCount.Should().Be(1);

            await starter1.Stop();

            await starter2.Stop();

            starter1.InstanciedServiceCount.Should().Be(0);
            starter2.InstanciedServiceCount.Should().Be(0);
        }
예제 #4
0
        public async Task Start_With_Crashed_MicroService()
        {
            var host = TestsHelper.CreateTestHostWithServer();

            TestsHelper.CleanupFolders(host);

            var settings = host.Services.GetRequiredService <Palace.Configuration.PalaceSettings>();

            var starter        = host.Services.GetRequiredService <Palace.Services.IStarter>();
            var palaceSettings = host.Services.GetRequiredService <Palace.Configuration.PalaceSettings>();

            var msm = host.Services.GetRequiredService <Palace.Services.MicroServicesCollectionManager>();
            await msm.SynchronizeConfiguration(true);

            await msm.AddOrUpdateService(new Models.MicroServiceSettings
            {
                PackageFileName = "DemoSvc.zip",
                ServiceName     = "DemoSvc4",
                MainAssembly    = "DemoSvc.dll",
                Arguments       = "--port 12349",
                AdminServiceUrl = "http://localhost:12349",
                PalaceApiKey    = "test"
            });

            TestsHelper.PublishDemoProject(host);

            await starter.Start();

            await starter.CheckHealth();

            var svc = starter.GetMicroServiceInfo("DemoSvc4");

            svc.Should().NotBeNull();
            var version = svc.Version;

            starter.InstanciedServiceCount.Should().Be(1);
            starter.RunningServiceCount.Should().Be(1);

            // Mise à jour du service
            TestsHelper.UpdateVersionDemoProject(host);
            TestsHelper.PublishDemoProject(host);

            // Temps de mise à jour du package LastWriteTime
            await Task.Delay((palaceSettings.ScanIntervalInSeconds + 2) * 1000);

            await starter.CheckHealth();

            await starter.CheckUpdate();

            await starter.CheckHealth();

            svc = starter.GetMicroServiceInfo("DemoSvc4");
            var newVersion = svc.Version;

            version.Should().NotBe(newVersion);

            await starter.Stop();

            starter.InstanciedServiceCount.Should().Be(0);
        }
예제 #5
0
        public async Task Start_With_Server_And_AvailableService()
        {
            var host = TestsHelper.CreateTestHostWithServer();

            TestsHelper.CleanupFolders(host);
            TestsHelper.PublishDemoProject(host);
            var starter = host.Services.GetRequiredService <Palace.Services.IStarter>();

            await starter.Start();

            starter.InstanciedServiceCount.Should().Be(1);

            await starter.Stop();

            starter.InstanciedServiceCount.Should().Be(0);
        }