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 async Task Should_not_stop_if_didnt_start_any_application() { var vostokMultiHost = new VostokMultiHost(new VostokMultiHostSettings(SetupMultiHost)); await vostokMultiHost.StartAsync(); await Task.Delay(500); vostokMultiHost.MultiHostState.Should().Be(VostokMultiHostState.Running); Action stop = () => vostokMultiHost.StopAsync().GetAwaiter().GetResult(); stop.ShouldPassIn(1.Seconds()); }
public async Task Should_be_able_to_override_common_components() { IHerculesSink extractedSink = null; void Assert(IVostokHostingEnvironment environment) { environment.HerculesSink.Should().BeSameAs(extractedSink); } void Extract(IVostokHostingEnvironment environment) { extractedSink = environment.HerculesSink; } var initialSink = new DevNullHerculesSink(); var vostokMultiHost = new VostokMultiHost( new VostokMultiHostSettings( builder => { builder.SetupApplicationIdentity(identityBuilder => identityBuilder.SetProject("testProject").SetEnvironment("testEnvironment")); builder.SetupHerculesSink(sinkBuilder => sinkBuilder.UseInstance(initialSink)); builder.SetupLog(logBuilder => logBuilder.SetupConsoleLog()); })); var extractIdentifier = ("testApplication", "testInstance"); var extractApplication = new VostokMultiHostApplicationSettings( new TesterApplication(Extract), extractIdentifier, SetupMultiHostApplication); var assertIdentifier = ("testApplication", "testInstance2"); var assertApplication = new VostokMultiHostApplicationSettings( new TesterApplication(Assert), assertIdentifier, SetupMultiHostApplication); await vostokMultiHost.StartAsync(); await vostokMultiHost.RunSequentiallyAsync(extractApplication, assertApplication); var results = await vostokMultiHost.StopAsync(); // ReSharper disable once PossibleNullReferenceException results.ApplicationRunResults[assertIdentifier].EnsureSuccess(); extractedSink.Should().BeSameAs(initialSink); }
public async Task Start_should_wait_until_given_state_occurs(VostokApplicationState stateToAwait) { var identifier = ("test", "test"); var workerApplication = new VostokMultiHostApplicationSettings(new NeverEndingApplication(), identifier, SetupMultiHostApplication); vostokMultiHost = new VostokMultiHost(new VostokMultiHostSettings(SetupMultiHost), workerApplication); await vostokMultiHost.StartAsync(); await vostokMultiHost.GetApplication(identifier).StartAsync(stateToAwait); vostokMultiHost.GetApplication(identifier).ApplicationState.Should().Match <VostokApplicationState>(state => state >= stateToAwait); await vostokMultiHost.StopApplicationAsync(identifier); vostokMultiHost.GetApplication(identifier).ApplicationState.IsTerminal().Should().BeTrue(); await vostokMultiHost.StopAsync(); }
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(); }
private async Task SetupAndStartMultiHost() { vostokMultiHost = new VostokMultiHost(new VostokMultiHostSettings(SetupMultiHost)); await vostokMultiHost.StartAsync(); }