This commit is contained in:
Phillip Webb 2017-12-15 14:57:25 -08:00
parent b7435016fb
commit befdbaaaa9
8 changed files with 30 additions and 37 deletions

View File

@ -47,8 +47,8 @@ import org.springframework.context.annotation.Configuration;
@ConditionalOnEnabledHealthIndicator("influxdb") @ConditionalOnEnabledHealthIndicator("influxdb")
@AutoConfigureBefore(HealthIndicatorAutoConfiguration.class) @AutoConfigureBefore(HealthIndicatorAutoConfiguration.class)
@AutoConfigureAfter(InfluxDbAutoConfiguration.class) @AutoConfigureAfter(InfluxDbAutoConfiguration.class)
public class InfluxDbHealthIndicatorAutoConfiguration extends public class InfluxDbHealthIndicatorAutoConfiguration
CompositeHealthIndicatorConfiguration<InfluxDbHealthIndicator, InfluxDB> { extends CompositeHealthIndicatorConfiguration<InfluxDbHealthIndicator, InfluxDB> {
private final Map<String, InfluxDB> influxDbs; private final Map<String, InfluxDB> influxDbs;

View File

@ -38,9 +38,8 @@ import static org.mockito.Mockito.mock;
public class InfluxDbHealthIndicatorAutoConfigurationTests { public class InfluxDbHealthIndicatorAutoConfigurationTests {
private ApplicationContextRunner contextRunner = new ApplicationContextRunner() private ApplicationContextRunner contextRunner = new ApplicationContextRunner()
.withUserConfiguration(InfluxDbConfiguration.class) .withUserConfiguration(InfluxDbConfiguration.class).withConfiguration(
.withConfiguration(AutoConfigurations.of( AutoConfigurations.of(InfluxDbHealthIndicatorAutoConfiguration.class,
InfluxDbHealthIndicatorAutoConfiguration.class,
HealthIndicatorAutoConfiguration.class)); HealthIndicatorAutoConfiguration.class));
@Test @Test
@ -52,9 +51,8 @@ public class InfluxDbHealthIndicatorAutoConfigurationTests {
@Test @Test
public void runWhenDisabledShouldNotCreateIndicator() { public void runWhenDisabledShouldNotCreateIndicator() {
this.contextRunner this.contextRunner.withPropertyValues("management.health.influxdb.enabled:false")
.withPropertyValues("management.health.influxdb.enabled:false").run( .run((context) -> assertThat(context)
(context) -> assertThat(context)
.doesNotHaveBean(InfluxDbHealthIndicator.class) .doesNotHaveBean(InfluxDbHealthIndicator.class)
.hasSingleBean(ApplicationHealthIndicator.class)); .hasSingleBean(ApplicationHealthIndicator.class));
} }

View File

@ -42,9 +42,8 @@ import static org.mockito.Mockito.mock;
public class Neo4jHealthIndicatorAutoConfigurationTests { public class Neo4jHealthIndicatorAutoConfigurationTests {
private ApplicationContextRunner contextRunner = new ApplicationContextRunner() private ApplicationContextRunner contextRunner = new ApplicationContextRunner()
.withUserConfiguration(Neo4jConfiguration.class) .withUserConfiguration(Neo4jConfiguration.class).withConfiguration(
.withConfiguration(AutoConfigurations.of( AutoConfigurations.of(Neo4jHealthIndicatorAutoConfiguration.class,
Neo4jHealthIndicatorAutoConfiguration.class,
HealthIndicatorAutoConfiguration.class)); HealthIndicatorAutoConfiguration.class));
@Test @Test
@ -64,9 +63,8 @@ public class Neo4jHealthIndicatorAutoConfigurationTests {
@Test @Test
public void defaultIndicatorCanBeReplaced() { public void defaultIndicatorCanBeReplaced() {
this.contextRunner this.contextRunner.withUserConfiguration(CustomIndicatorConfiguration.class)
.withUserConfiguration(CustomIndicatorConfiguration.class).run( .run((context) -> {
(context) -> {
assertThat(context).hasSingleBean(Neo4jHealthIndicator.class); assertThat(context).hasSingleBean(Neo4jHealthIndicator.class);
assertThat(context).doesNotHaveBean(ApplicationHealthIndicator.class); assertThat(context).doesNotHaveBean(ApplicationHealthIndicator.class);
Health health = context.getBean(Neo4jHealthIndicator.class).health(); Health health = context.getBean(Neo4jHealthIndicator.class).health();
@ -90,12 +88,15 @@ public class Neo4jHealthIndicatorAutoConfigurationTests {
@Bean @Bean
public Neo4jHealthIndicator neo4jHealthIndicator(SessionFactory sessionFactory) { public Neo4jHealthIndicator neo4jHealthIndicator(SessionFactory sessionFactory) {
return new Neo4jHealthIndicator(sessionFactory) { return new Neo4jHealthIndicator(sessionFactory) {
@Override @Override
protected void extractResult(Session session, Health.Builder builder) { protected void extractResult(Session session, Health.Builder builder) {
builder.up().withDetail("test", true); builder.up().withDetail("test", true);
} }
}; };
} }
} }
} }

View File

@ -48,8 +48,7 @@ public class CassandraHealthIndicator extends AbstractHealthIndicator {
@Override @Override
protected void doHealthCheck(Health.Builder builder) throws Exception { protected void doHealthCheck(Health.Builder builder) throws Exception {
Select select = QueryBuilder.select("release_version").from("system", Select select = QueryBuilder.select("release_version").from("system", "local");
"local");
ResultSet results = this.cassandraOperations.getCqlOperations() ResultSet results = this.cassandraOperations.getCqlOperations()
.queryForResultSet(select); .queryForResultSet(select);
if (results.isExhausted()) { if (results.isExhausted()) {

View File

@ -16,10 +16,8 @@
package org.springframework.boot.actuate.couchbase; package org.springframework.boot.actuate.couchbase;
import java.util.List;
import com.couchbase.client.java.bucket.BucketInfo; import com.couchbase.client.java.bucket.BucketInfo;
import com.couchbase.client.java.util.features.Version; import com.couchbase.client.java.cluster.ClusterInfo;
import org.springframework.boot.actuate.health.AbstractHealthIndicator; import org.springframework.boot.actuate.health.AbstractHealthIndicator;
import org.springframework.boot.actuate.health.Health; import org.springframework.boot.actuate.health.Health;
@ -37,24 +35,21 @@ import org.springframework.util.StringUtils;
*/ */
public class CouchbaseHealthIndicator extends AbstractHealthIndicator { public class CouchbaseHealthIndicator extends AbstractHealthIndicator {
private CouchbaseOperations couchbaseOperations; private CouchbaseOperations operations;
public CouchbaseHealthIndicator(CouchbaseOperations couchbaseOperations) { public CouchbaseHealthIndicator(CouchbaseOperations couchbaseOperations) {
Assert.notNull(couchbaseOperations, "CouchbaseOperations must not be null"); Assert.notNull(couchbaseOperations, "CouchbaseOperations must not be null");
this.couchbaseOperations = couchbaseOperations; this.operations = couchbaseOperations;
} }
@Override @Override
protected void doHealthCheck(Health.Builder builder) throws Exception { protected void doHealthCheck(Health.Builder builder) throws Exception {
List<Version> versions = this.couchbaseOperations.getCouchbaseClusterInfo() ClusterInfo cluster = this.operations.getCouchbaseClusterInfo();
.getAllVersions(); BucketInfo bucket = this.operations.getCouchbaseBucket().bucketManager().info();
BucketInfo bucketInfo = this.couchbaseOperations.getCouchbaseBucket() String versions = StringUtils
.bucketManager().info(); .collectionToCommaDelimitedString(cluster.getAllVersions());
builder.up() String nodes = StringUtils.collectionToCommaDelimitedString(bucket.nodeList());
.withDetail("versions", StringUtils.collectionToCommaDelimitedString( builder.up().withDetail("versions", versions).withDetail("nodes", nodes);
versions))
.withDetail("nodes", StringUtils.collectionToCommaDelimitedString(
bucketInfo.nodeList()));
} }
} }

View File

@ -48,8 +48,8 @@ public class CouchbaseHealthIndicatorTests {
@Test @Test
public void couchbaseIsUp() throws UnknownHostException { public void couchbaseIsUp() throws UnknownHostException {
BucketInfo bucketInfo = mock(BucketInfo.class); BucketInfo bucketInfo = mock(BucketInfo.class);
given(bucketInfo.nodeList()).willReturn(Collections.singletonList( given(bucketInfo.nodeList()).willReturn(
InetAddress.getByName("127.0.0.1"))); Collections.singletonList(InetAddress.getByName("127.0.0.1")));
BucketManager bucketManager = mock(BucketManager.class); BucketManager bucketManager = mock(BucketManager.class);
given(bucketManager.info()).willReturn(bucketInfo); given(bucketManager.info()).willReturn(bucketInfo);
Bucket bucket = mock(Bucket.class); Bucket bucket = mock(Bucket.class);

View File

@ -55,8 +55,8 @@ public class InfluxDbHealthIndicatorTests {
@Test @Test
public void influxDbIsDown() { public void influxDbIsDown() {
InfluxDB influxDB = mock(InfluxDB.class); InfluxDB influxDB = mock(InfluxDB.class);
given(influxDB.ping()).willThrow( given(influxDB.ping())
new InfluxDBException(new IOException("Connection failed"))); .willThrow(new InfluxDBException(new IOException("Connection failed")));
InfluxDbHealthIndicator healthIndicator = new InfluxDbHealthIndicator(influxDB); InfluxDbHealthIndicator healthIndicator = new InfluxDbHealthIndicator(influxDB);
Health health = healthIndicator.health(); Health health = healthIndicator.health();
assertThat(health.getStatus()).isEqualTo(Status.DOWN); assertThat(health.getStatus()).isEqualTo(Status.DOWN);

View File

@ -56,7 +56,7 @@ public class CassandraProperties {
private String clusterName; private String clusterName;
/** /**
* Comma-separated list of cluster node addresses. * Cluster node addresses.
*/ */
private final List<String> contactPoints = new ArrayList<>( private final List<String> contactPoints = new ArrayList<>(
Collections.singleton("localhost")); Collections.singleton("localhost"));