Example #1
0
        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 void Should_stop_after_applications_finished()
        {
            var application = new VostokMultiHostApplicationSettings(
                new DelayApplication(),
                ("test", "test"),
                SetupMultiHostApplication);

            var vostokMultiHost = new VostokMultiHost(new VostokMultiHostSettings(SetupMultiHost), application);

            Action run = () => vostokMultiHost.RunAsync().GetAwaiter().GetResult();

            run.ShouldPassIn(1.Seconds());

            vostokMultiHost.MultiHostState.Should().Be(VostokMultiHostState.Exited);
        }
        public void Should_return_CrashedDuringEnvironmentSetup()
        {
            vostokMultiHost = new VostokMultiHost(
                new VostokMultiHostSettings(
                    builder =>
            {
                builder.SetupApplicationIdentity(identityBuilder => throw new Exception("Failed!"));
                builder.SetupLog(logBuilder => logBuilder.SetupConsoleLog());
            })
                );

            Action error = () => vostokMultiHost.RunAsync().GetAwaiter().GetResult();

            error.Should().Throw <Exception>().WithMessage("Failed!");

            vostokMultiHost.MultiHostState.Should().Be(VostokMultiHostState.CrashedDuringEnvironmentSetup);
        }
        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);
        }
Example #5
0
        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();
        }