Make sure Reactive health indicators take precedence

This commit restores the highest precedence of reactive
HealthContributor over imperative one. Previously, both would be
registered, leading to duplicate entries in health output.

Closes gh-18748
This commit is contained in:
Stephane Nicoll
2019-10-28 12:24:09 +01:00
parent a664eadb9a
commit d7652e8f14
12 changed files with 57 additions and 24 deletions

View File

@@ -18,6 +18,7 @@ package org.springframework.boot.actuate.autoconfigure.cassandra;
import org.junit.jupiter.api.Test;
import org.springframework.boot.actuate.autoconfigure.cassandra.CassandraHealthContributorAutoConfigurationTests.CassandraConfiguration;
import org.springframework.boot.actuate.autoconfigure.health.HealthContributorAutoConfiguration;
import org.springframework.boot.actuate.cassandra.CassandraHealthIndicator;
import org.springframework.boot.actuate.cassandra.CassandraReactiveHealthIndicator;
@@ -44,13 +45,23 @@ class CassandraReactiveHealthContributorAutoConfigurationTests {
@Test
void runShouldCreateIndicator() {
this.contextRunner.run((context) -> assertThat(context).hasSingleBean(CassandraReactiveHealthIndicator.class)
.doesNotHaveBean(CassandraHealthIndicator.class));
.hasBean("cassandraHealthContributor"));
}
@Test
void runWithRegularIndicatorShouldOnlyCreateReactiveIndicator() {
this.contextRunner
.withConfiguration(AutoConfigurations.of(CassandraConfiguration.class,
CassandraHealthContributorAutoConfiguration.class))
.run((context) -> assertThat(context).hasSingleBean(CassandraReactiveHealthIndicator.class)
.hasBean("cassandraHealthContributor").doesNotHaveBean(CassandraHealthIndicator.class));
}
@Test
void runWhenDisabledShouldNotCreateIndicator() {
this.contextRunner.withPropertyValues("management.health.cassandra.enabled:false")
.run((context) -> assertThat(context).doesNotHaveBean(CassandraReactiveHealthIndicator.class));
.run((context) -> assertThat(context).doesNotHaveBean(CassandraReactiveHealthIndicator.class)
.doesNotHaveBean("cassandraHealthContributor"));
}
}

View File

@@ -43,13 +43,21 @@ class CouchbaseReactiveHealthContributorAutoConfigurationTests {
@Test
void runShouldCreateIndicator() {
this.contextRunner.run((context) -> assertThat(context).hasSingleBean(CouchbaseReactiveHealthIndicator.class)
.doesNotHaveBean(CouchbaseHealthIndicator.class));
.hasBean("couchbaseHealthContributor"));
}
@Test
void runWithRegularIndicatorShouldOnlyCreateReactiveIndicator() {
this.contextRunner.withConfiguration(AutoConfigurations.of(CouchbaseHealthContributorAutoConfiguration.class))
.run((context) -> assertThat(context).hasSingleBean(CouchbaseReactiveHealthIndicator.class)
.hasBean("couchbaseHealthContributor").doesNotHaveBean(CouchbaseHealthIndicator.class));
}
@Test
void runWhenDisabledShouldNotCreateIndicator() {
this.contextRunner.withPropertyValues("management.health.couchbase.enabled:false")
.run((context) -> assertThat(context).doesNotHaveBean(CouchbaseReactiveHealthIndicator.class));
.run((context) -> assertThat(context).doesNotHaveBean(CouchbaseReactiveHealthIndicator.class)
.doesNotHaveBean("couchbaseHealthContributor"));
}
}

View File

@@ -45,14 +45,21 @@ class MongoReactiveHealthContributorAutoConfigurationTests {
@Test
void runShouldCreateIndicator() {
this.contextRunner.run((context) -> assertThat(context).hasSingleBean(MongoReactiveHealthIndicator.class)
.doesNotHaveBean(MongoHealthIndicator.class));
.hasBean("mongoHealthContributor"));
}
@Test
void runWithRegularIndicatorShouldOnlyCreateReactiveIndicator() {
this.contextRunner.withConfiguration(AutoConfigurations.of(MongoHealthContributorAutoConfiguration.class))
.run((context) -> assertThat(context).hasSingleBean(MongoReactiveHealthIndicator.class)
.hasBean("mongoHealthContributor").doesNotHaveBean(MongoHealthIndicator.class));
}
@Test
void runWhenDisabledShouldNotCreateIndicator() {
this.contextRunner.withPropertyValues("management.health.mongo.enabled:false")
.run((context) -> assertThat(context).doesNotHaveBean(MongoReactiveHealthIndicator.class)
.doesNotHaveBean(MongoHealthIndicator.class));
.doesNotHaveBean("mongoHealthContributor"));
}
}

View File

@@ -40,16 +40,22 @@ class RedisReactiveHealthContributorAutoConfigurationTests {
@Test
void runShouldCreateIndicator() {
this.contextRunner.run(
(context) -> assertThat(context).hasSingleBean(RedisReactiveHealthContributorAutoConfiguration.class)
.doesNotHaveBean(RedisHealthIndicator.class));
this.contextRunner.run((context) -> assertThat(context).hasSingleBean(RedisReactiveHealthIndicator.class)
.hasBean("redisHealthContributor"));
}
@Test
void runWithRegularIndicatorShouldOnlyCreateReactiveIndicator() {
this.contextRunner.withConfiguration(AutoConfigurations.of(RedisHealthContributorAutoConfiguration.class))
.run((context) -> assertThat(context).hasSingleBean(RedisReactiveHealthIndicator.class)
.hasBean("redisHealthContributor").doesNotHaveBean(RedisHealthIndicator.class));
}
@Test
void runWhenDisabledShouldNotCreateIndicator() {
this.contextRunner.withPropertyValues("management.health.redis.enabled:false")
.run((context) -> assertThat(context).doesNotHaveBean(RedisReactiveHealthIndicator.class)
.doesNotHaveBean(RedisHealthIndicator.class));
.doesNotHaveBean("redisHealthContributor"));
}
}