Skip to content

Commit 1f2a655

Browse files
committed
Merge pull request #20709 from adutra
* pr/20709: Polish "Use LOCAL_ONE when querying system.local" Use LOCAL_ONE when querying system.local Closes gh-20709
2 parents 1835323 + 63be167 commit 1f2a655

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/cassandra/CassandraHealthIndicator.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,9 +16,10 @@
1616

1717
package org.springframework.boot.actuate.cassandra;
1818

19+
import com.datastax.driver.core.ConsistencyLevel;
1920
import com.datastax.driver.core.ResultSet;
20-
import com.datastax.driver.core.querybuilder.QueryBuilder;
21-
import com.datastax.driver.core.querybuilder.Select;
21+
import com.datastax.driver.core.SimpleStatement;
22+
import com.datastax.driver.core.Statement;
2223

2324
import org.springframework.boot.actuate.health.AbstractHealthIndicator;
2425
import org.springframework.boot.actuate.health.Health;
@@ -31,10 +32,14 @@
3132
* Cassandra data stores.
3233
*
3334
* @author Julien Dubois
35+
* @author Alexandre Dutra
3436
* @since 2.0.0
3537
*/
3638
public class CassandraHealthIndicator extends AbstractHealthIndicator {
3739

40+
private static final Statement SELECT = new SimpleStatement("SELECT release_version FROM system.local")
41+
.setConsistencyLevel(ConsistencyLevel.LOCAL_ONE);
42+
3843
private CassandraOperations cassandraOperations;
3944

4045
public CassandraHealthIndicator() {
@@ -53,9 +58,8 @@ public CassandraHealthIndicator(CassandraOperations cassandraOperations) {
5358

5459
@Override
5560
protected void doHealthCheck(Health.Builder builder) throws Exception {
56-
Select select = QueryBuilder.select("release_version").from("system", "local");
57-
ResultSet results = this.cassandraOperations.getCqlOperations().queryForResultSet(select);
58-
if (results.isExhausted()) {
61+
ResultSet results = this.cassandraOperations.getCqlOperations().queryForResultSet(SELECT);
62+
if (results.isFullyFetched()) {
5963
builder.up();
6064
return;
6165
}

spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/cassandra/CassandraHealthIndicatorTests.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
import com.datastax.driver.core.ResultSet;
2020
import com.datastax.driver.core.Row;
21-
import com.datastax.driver.core.querybuilder.Select;
21+
import com.datastax.driver.core.Statement;
2222
import org.junit.Test;
2323

2424
import org.springframework.boot.actuate.health.Health;
@@ -51,8 +51,8 @@ public void verifyHealthStatusWhenExhausted() {
5151
ResultSet resultSet = mock(ResultSet.class);
5252
CassandraHealthIndicator healthIndicator = new CassandraHealthIndicator(cassandraOperations);
5353
given(cassandraOperations.getCqlOperations()).willReturn(cqlOperations);
54-
given(cqlOperations.queryForResultSet(any(Select.class))).willReturn(resultSet);
55-
given(resultSet.isExhausted()).willReturn(true);
54+
given(cqlOperations.queryForResultSet(any(Statement.class))).willReturn(resultSet);
55+
given(resultSet.isFullyFetched()).willReturn(true);
5656
Health health = healthIndicator.health();
5757
assertThat(health.getStatus()).isEqualTo(Status.UP);
5858
}
@@ -65,8 +65,8 @@ public void verifyHealthStatusWithVersion() {
6565
Row row = mock(Row.class);
6666
CassandraHealthIndicator healthIndicator = new CassandraHealthIndicator(cassandraOperations);
6767
given(cassandraOperations.getCqlOperations()).willReturn(cqlOperations);
68-
given(cqlOperations.queryForResultSet(any(Select.class))).willReturn(resultSet);
69-
given(resultSet.isExhausted()).willReturn(false);
68+
given(cqlOperations.queryForResultSet(any(Statement.class))).willReturn(resultSet);
69+
given(resultSet.isFullyFetched()).willReturn(false);
7070
given(resultSet.one()).willReturn(row);
7171
String expectedVersion = "1.0.0";
7272
given(row.getString(0)).willReturn(expectedVersion);

0 commit comments

Comments
 (0)