コード例 #1
0
        public async Task get_latest_get_single_information_for_specified_liveness()
        {
            var notifier = new MemoryNotifier();

            var tokenSource = new CancellationTokenSource();

            var livenessConfiguration = new LivenessConfigurationBuilder()
                                        .With("http://someserver-3/health", "Liveness")
                                        .Build();

            var context = new LivenessContextBuilder()
                          .WithLiveness(livenessConfiguration)
                          .WithRandomDatabaseName()
                          .Build();

            var runnerBuilder = new LivenessRunnerBuilder()
                                .WithHttpStatusCode(HttpStatusCode.OK)
                                .WithHealthyMessageContent()
                                .WithLivenessDb(context)
                                .WithNotifier(notifier);

            var runner = runnerBuilder.Build();

            await runner.Run(tokenSource.Token);

            await runner.Run(tokenSource.Token);

            var execution = context.LivenessExecutions
                            .ToList();

            execution.Count().Should().Be(1);

            execution.Where(h => h.LivenessName == "Liveness")
            .Single()?.IsHealthy.Should().BeTrue();
        }
コード例 #2
0
        public async Task save_execution_if_is_new()
        {
            var notifier = new MemoryNotifier();

            var tokenSource = new CancellationTokenSource();

            var livenessConfiguration = new LivenessConfigurationBuilder()
                                        .With("http://someserver-2/health", "Liveness")
                                        .Build();

            var context = new LivenessContextBuilder()
                          .WithLiveness(livenessConfiguration)
                          .WithRandomDatabaseName()
                          .Build();

            var runnerBuilder = new LivenessRunnerBuilder()
                                .WithHttpStatusCode(HttpStatusCode.ServiceUnavailable)
                                .WithDegradedMessageContent()
                                .WithLivenessDb(context)
                                .WithNotifier(notifier);

            var runner = runnerBuilder.Build();

            await runner.Run(tokenSource.Token);

            var execution = context.LivenessExecutions
                            .ToList();

            execution.Count().Should().Be(1);

            execution.Where(h => h.LivenessName == "Liveness")
            .Single()?.IsHealthy.Should().BeFalse();
        }
コード例 #3
0
        public async Task notify_failures_if_liveness_is_down()
        {
            var notifier = new MemoryNotifier();

            var tokenSource = new CancellationTokenSource();

            var livenessConfiguration = new LivenessConfigurationBuilder()
                                        .With("http://someserver-1/health", "Failing Liveness")
                                        .Build();

            var context = new LivenessContextBuilder()
                          .WithLiveness(livenessConfiguration)
                          .WithRandomDatabaseName()
                          .Build();

            var runnerBuilder = new LivenessRunnerBuilder()
                                .WithHttpStatusCode(HttpStatusCode.ServiceUnavailable)
                                .WithDegradedMessageContent()
                                .WithLivenessDb(context)
                                .WithMinimumElapsedSecondsOnNotifications(0)
                                .WithNotifier(notifier);

            var runner = runnerBuilder.Build();

            await runner.Run(tokenSource.Token);

            notifier.ContainsFailureNotificationFor(livenessConfiguration.LivenessName)
            .Should().BeTrue();
        }
コード例 #4
0
        public async Task get_all_livenes_configuration()
        {
            var notifier     = new MemoryNotifier();
            var livenessName = "livenessName";
            var tokenSource  = new CancellationTokenSource();


            var livenessConfiguration = new LivenessConfigurationBuilder()
                                        .With("http://someserver-6/health", livenessName)
                                        .Build();

            var context = new LivenessContextBuilder()
                          .WithLiveness(livenessConfiguration)
                          .WithRandomDatabaseName()
                          .Build();

            var runnerBuilder = new LivenessRunnerBuilder()
                                .WithHttpStatusCode(HttpStatusCode.OK)
                                .WithHealthyMessageContent()
                                .WithLivenessDb(context)
                                .WithNotifier(notifier);

            var runner = runnerBuilder.Build();

            await runner.Run(tokenSource.Token);

            var liveness = await runner.GetConfiguredLiveness(CancellationToken.None);

            liveness.Count.Should().Be(1);

            liveness.Single()
            .LivenessName.Should().Be(livenessName);
        }
コード例 #5
0
        public async Task save_execution_history_update_onStateFrom_if_execution_exist_and_the_status_is_not_the_same()
        {
            var notifier = new MemoryNotifier();

            var tokenSource = new CancellationTokenSource();

            var livenessConfiguration = new LivenessConfigurationBuilder()
                                        .With("http://someserver-5/health", "Liveness")
                                        .Build();

            var context = new LivenessContextBuilder()
                          .WithLiveness(livenessConfiguration)
                          .WithRandomDatabaseName()
                          .Build();

            var runnerBuilderOk = new LivenessRunnerBuilder()
                                  .WithHttpStatusCode(HttpStatusCode.OK)
                                  .WithHealthyMessageContent()
                                  .WithLivenessDb(context)
                                  .WithNotifier(notifier);

            var runnerBuilderUnavailable = new LivenessRunnerBuilder()
                                           .WithHttpStatusCode(HttpStatusCode.ServiceUnavailable)
                                           .WithDegradedMessageContent()
                                           .WithLivenessDb(context)
                                           .WithNotifier(notifier);

            var runnerOk = runnerBuilderOk.Build();

            await runnerOk.Run(tokenSource.Token);

            var execution1 = context.LivenessExecutions
                             .Single();

            var status1     = execution1.Status;
            var onStateFrom = execution1.OnStateFrom;

            var runnerServiceUnavailable = runnerBuilderUnavailable.Build();

            await runnerServiceUnavailable.Run(tokenSource.Token);

            var execution2 = context.LivenessExecutions
                             .Single();

            status1.Should().NotBe(execution2.Status);
            onStateFrom.Should().NotBe(execution2.OnStateFrom);
        }
コード例 #6
0
        public async Task save_execution_history_update_lastExecuted_if_execution_exist_and_the_status_is_the_same()
        {
            var notifier = new MemoryNotifier();

            var tokenSource = new CancellationTokenSource();

            var livenessConfiguration = new LivenessConfigurationBuilder()
                                        .With("http://someserver-4/health", "Liveness")
                                        .Build();

            var context = new LivenessContextBuilder()
                          .WithLiveness(livenessConfiguration)
                          .WithRandomDatabaseName()
                          .Build();

            var runnerBuilder = new LivenessRunnerBuilder()
                                .WithHttpStatusCode(HttpStatusCode.OK)
                                .WithHealthyMessageContent()
                                .WithLivenessDb(context)
                                .WithNotifier(notifier);

            var runner = runnerBuilder.Build();

            await runner.Run(tokenSource.Token);

            var execution1 = context.LivenessExecutions
                             .Single();

            await runner.Run(tokenSource.Token);

            var execution2 = context.LivenessExecutions
                             .Single();

            execution1.Id.Should().Be(execution2.Id);
            execution1.LivenessName.Should().Be(execution2.LivenessName);
            execution1.LivenessUri.Should().Be(execution2.LivenessUri);
            execution1.OnStateFrom.Should().Be(execution2.OnStateFrom);
            execution1.Status.Should().Be(execution2.Status);
        }