Skip to content

Commit

Permalink
Merge branch '2.1.x' into 2.2.x
Browse files Browse the repository at this point in the history
Closes gh-20711
  • Loading branch information
snicoll committed Mar 28, 2020
2 parents 5d56e24 + 1f2a655 commit a9a6df2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -16,9 +16,10 @@

package org.springframework.boot.actuate.cassandra;

import com.datastax.driver.core.ConsistencyLevel;
import com.datastax.driver.core.ResultSet;
import com.datastax.driver.core.querybuilder.QueryBuilder;
import com.datastax.driver.core.querybuilder.Select;
import com.datastax.driver.core.SimpleStatement;
import com.datastax.driver.core.Statement;

import org.springframework.boot.actuate.health.AbstractHealthIndicator;
import org.springframework.boot.actuate.health.Health;
Expand All @@ -31,10 +32,14 @@
* Cassandra data stores.
*
* @author Julien Dubois
* @author Alexandre Dutra
* @since 2.0.0
*/
public class CassandraHealthIndicator extends AbstractHealthIndicator {

private static final Statement SELECT = new SimpleStatement("SELECT release_version FROM system.local")
.setConsistencyLevel(ConsistencyLevel.LOCAL_ONE);

private CassandraOperations cassandraOperations;

public CassandraHealthIndicator() {
Expand All @@ -53,9 +58,8 @@ public CassandraHealthIndicator(CassandraOperations cassandraOperations) {

@Override
protected void doHealthCheck(Health.Builder builder) throws Exception {
Select select = QueryBuilder.select("release_version").from("system", "local");
ResultSet results = this.cassandraOperations.getCqlOperations().queryForResultSet(select);
if (results.isExhausted()) {
ResultSet results = this.cassandraOperations.getCqlOperations().queryForResultSet(SELECT);
if (results.isFullyFetched()) {
builder.up();
return;
}
Expand Down
Expand Up @@ -18,7 +18,7 @@

import com.datastax.driver.core.ResultSet;
import com.datastax.driver.core.Row;
import com.datastax.driver.core.querybuilder.Select;
import com.datastax.driver.core.Statement;
import org.junit.jupiter.api.Test;

import org.springframework.boot.actuate.health.Health;
Expand Down Expand Up @@ -51,8 +51,8 @@ void verifyHealthStatusWhenExhausted() {
ResultSet resultSet = mock(ResultSet.class);
CassandraHealthIndicator healthIndicator = new CassandraHealthIndicator(cassandraOperations);
given(cassandraOperations.getCqlOperations()).willReturn(cqlOperations);
given(cqlOperations.queryForResultSet(any(Select.class))).willReturn(resultSet);
given(resultSet.isExhausted()).willReturn(true);
given(cqlOperations.queryForResultSet(any(Statement.class))).willReturn(resultSet);
given(resultSet.isFullyFetched()).willReturn(true);
Health health = healthIndicator.health();
assertThat(health.getStatus()).isEqualTo(Status.UP);
}
Expand All @@ -65,8 +65,8 @@ void verifyHealthStatusWithVersion() {
Row row = mock(Row.class);
CassandraHealthIndicator healthIndicator = new CassandraHealthIndicator(cassandraOperations);
given(cassandraOperations.getCqlOperations()).willReturn(cqlOperations);
given(cqlOperations.queryForResultSet(any(Select.class))).willReturn(resultSet);
given(resultSet.isExhausted()).willReturn(false);
given(cqlOperations.queryForResultSet(any(Statement.class))).willReturn(resultSet);
given(resultSet.isFullyFetched()).willReturn(false);
given(resultSet.one()).willReturn(row);
String expectedVersion = "1.0.0";
given(row.getString(0)).willReturn(expectedVersion);
Expand Down

0 comments on commit a9a6df2

Please sign in to comment.