@Test void startShouldLogWhenMultipleHealthChecks() { ListAppender<ILoggingEvent> loggingEvents = getListAppenderForClass(PeriodicalHealthChecks.class); TestingHealthCheck unhealthy = () -> Mono.just(Result.unhealthy(TestingHealthCheck.COMPONENT_NAME, "cause")); TestingHealthCheck degraded = () -> Mono.just(Result.degraded(TestingHealthCheck.COMPONENT_NAME, "cause")); TestingHealthCheck healthy = () -> Mono.just(Result.healthy(TestingHealthCheck.COMPONENT_NAME)); testee = new PeriodicalHealthChecks(ImmutableSet.of(unhealthy, degraded, healthy), scheduler, new PeriodicalHealthChecksConfiguration(PERIOD)); testee.start(); scheduler.advanceTimeBy(PERIOD); SoftAssertions.assertSoftly(softly -> { softly.assertThat(loggingEvents.list).hasSize(2); softly.assertThat(loggingEvents.list.stream() .map(event -> new Tuple(event.getLevel(), event.getFormattedMessage())) .collect(Guavate.toImmutableList())) .containsExactlyInAnyOrder( new Tuple(Level.ERROR, "UNHEALTHY: testing : cause"), new Tuple(Level.WARN, "DEGRADED: testing : cause")); }); }
public void start() { disposable = Flux.interval(configuration.getPeriod(), scheduler) .flatMapIterable(any -> healthChecks) .flatMap(healthCheck -> Mono.from(healthCheck.check())) .doOnNext(this::logResult) .onErrorContinue(this::logError) .subscribeOn(Schedulers.elastic()) .subscribe(); }
PeriodicalHealthChecks implements Startable { public void start() { disposable = Flux.interval(configuration.getPeriod(), scheduler) .flatMapIterable(any -> healthChecks) .flatMap(healthCheck -> Mono.from(healthCheck.check())) .doOnNext(this::logResult) .onErrorContinue(this::logError) .subscribeOn(Schedulers.elastic()) .subscribe(); } }
PeriodicalHealthChecks implements Startable { public void start() { disposable = Flux.interval(configuration.getPeriod(), scheduler) .flatMapIterable(any -> healthChecks) .flatMap(healthCheck -> Mono.from(healthCheck.check())) .doOnNext(this::logResult) .onErrorContinue(this::logError) .subscribeOn(Schedulers.elastic()) .subscribe(); } @Inject  PeriodicalHealthChecks(Set<HealthCheck> healthChecks, PeriodicalHealthChecksConfiguration configuration);   PeriodicalHealthChecks(Set<HealthCheck> healthChecks, Scheduler scheduler, PeriodicalHealthChecksConfiguration configuration); }
PeriodicalHealthChecks implements Startable { public void start() { disposable = Flux.interval(configuration.getPeriod(), scheduler) .flatMapIterable(any -> healthChecks) .flatMap(healthCheck -> Mono.from(healthCheck.check())) .doOnNext(this::logResult) .onErrorContinue(this::logError) .subscribeOn(Schedulers.elastic()) .subscribe(); } @Inject  PeriodicalHealthChecks(Set<HealthCheck> healthChecks, PeriodicalHealthChecksConfiguration configuration);   PeriodicalHealthChecks(Set<HealthCheck> healthChecks, Scheduler scheduler, PeriodicalHealthChecksConfiguration configuration); void start(); @PreDestroy void stop(); }
PeriodicalHealthChecks implements Startable { public void start() { disposable = Flux.interval(configuration.getPeriod(), scheduler) .flatMapIterable(any -> healthChecks) .flatMap(healthCheck -> Mono.from(healthCheck.check())) .doOnNext(this::logResult) .onErrorContinue(this::logError) .subscribeOn(Schedulers.elastic()) .subscribe(); } @Inject  PeriodicalHealthChecks(Set<HealthCheck> healthChecks, PeriodicalHealthChecksConfiguration configuration);   PeriodicalHealthChecks(Set<HealthCheck> healthChecks, Scheduler scheduler, PeriodicalHealthChecksConfiguration configuration); void start(); @PreDestroy void stop();  }