Polish
This commit is contained in:
@@ -246,9 +246,8 @@ public class EndpointAutoConfiguration {
|
||||
}
|
||||
Map<String, HealthIndicator> allIndicators = new LinkedHashMap<>(
|
||||
healthIndicators);
|
||||
reactiveHealthIndicators.forEach((beanName, indicator) -> {
|
||||
allIndicators.computeIfAbsent(beanName, n -> adapt(indicator));
|
||||
});
|
||||
reactiveHealthIndicators.forEach((beanName, indicator) -> allIndicators
|
||||
.computeIfAbsent(beanName, n -> adapt(indicator)));
|
||||
return allIndicators;
|
||||
}
|
||||
|
||||
|
||||
@@ -67,4 +67,3 @@ public class CompositeReactiveHealthIndicatorConfiguration<H extends ReactiveHea
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -43,8 +43,7 @@ public class ReactiveHealthIndicatorsConfiguration {
|
||||
@ConditionalOnBean(ReactiveRedisConnectionFactory.class)
|
||||
@ConditionalOnEnabledHealthIndicator("redis")
|
||||
static class RedisHealthIndicatorConfiguration extends
|
||||
CompositeReactiveHealthIndicatorConfiguration<RedisReactiveHealthIndicator,
|
||||
ReactiveRedisConnectionFactory> {
|
||||
CompositeReactiveHealthIndicatorConfiguration<RedisReactiveHealthIndicator, ReactiveRedisConnectionFactory> {
|
||||
|
||||
private final Map<String, ReactiveRedisConnectionFactory> redisConnectionFactories;
|
||||
|
||||
|
||||
@@ -47,7 +47,7 @@ public class HealthReactiveWebEndpointExtension {
|
||||
|
||||
@ReadOperation
|
||||
public Mono<WebEndpointResponse<Health>> health() {
|
||||
return this.delegate.health().map(health -> {
|
||||
return this.delegate.health().map((health) -> {
|
||||
Integer status = this.statusHttpMapper.mapStatus(health.getStatus());
|
||||
return new WebEndpointResponse<>(health, status);
|
||||
});
|
||||
|
||||
@@ -47,10 +47,10 @@ public class StatusReactiveWebEndpointExtension {
|
||||
|
||||
@ReadOperation
|
||||
public Mono<WebEndpointResponse<Health>> health() {
|
||||
return this.delegate.health().map(health -> {
|
||||
return this.delegate.health().map((health) -> {
|
||||
Integer status = this.statusHttpMapper.mapStatus(health.getStatus());
|
||||
return new WebEndpointResponse<>(
|
||||
Health.status(health.getStatus()).build(), status);
|
||||
return new WebEndpointResponse<>(Health.status(health.getStatus()).build(),
|
||||
status);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -25,18 +25,17 @@ import reactor.core.publisher.Mono;
|
||||
* @author Stephane Nicoll
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public abstract class AbstractReactiveHealthIndicator
|
||||
implements ReactiveHealthIndicator {
|
||||
public abstract class AbstractReactiveHealthIndicator implements ReactiveHealthIndicator {
|
||||
|
||||
@Override
|
||||
public final Mono<Health> health() {
|
||||
return doHealthCheck(new Health.Builder())
|
||||
.onErrorResume(ex -> Mono.just(new Health.Builder().down(ex).build()));
|
||||
.onErrorResume((ex) -> Mono.just(new Health.Builder().down(ex).build()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Actual health check logic. If an error occurs in the pipeline it will be
|
||||
* handled automatically.
|
||||
* Actual health check logic. If an error occurs in the pipeline it will be handled
|
||||
* automatically.
|
||||
* @param builder the {@link Health.Builder} to report health status and details
|
||||
* @return a {@link Mono} that provides the {@link Health}
|
||||
*/
|
||||
|
||||
@@ -47,7 +47,8 @@ public class CompositeHealthIndicatorFactory {
|
||||
* @return a {@link HealthIndicator} that delegates to the specified
|
||||
* {@code healthIndicators}.
|
||||
*/
|
||||
public CompositeHealthIndicator createHealthIndicator(HealthAggregator healthAggregator,
|
||||
public CompositeHealthIndicator createHealthIndicator(
|
||||
HealthAggregator healthAggregator,
|
||||
Map<String, HealthIndicator> healthIndicators) {
|
||||
Assert.notNull(healthAggregator, "HealthAggregator must not be null");
|
||||
Assert.notNull(healthIndicators, "HealthIndicators must not be null");
|
||||
|
||||
@@ -57,9 +57,8 @@ public class CompositeReactiveHealthIndicator implements ReactiveHealthIndicator
|
||||
Assert.notNull(indicators, "Indicators must not be null");
|
||||
this.indicators = new LinkedHashMap<>(indicators);
|
||||
this.healthAggregator = healthAggregator;
|
||||
this.timeoutCompose = mono -> this.timeout != null ?
|
||||
mono.timeout(Duration.ofMillis(this.timeout), Mono.just(this.timeoutHealth)) :
|
||||
mono;
|
||||
this.timeoutCompose = (mono) -> this.timeout != null ? mono.timeout(
|
||||
Duration.ofMillis(this.timeout), Mono.just(this.timeoutHealth)) : mono;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -77,9 +76,10 @@ public class CompositeReactiveHealthIndicator implements ReactiveHealthIndicator
|
||||
/**
|
||||
* Specify an alternative timeout {@link Health} if an {@link HealthIndicator} failed
|
||||
* to reply after specified {@code timeout}.
|
||||
* @param timeout number of milliseconds to wait before using the {@code timeoutHealth}
|
||||
* @param timeout number of milliseconds to wait before using the
|
||||
* {@code timeoutHealth}
|
||||
* @param timeoutHealth the {@link Health} to use if an health indicator reached the
|
||||
* {@code} timeout
|
||||
* {@code timeout}
|
||||
* @return this instance
|
||||
*/
|
||||
public CompositeReactiveHealthIndicator timeoutStrategy(long timeout,
|
||||
@@ -93,7 +93,7 @@ public class CompositeReactiveHealthIndicator implements ReactiveHealthIndicator
|
||||
@Override
|
||||
public Mono<Health> health() {
|
||||
return Flux.fromIterable(this.indicators.entrySet())
|
||||
.flatMap(entry -> Mono.just(entry.getKey())
|
||||
.flatMap((entry) -> Mono.just(entry.getKey())
|
||||
.and(entry.getValue().health().compose(this.timeoutCompose)))
|
||||
.collectMap(Tuple2::getT1, Tuple2::getT2)
|
||||
.map(this.healthAggregator::aggregate);
|
||||
|
||||
@@ -60,13 +60,15 @@ public class CompositeReactiveHealthIndicatorFactory {
|
||||
Map<String, ReactiveHealthIndicator> reactiveHealthIndicators,
|
||||
Map<String, HealthIndicator> healthIndicators) {
|
||||
Assert.notNull(healthAggregator, "HealthAggregator must not be null");
|
||||
Assert.notNull(reactiveHealthIndicators, "ReactiveHealthIndicators must not be null");
|
||||
Assert.notNull(reactiveHealthIndicators,
|
||||
"ReactiveHealthIndicators must not be null");
|
||||
CompositeReactiveHealthIndicator healthIndicator = new CompositeReactiveHealthIndicator(
|
||||
healthAggregator);
|
||||
merge(reactiveHealthIndicators, healthIndicators).forEach((beanName, indicator) -> {
|
||||
String name = this.healthIndicatorNameFactory.apply(beanName);
|
||||
healthIndicator.addHealthIndicator(name, indicator);
|
||||
});
|
||||
merge(reactiveHealthIndicators, healthIndicators)
|
||||
.forEach((beanName, indicator) -> {
|
||||
String name = this.healthIndicatorNameFactory.apply(beanName);
|
||||
healthIndicator.addHealthIndicator(name, indicator);
|
||||
});
|
||||
return healthIndicator;
|
||||
}
|
||||
|
||||
@@ -80,8 +82,8 @@ public class CompositeReactiveHealthIndicatorFactory {
|
||||
reactiveHealthIndicators);
|
||||
healthIndicators.forEach((beanName, indicator) -> {
|
||||
String name = this.healthIndicatorNameFactory.apply(beanName);
|
||||
allIndicators.computeIfAbsent(name, n ->
|
||||
new HealthIndicatorReactiveAdapter(indicator));
|
||||
allIndicators.computeIfAbsent(name,
|
||||
(n) -> new HealthIndicatorReactiveAdapter(indicator));
|
||||
});
|
||||
return allIndicators;
|
||||
}
|
||||
|
||||
@@ -23,8 +23,8 @@ import reactor.core.scheduler.Schedulers;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* Adapts a {@link HealthIndicator} to a {@link ReactiveHealthIndicator} so that it can
|
||||
* be safely invoked in a reactive environment.
|
||||
* Adapts a {@link HealthIndicator} to a {@link ReactiveHealthIndicator} so that it can be
|
||||
* safely invoked in a reactive environment.
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
* @since 2.0.0
|
||||
@@ -40,8 +40,7 @@ public class HealthIndicatorReactiveAdapter implements ReactiveHealthIndicator {
|
||||
|
||||
@Override
|
||||
public Mono<Health> health() {
|
||||
return Mono.create((sink) ->
|
||||
Schedulers.elastic().schedule(() -> invoke(sink)));
|
||||
return Mono.create((sink) -> Schedulers.elastic().schedule(() -> invoke(sink)));
|
||||
}
|
||||
|
||||
private void invoke(MonoSink<Health> sink) {
|
||||
|
||||
@@ -42,11 +42,11 @@ public class RedisReactiveHealthIndicator extends AbstractReactiveHealthIndicato
|
||||
ReactiveRedisConnection connection = this.connectionFactory
|
||||
.getReactiveConnection();
|
||||
return connection.serverCommands().info()
|
||||
.map(info -> builder.up()
|
||||
.map((info) -> builder.up()
|
||||
.withDetail(RedisHealthIndicator.VERSION,
|
||||
info.getProperty(RedisHealthIndicator.REDIS_VERSION))
|
||||
.build())
|
||||
.doFinally(signal -> connection.close());
|
||||
.doFinally((signal) -> connection.close());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -47,37 +47,38 @@ public class EndpointAutoConfigurationTests {
|
||||
|
||||
@Test
|
||||
public void healthEndpointAdaptReactiveHealthIndicator() {
|
||||
this.contextRunner.withUserConfiguration(
|
||||
ReactiveHealthIndicatorConfiguration.class).run((context) -> {
|
||||
ReactiveHealthIndicator reactiveHealthIndicator = context.getBean(
|
||||
"reactiveHealthIndicator", ReactiveHealthIndicator.class);
|
||||
verify(reactiveHealthIndicator, times(0)).health();
|
||||
Health health = context.getBean(HealthEndpoint.class).health();
|
||||
assertThat(health.getStatus()).isEqualTo(Status.UP);
|
||||
assertThat(health.getDetails()).containsOnlyKeys("reactive");
|
||||
verify(reactiveHealthIndicator, times(1)).health();
|
||||
});
|
||||
this.contextRunner
|
||||
.withUserConfiguration(ReactiveHealthIndicatorConfiguration.class)
|
||||
.run((context) -> {
|
||||
ReactiveHealthIndicator reactiveHealthIndicator = context.getBean(
|
||||
"reactiveHealthIndicator", ReactiveHealthIndicator.class);
|
||||
verify(reactiveHealthIndicator, times(0)).health();
|
||||
Health health = context.getBean(HealthEndpoint.class).health();
|
||||
assertThat(health.getStatus()).isEqualTo(Status.UP);
|
||||
assertThat(health.getDetails()).containsOnlyKeys("reactive");
|
||||
verify(reactiveHealthIndicator, times(1)).health();
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void healthEndpointMergeRegularAndReactive() {
|
||||
this.contextRunner.withUserConfiguration(HealthIndicatorConfiguration.class,
|
||||
ReactiveHealthIndicatorConfiguration.class).run((context) -> {
|
||||
HealthIndicator simpleHealthIndicator = context.getBean(
|
||||
"simpleHealthIndicator", HealthIndicator.class);
|
||||
ReactiveHealthIndicator reactiveHealthIndicator = context.getBean(
|
||||
"reactiveHealthIndicator", ReactiveHealthIndicator.class);
|
||||
verify(simpleHealthIndicator, times(0)).health();
|
||||
verify(reactiveHealthIndicator, times(0)).health();
|
||||
Health health = context.getBean(HealthEndpoint.class).health();
|
||||
assertThat(health.getStatus()).isEqualTo(Status.UP);
|
||||
assertThat(health.getDetails()).containsOnlyKeys("simple", "reactive");
|
||||
verify(simpleHealthIndicator, times(1)).health();
|
||||
verify(reactiveHealthIndicator, times(1)).health();
|
||||
});
|
||||
HealthIndicator simpleHealthIndicator = context
|
||||
.getBean("simpleHealthIndicator", HealthIndicator.class);
|
||||
ReactiveHealthIndicator reactiveHealthIndicator = context.getBean(
|
||||
"reactiveHealthIndicator", ReactiveHealthIndicator.class);
|
||||
verify(simpleHealthIndicator, times(0)).health();
|
||||
verify(reactiveHealthIndicator, times(0)).health();
|
||||
Health health = context.getBean(HealthEndpoint.class).health();
|
||||
assertThat(health.getStatus()).isEqualTo(Status.UP);
|
||||
assertThat(health.getDetails()).containsOnlyKeys("simple",
|
||||
"reactive");
|
||||
verify(simpleHealthIndicator, times(1)).health();
|
||||
verify(reactiveHealthIndicator, times(1)).health();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@Configuration
|
||||
static class HealthIndicatorConfiguration {
|
||||
|
||||
|
||||
@@ -43,17 +43,16 @@ public class ReactiveHealthIndicatorsConfigurationTests {
|
||||
@Test
|
||||
public void redisHealthIndicator() {
|
||||
this.contextRunner
|
||||
.withConfiguration(AutoConfigurations.of(
|
||||
RedisAutoConfiguration.class))
|
||||
.withConfiguration(AutoConfigurations.of(RedisAutoConfiguration.class))
|
||||
.withPropertyValues("management.health.diskspace.enabled:false")
|
||||
.run(hasSingleReactiveHealthIndicator(RedisReactiveHealthIndicator.class));
|
||||
.run(hasSingleReactiveHealthIndicator(
|
||||
RedisReactiveHealthIndicator.class));
|
||||
}
|
||||
|
||||
private ContextConsumer<AssertableApplicationContext> hasSingleReactiveHealthIndicator(
|
||||
Class<? extends ReactiveHealthIndicator> type) {
|
||||
return (context) -> assertThat(context).getBeans(ReactiveHealthIndicator.class)
|
||||
.hasSize(1)
|
||||
.hasValueSatisfying(
|
||||
.hasSize(1).hasValueSatisfying(
|
||||
new Condition<>((indicator) -> indicator.getClass().equals(type),
|
||||
"Wrong indicator type"));
|
||||
}
|
||||
|
||||
@@ -44,7 +44,6 @@ public class LiquibaseEndpointTests {
|
||||
LiquibaseAutoConfiguration.class))
|
||||
.withPropertyValues("spring.datasource.generate-unique-name=true");
|
||||
|
||||
|
||||
@Test
|
||||
public void liquibaseReportIsReturned() throws Exception {
|
||||
this.contextRunner.withUserConfiguration(Config.class)
|
||||
|
||||
@@ -69,8 +69,9 @@ public class HealthEndpointWebIntegrationTests {
|
||||
@Bean
|
||||
public HealthEndpoint healthEndpoint(
|
||||
Map<String, HealthIndicator> healthIndicators) {
|
||||
return new HealthEndpoint(new CompositeHealthIndicatorFactory().createHealthIndicator(
|
||||
new OrderedHealthAggregator(), healthIndicators));
|
||||
return new HealthEndpoint(
|
||||
new CompositeHealthIndicatorFactory().createHealthIndicator(
|
||||
new OrderedHealthAggregator(), healthIndicators));
|
||||
}
|
||||
|
||||
@Bean
|
||||
|
||||
@@ -67,8 +67,9 @@ public class StatusEndpointWebIntegrationTests {
|
||||
@Bean
|
||||
public StatusEndpoint statusEndpoint(
|
||||
Map<String, HealthIndicator> healthIndicators) {
|
||||
return new StatusEndpoint(new CompositeHealthIndicatorFactory().createHealthIndicator(
|
||||
new OrderedHealthAggregator(), healthIndicators));
|
||||
return new StatusEndpoint(
|
||||
new CompositeHealthIndicatorFactory().createHealthIndicator(
|
||||
new OrderedHealthAggregator(), healthIndicators));
|
||||
}
|
||||
|
||||
@Bean
|
||||
|
||||
@@ -44,7 +44,7 @@ public class CompositeReactiveHealthIndicatorFactoryTests {
|
||||
public void noHealthIndicator() {
|
||||
ReactiveHealthIndicator healthIndicator = createHealthIndicator(
|
||||
Collections.singletonMap("test", () -> Mono.just(UP)), null);
|
||||
StepVerifier.create(healthIndicator.health()).consumeNextWith(h -> {
|
||||
StepVerifier.create(healthIndicator.health()).consumeNextWith((h) -> {
|
||||
assertThat(h.getStatus()).isEqualTo(Status.UP);
|
||||
assertThat(h.getDetails()).containsOnlyKeys("test");
|
||||
}).verifyComplete();
|
||||
@@ -53,10 +53,9 @@ public class CompositeReactiveHealthIndicatorFactoryTests {
|
||||
@Test
|
||||
public void defaultHealthIndicatorNameFactory() {
|
||||
ReactiveHealthIndicator healthIndicator = new CompositeReactiveHealthIndicatorFactory()
|
||||
.createReactiveHealthIndicator(new OrderedHealthAggregator(),
|
||||
Collections.singletonMap("myHealthIndicator", () -> Mono.just(UP)),
|
||||
null);
|
||||
StepVerifier.create(healthIndicator.health()).consumeNextWith(h -> {
|
||||
.createReactiveHealthIndicator(new OrderedHealthAggregator(), Collections
|
||||
.singletonMap("myHealthIndicator", () -> Mono.just(UP)), null);
|
||||
StepVerifier.create(healthIndicator.health()).consumeNextWith((h) -> {
|
||||
assertThat(h.getStatus()).isEqualTo(Status.UP);
|
||||
assertThat(h.getDetails()).containsOnlyKeys("my");
|
||||
}).verifyComplete();
|
||||
@@ -67,7 +66,7 @@ public class CompositeReactiveHealthIndicatorFactoryTests {
|
||||
ReactiveHealthIndicator healthIndicator = createHealthIndicator(
|
||||
Collections.singletonMap("test", () -> Mono.just(UP)),
|
||||
Collections.singletonMap("regular", () -> DOWN));
|
||||
StepVerifier.create(healthIndicator.health()).consumeNextWith(h -> {
|
||||
StepVerifier.create(healthIndicator.health()).consumeNextWith((h) -> {
|
||||
assertThat(h.getStatus()).isEqualTo(Status.DOWN);
|
||||
assertThat(h.getDetails()).containsOnlyKeys("test", "regular");
|
||||
}).verifyComplete();
|
||||
@@ -75,14 +74,15 @@ public class CompositeReactiveHealthIndicatorFactoryTests {
|
||||
|
||||
@Test
|
||||
public void reactiveHealthIndicatorTakesPrecedence() {
|
||||
ReactiveHealthIndicator reactivehealthIndicator = mock(ReactiveHealthIndicator.class);
|
||||
ReactiveHealthIndicator reactivehealthIndicator = mock(
|
||||
ReactiveHealthIndicator.class);
|
||||
given(reactivehealthIndicator.health()).willReturn(Mono.just(UP));
|
||||
HealthIndicator regularHealthIndicator = mock(HealthIndicator.class);
|
||||
given(regularHealthIndicator.health()).willReturn(UP);
|
||||
ReactiveHealthIndicator healthIndicator = createHealthIndicator(
|
||||
Collections.singletonMap("test", reactivehealthIndicator),
|
||||
Collections.singletonMap("test", regularHealthIndicator));
|
||||
StepVerifier.create(healthIndicator.health()).consumeNextWith(h -> {
|
||||
StepVerifier.create(healthIndicator.health()).consumeNextWith((h) -> {
|
||||
assertThat(h.getStatus()).isEqualTo(Status.UP);
|
||||
assertThat(h.getDetails()).containsOnlyKeys("test");
|
||||
}).verifyComplete();
|
||||
@@ -93,7 +93,7 @@ public class CompositeReactiveHealthIndicatorFactoryTests {
|
||||
private ReactiveHealthIndicator createHealthIndicator(
|
||||
Map<String, ReactiveHealthIndicator> reactiveHealthIndicators,
|
||||
Map<String, HealthIndicator> healthIndicators) {
|
||||
return new CompositeReactiveHealthIndicatorFactory(n -> n)
|
||||
return new CompositeReactiveHealthIndicatorFactory((n) -> n)
|
||||
.createReactiveHealthIndicator(new OrderedHealthAggregator(),
|
||||
reactiveHealthIndicators, healthIndicators);
|
||||
}
|
||||
|
||||
@@ -38,13 +38,13 @@ public class CompositeReactiveHealthIndicatorTests {
|
||||
|
||||
private OrderedHealthAggregator healthAggregator = new OrderedHealthAggregator();
|
||||
|
||||
private CompositeReactiveHealthIndicator indicator =
|
||||
new CompositeReactiveHealthIndicator(this.healthAggregator);
|
||||
private CompositeReactiveHealthIndicator indicator = new CompositeReactiveHealthIndicator(
|
||||
this.healthAggregator);
|
||||
|
||||
@Test
|
||||
public void singleIndicator() {
|
||||
this.indicator.addHealthIndicator("test", () -> Mono.just(HEALTHY));
|
||||
StepVerifier.create(this.indicator.health()).consumeNextWith(h -> {
|
||||
StepVerifier.create(this.indicator.health()).consumeNextWith((h) -> {
|
||||
assertThat(h.getStatus()).isEqualTo(Status.UP);
|
||||
assertThat(h.getDetails()).containsOnlyKeys("test");
|
||||
assertThat(h.getDetails().get("test")).isEqualTo(HEALTHY);
|
||||
@@ -54,17 +54,14 @@ public class CompositeReactiveHealthIndicatorTests {
|
||||
@Test
|
||||
public void longHealth() {
|
||||
for (int i = 0; i < 50; i++) {
|
||||
this.indicator.addHealthIndicator(
|
||||
"test" + i, new TimeoutHealth(10000, Status.UP));
|
||||
this.indicator.addHealthIndicator("test" + i,
|
||||
new TimeoutHealth(10000, Status.UP));
|
||||
}
|
||||
StepVerifier.withVirtualTime(this.indicator::health)
|
||||
.expectSubscription()
|
||||
.thenAwait(Duration.ofMillis(10000))
|
||||
.consumeNextWith(h -> {
|
||||
StepVerifier.withVirtualTime(this.indicator::health).expectSubscription()
|
||||
.thenAwait(Duration.ofMillis(10000)).consumeNextWith((h) -> {
|
||||
assertThat(h.getStatus()).isEqualTo(Status.UP);
|
||||
assertThat(h.getDetails()).hasSize(50);
|
||||
})
|
||||
.verifyComplete();
|
||||
}).verifyComplete();
|
||||
|
||||
}
|
||||
|
||||
@@ -73,7 +70,7 @@ public class CompositeReactiveHealthIndicatorTests {
|
||||
this.indicator.addHealthIndicator("slow", new TimeoutHealth(10000, Status.UP))
|
||||
.addHealthIndicator("fast", new TimeoutHealth(10, Status.UP))
|
||||
.timeoutStrategy(100, UNKNOWN_HEALTH);
|
||||
StepVerifier.create(this.indicator.health()).consumeNextWith(h -> {
|
||||
StepVerifier.create(this.indicator.health()).consumeNextWith((h) -> {
|
||||
assertThat(h.getStatus()).isEqualTo(Status.UP);
|
||||
assertThat(h.getDetails()).containsOnlyKeys("slow", "fast");
|
||||
assertThat(h.getDetails().get("slow")).isEqualTo(UNKNOWN_HEALTH);
|
||||
@@ -86,16 +83,13 @@ public class CompositeReactiveHealthIndicatorTests {
|
||||
this.indicator.addHealthIndicator("slow", new TimeoutHealth(10000, Status.UP))
|
||||
.addHealthIndicator("fast", new TimeoutHealth(10, Status.UP))
|
||||
.timeoutStrategy(20000, null);
|
||||
StepVerifier.withVirtualTime(this.indicator::health)
|
||||
.expectSubscription()
|
||||
.thenAwait(Duration.ofMillis(10000))
|
||||
.consumeNextWith(h -> {
|
||||
StepVerifier.withVirtualTime(this.indicator::health).expectSubscription()
|
||||
.thenAwait(Duration.ofMillis(10000)).consumeNextWith((h) -> {
|
||||
assertThat(h.getStatus()).isEqualTo(Status.UP);
|
||||
assertThat(h.getDetails()).containsOnlyKeys("slow", "fast");
|
||||
assertThat(h.getDetails().get("slow")).isEqualTo(HEALTHY);
|
||||
assertThat(h.getDetails().get("fast")).isEqualTo(HEALTHY);
|
||||
})
|
||||
.verifyComplete();
|
||||
}).verifyComplete();
|
||||
}
|
||||
|
||||
static class TimeoutHealth implements ReactiveHealthIndicator {
|
||||
@@ -112,7 +106,7 @@ public class CompositeReactiveHealthIndicatorTests {
|
||||
@Override
|
||||
public Mono<Health> health() {
|
||||
return Mono.delay(Duration.ofMillis(this.timeout))
|
||||
.map(l -> Health.status(this.status).build());
|
||||
.map((l) -> Health.status(this.status).build());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -32,7 +32,8 @@ public class HealthIndicatorReactiveAdapterTests {
|
||||
@Test
|
||||
public void delegateReturnsHealth() {
|
||||
HealthIndicator delegate = mock(HealthIndicator.class);
|
||||
HealthIndicatorReactiveAdapter adapter = new HealthIndicatorReactiveAdapter(delegate);
|
||||
HealthIndicatorReactiveAdapter adapter = new HealthIndicatorReactiveAdapter(
|
||||
delegate);
|
||||
Health status = Health.up().build();
|
||||
given(delegate.health()).willReturn(status);
|
||||
StepVerifier.create(adapter.health()).expectNext(status).verifyComplete();
|
||||
@@ -41,7 +42,8 @@ public class HealthIndicatorReactiveAdapterTests {
|
||||
@Test
|
||||
public void delegateThrowError() {
|
||||
HealthIndicator delegate = mock(HealthIndicator.class);
|
||||
HealthIndicatorReactiveAdapter adapter = new HealthIndicatorReactiveAdapter(delegate);
|
||||
HealthIndicatorReactiveAdapter adapter = new HealthIndicatorReactiveAdapter(
|
||||
delegate);
|
||||
given(delegate.health()).willThrow(new IllegalStateException("Expected"));
|
||||
StepVerifier.create(adapter.health()).expectError(IllegalStateException.class);
|
||||
}
|
||||
@@ -49,9 +51,12 @@ public class HealthIndicatorReactiveAdapterTests {
|
||||
@Test
|
||||
public void delegateRunsOnTheElasticScheduler() {
|
||||
String currentThread = Thread.currentThread().getName();
|
||||
HealthIndicator delegate = () -> Health.status(Thread.currentThread().getName()
|
||||
.equals(currentThread) ? Status.DOWN : Status.UP).build();
|
||||
HealthIndicatorReactiveAdapter adapter = new HealthIndicatorReactiveAdapter(delegate);
|
||||
HealthIndicator delegate = () -> Health
|
||||
.status(Thread.currentThread().getName().equals(currentThread)
|
||||
? Status.DOWN : Status.UP)
|
||||
.build();
|
||||
HealthIndicatorReactiveAdapter adapter = new HealthIndicatorReactiveAdapter(
|
||||
delegate);
|
||||
StepVerifier.create(adapter.health()).expectNext(Health.status(Status.UP).build())
|
||||
.verifyComplete();
|
||||
}
|
||||
|
||||
@@ -47,9 +47,10 @@ public class RedisReactiveHealthIndicatorTests {
|
||||
ReactiveRedisConnection redisConnection = mock(ReactiveRedisConnection.class);
|
||||
ReactiveServerCommands commands = mock(ReactiveServerCommands.class);
|
||||
given(commands.info()).willReturn(Mono.just(info));
|
||||
RedisReactiveHealthIndicator healthIndicator = createHealthIndicator(redisConnection, commands);
|
||||
RedisReactiveHealthIndicator healthIndicator = createHealthIndicator(
|
||||
redisConnection, commands);
|
||||
Mono<Health> health = healthIndicator.health();
|
||||
StepVerifier.create(health).consumeNextWith(h -> {
|
||||
StepVerifier.create(health).consumeNextWith((h) -> {
|
||||
assertThat(h.getStatus()).isEqualTo(Status.UP);
|
||||
assertThat(h.getDetails()).containsOnlyKeys("version");
|
||||
assertThat(h.getDetails().get("version")).isEqualTo("2.8.9");
|
||||
@@ -60,19 +61,21 @@ public class RedisReactiveHealthIndicatorTests {
|
||||
@Test
|
||||
public void redisIsDown() throws Exception {
|
||||
ReactiveServerCommands commands = mock(ReactiveServerCommands.class);
|
||||
given(commands.info()).willReturn(Mono.error(
|
||||
new RedisConnectionFailureException("Connection failed")));
|
||||
given(commands.info()).willReturn(
|
||||
Mono.error(new RedisConnectionFailureException("Connection failed")));
|
||||
ReactiveRedisConnection redisConnection = mock(ReactiveRedisConnection.class);
|
||||
RedisReactiveHealthIndicator healthIndicator = createHealthIndicator(redisConnection, commands);
|
||||
RedisReactiveHealthIndicator healthIndicator = createHealthIndicator(
|
||||
redisConnection, commands);
|
||||
Mono<Health> health = healthIndicator.health();
|
||||
StepVerifier.create(health).consumeNextWith(h -> {
|
||||
assertThat(h.getStatus()).isEqualTo(Status.DOWN);
|
||||
}).verifyComplete();
|
||||
StepVerifier.create(health)
|
||||
.consumeNextWith((h) -> assertThat(h.getStatus()).isEqualTo(Status.DOWN))
|
||||
.verifyComplete();
|
||||
verify(redisConnection).close();
|
||||
}
|
||||
|
||||
private RedisReactiveHealthIndicator createHealthIndicator(
|
||||
ReactiveRedisConnection redisConnection, ReactiveServerCommands serverCommands) {
|
||||
ReactiveRedisConnection redisConnection,
|
||||
ReactiveServerCommands serverCommands) {
|
||||
|
||||
ReactiveRedisConnectionFactory redisConnectionFactory = mock(
|
||||
ReactiveRedisConnectionFactory.class);
|
||||
|
||||
Reference in New Issue
Block a user