Polish
This commit is contained in:
parent
b7435016fb
commit
befdbaaaa9
|
@ -47,8 +47,8 @@ import org.springframework.context.annotation.Configuration;
|
|||
@ConditionalOnEnabledHealthIndicator("influxdb")
|
||||
@AutoConfigureBefore(HealthIndicatorAutoConfiguration.class)
|
||||
@AutoConfigureAfter(InfluxDbAutoConfiguration.class)
|
||||
public class InfluxDbHealthIndicatorAutoConfiguration extends
|
||||
CompositeHealthIndicatorConfiguration<InfluxDbHealthIndicator, InfluxDB> {
|
||||
public class InfluxDbHealthIndicatorAutoConfiguration
|
||||
extends CompositeHealthIndicatorConfiguration<InfluxDbHealthIndicator, InfluxDB> {
|
||||
|
||||
private final Map<String, InfluxDB> influxDbs;
|
||||
|
||||
|
|
|
@ -38,9 +38,8 @@ import static org.mockito.Mockito.mock;
|
|||
public class InfluxDbHealthIndicatorAutoConfigurationTests {
|
||||
|
||||
private ApplicationContextRunner contextRunner = new ApplicationContextRunner()
|
||||
.withUserConfiguration(InfluxDbConfiguration.class)
|
||||
.withConfiguration(AutoConfigurations.of(
|
||||
InfluxDbHealthIndicatorAutoConfiguration.class,
|
||||
.withUserConfiguration(InfluxDbConfiguration.class).withConfiguration(
|
||||
AutoConfigurations.of(InfluxDbHealthIndicatorAutoConfiguration.class,
|
||||
HealthIndicatorAutoConfiguration.class));
|
||||
|
||||
@Test
|
||||
|
@ -52,9 +51,8 @@ public class InfluxDbHealthIndicatorAutoConfigurationTests {
|
|||
|
||||
@Test
|
||||
public void runWhenDisabledShouldNotCreateIndicator() {
|
||||
this.contextRunner
|
||||
.withPropertyValues("management.health.influxdb.enabled:false").run(
|
||||
(context) -> assertThat(context)
|
||||
this.contextRunner.withPropertyValues("management.health.influxdb.enabled:false")
|
||||
.run((context) -> assertThat(context)
|
||||
.doesNotHaveBean(InfluxDbHealthIndicator.class)
|
||||
.hasSingleBean(ApplicationHealthIndicator.class));
|
||||
}
|
||||
|
|
|
@ -42,9 +42,8 @@ import static org.mockito.Mockito.mock;
|
|||
public class Neo4jHealthIndicatorAutoConfigurationTests {
|
||||
|
||||
private ApplicationContextRunner contextRunner = new ApplicationContextRunner()
|
||||
.withUserConfiguration(Neo4jConfiguration.class)
|
||||
.withConfiguration(AutoConfigurations.of(
|
||||
Neo4jHealthIndicatorAutoConfiguration.class,
|
||||
.withUserConfiguration(Neo4jConfiguration.class).withConfiguration(
|
||||
AutoConfigurations.of(Neo4jHealthIndicatorAutoConfiguration.class,
|
||||
HealthIndicatorAutoConfiguration.class));
|
||||
|
||||
@Test
|
||||
|
@ -64,9 +63,8 @@ public class Neo4jHealthIndicatorAutoConfigurationTests {
|
|||
|
||||
@Test
|
||||
public void defaultIndicatorCanBeReplaced() {
|
||||
this.contextRunner
|
||||
.withUserConfiguration(CustomIndicatorConfiguration.class).run(
|
||||
(context) -> {
|
||||
this.contextRunner.withUserConfiguration(CustomIndicatorConfiguration.class)
|
||||
.run((context) -> {
|
||||
assertThat(context).hasSingleBean(Neo4jHealthIndicator.class);
|
||||
assertThat(context).doesNotHaveBean(ApplicationHealthIndicator.class);
|
||||
Health health = context.getBean(Neo4jHealthIndicator.class).health();
|
||||
|
@ -90,12 +88,15 @@ public class Neo4jHealthIndicatorAutoConfigurationTests {
|
|||
@Bean
|
||||
public Neo4jHealthIndicator neo4jHealthIndicator(SessionFactory sessionFactory) {
|
||||
return new Neo4jHealthIndicator(sessionFactory) {
|
||||
|
||||
@Override
|
||||
protected void extractResult(Session session, Health.Builder builder) {
|
||||
builder.up().withDetail("test", true);
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -48,8 +48,7 @@ public class CassandraHealthIndicator extends AbstractHealthIndicator {
|
|||
|
||||
@Override
|
||||
protected void doHealthCheck(Health.Builder builder) throws Exception {
|
||||
Select select = QueryBuilder.select("release_version").from("system",
|
||||
"local");
|
||||
Select select = QueryBuilder.select("release_version").from("system", "local");
|
||||
ResultSet results = this.cassandraOperations.getCqlOperations()
|
||||
.queryForResultSet(select);
|
||||
if (results.isExhausted()) {
|
||||
|
|
|
@ -16,10 +16,8 @@
|
|||
|
||||
package org.springframework.boot.actuate.couchbase;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
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.Health;
|
||||
|
@ -37,24 +35,21 @@ import org.springframework.util.StringUtils;
|
|||
*/
|
||||
public class CouchbaseHealthIndicator extends AbstractHealthIndicator {
|
||||
|
||||
private CouchbaseOperations couchbaseOperations;
|
||||
private CouchbaseOperations operations;
|
||||
|
||||
public CouchbaseHealthIndicator(CouchbaseOperations couchbaseOperations) {
|
||||
Assert.notNull(couchbaseOperations, "CouchbaseOperations must not be null");
|
||||
this.couchbaseOperations = couchbaseOperations;
|
||||
this.operations = couchbaseOperations;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doHealthCheck(Health.Builder builder) throws Exception {
|
||||
List<Version> versions = this.couchbaseOperations.getCouchbaseClusterInfo()
|
||||
.getAllVersions();
|
||||
BucketInfo bucketInfo = this.couchbaseOperations.getCouchbaseBucket()
|
||||
.bucketManager().info();
|
||||
builder.up()
|
||||
.withDetail("versions", StringUtils.collectionToCommaDelimitedString(
|
||||
versions))
|
||||
.withDetail("nodes", StringUtils.collectionToCommaDelimitedString(
|
||||
bucketInfo.nodeList()));
|
||||
ClusterInfo cluster = this.operations.getCouchbaseClusterInfo();
|
||||
BucketInfo bucket = this.operations.getCouchbaseBucket().bucketManager().info();
|
||||
String versions = StringUtils
|
||||
.collectionToCommaDelimitedString(cluster.getAllVersions());
|
||||
String nodes = StringUtils.collectionToCommaDelimitedString(bucket.nodeList());
|
||||
builder.up().withDetail("versions", versions).withDetail("nodes", nodes);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -48,8 +48,8 @@ public class CouchbaseHealthIndicatorTests {
|
|||
@Test
|
||||
public void couchbaseIsUp() throws UnknownHostException {
|
||||
BucketInfo bucketInfo = mock(BucketInfo.class);
|
||||
given(bucketInfo.nodeList()).willReturn(Collections.singletonList(
|
||||
InetAddress.getByName("127.0.0.1")));
|
||||
given(bucketInfo.nodeList()).willReturn(
|
||||
Collections.singletonList(InetAddress.getByName("127.0.0.1")));
|
||||
BucketManager bucketManager = mock(BucketManager.class);
|
||||
given(bucketManager.info()).willReturn(bucketInfo);
|
||||
Bucket bucket = mock(Bucket.class);
|
||||
|
|
|
@ -55,8 +55,8 @@ public class InfluxDbHealthIndicatorTests {
|
|||
@Test
|
||||
public void influxDbIsDown() {
|
||||
InfluxDB influxDB = mock(InfluxDB.class);
|
||||
given(influxDB.ping()).willThrow(
|
||||
new InfluxDBException(new IOException("Connection failed")));
|
||||
given(influxDB.ping())
|
||||
.willThrow(new InfluxDBException(new IOException("Connection failed")));
|
||||
InfluxDbHealthIndicator healthIndicator = new InfluxDbHealthIndicator(influxDB);
|
||||
Health health = healthIndicator.health();
|
||||
assertThat(health.getStatus()).isEqualTo(Status.DOWN);
|
||||
|
|
|
@ -56,7 +56,7 @@ public class CassandraProperties {
|
|||
private String clusterName;
|
||||
|
||||
/**
|
||||
* Comma-separated list of cluster node addresses.
|
||||
* Cluster node addresses.
|
||||
*/
|
||||
private final List<String> contactPoints = new ArrayList<>(
|
||||
Collections.singleton("localhost"));
|
||||
|
|
Loading…
Reference in New Issue