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

@@ -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()) {

View File

@@ -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);
}
}

View File

@@ -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);

View File

@@ -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);