public async Task Should_stop_all_applications() { vostokMultiHost = new VostokMultiHost(new VostokMultiHostSettings(SetupMultiHost)); var applications = new List <VostokMultiHostApplicationSettings>(); for (var i = 0; i < 10; i++) { applications.Add( new VostokMultiHostApplicationSettings( new NeverEndingApplication(), ("test", i.ToString()), SetupMultiHostApplication)); } foreach (var app in applications) { vostokMultiHost.AddApplication(app); } await vostokMultiHost.StartAsync(); await Task.Delay(1000); await vostokMultiHost.StopAsync(); foreach (var app in applications) { // ReSharper disable once PossibleNullReferenceException vostokMultiHost.GetApplication(app.Identifier).ApplicationState.IsTerminal().Should().BeTrue(); } }
public void Should_override_default_host_settings() { void Assertion(IVostokHostingEnvironment environment) { environment.ApplicationIdentity.Project.Should().Be("testProject"); environment.ApplicationIdentity.Environment.Should().Be("testEnvironment"); environment.ApplicationIdentity.Application.Should().Be("testApplication"); environment.ApplicationIdentity.Instance.Should().Be("testInstance"); } var vostokMultiHost = new VostokMultiHost( new VostokMultiHostSettings( builder => { builder.SetupApplicationIdentity( identityBuilder => { identityBuilder.SetProject("testProject").SetEnvironment("testEnvironment").SetApplication("default"); }); builder.SetupLog(logBuilder => logBuilder.SetupConsoleLog()); })); var application = new VostokMultiHostApplicationSettings( new TesterApplication(Assertion), ("testApplication", "testInstance"), SetupMultiHostApplication); vostokMultiHost.AddApplication(application); Action run = () => vostokMultiHost.RunAsync().GetAwaiter().GetResult().EnsureSuccess(); run.Should().NotThrow(); }
public async Task Should_allow_to_subscribe_to_state_changes_prior_to_start() { vostokMultiHost = new VostokMultiHost(new VostokMultiHostSettings(SetupMultiHost)); var workerIdentifier = ("nevermind", "delay"); var workerApplication = new VostokMultiHostApplicationSettings( new DelayApplication(), workerIdentifier, SetupMultiHostApplication); var stateChangesCount = 0; VostokApplicationState?lastState = null; var observable = vostokMultiHost.AddApplication(workerApplication).OnApplicationStateChanged; using (observable.Subscribe(state => stateChangesCount++)) using (observable.Subscribe(state => lastState = state)) await vostokMultiHost.RunAsync(); stateChangesCount.Should().Be(7); lastState.Should().Be(VostokApplicationState.Exited); }
public void Should_interpret_MultiHost_builder_settings_as_default_in_applications() { void Assertion(IVostokHostingEnvironment environment) => environment.HostExtensions.Get <TestHostExtension>().A.Should().Be(10); var vostokMultiHost = new VostokMultiHost( new VostokMultiHostSettings( builder => { builder.SetupLog(logBuilder => logBuilder.SetupConsoleLog()); builder.SetupHostExtensions(extensionsBuilder => extensionsBuilder.Add(new TestHostExtension(10))); })); var application = new VostokMultiHostApplicationSettings( new TesterApplication(Assertion), ("test", "test"), SetupMultiHostApplication); vostokMultiHost.AddApplication(application); Action run = () => vostokMultiHost.RunAsync().GetAwaiter().GetResult().EnsureSuccess(); run.Should().NotThrow(); }
public async Task Should_not_stop_if_contains_not_finished_application() { var application = new VostokMultiHostApplicationSettings( new DelayApplication(), ("test", "test"), SetupMultiHostApplication); var newApplication = new VostokMultiHostApplicationSettings( new NeverEndingApplication(), ("nevermind", "delay"), SetupMultiHostApplication); var vostokMultiHost = new VostokMultiHost(new VostokMultiHostSettings(SetupMultiHost), application); await vostokMultiHost.StartAsync(); vostokMultiHost.AddApplication(newApplication); await Task.Delay(500); vostokMultiHost.MultiHostState.Should().Be(VostokMultiHostState.Running); await vostokMultiHost.StopAsync(); }