Example #1
0
        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 Should_run_sequentially()
        {
            var currentIndex = 0;

            int GetIndex() => currentIndex;

            void SetIndex(int newIndex) => currentIndex = newIndex;

            await SetupAndStartMultiHost();

            var appList = new List <VostokMultiHostApplicationSettings>();

            for (var i = 1; i < 11; i++)
            {
                appList.Add(
                    new VostokMultiHostApplicationSettings(
                        new SequentialCheckerApplication(GetIndex, SetIndex, i),
                        ("test", i.ToString()),
                        SetupMultiHostApplication)
                    );
            }

            await vostokMultiHost.RunSequentiallyAsync(appList);
        }