Skip to content

Commit c9e32aa

Browse files
committed
Use LOCAL_ONE when querying system.local
This commit is a follow-up of gh-20709 to apply the same consistency level to the Cassandra reactive health indicator. Closes gh-20713
1 parent 1f2a655 commit c9e32aa

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

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

Lines changed: 8 additions & 5 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.
@@ -15,8 +15,9 @@
1515
*/
1616
package org.springframework.boot.actuate.cassandra;
1717

18-
import com.datastax.driver.core.querybuilder.QueryBuilder;
19-
import com.datastax.driver.core.querybuilder.Select;
18+
import com.datastax.driver.core.ConsistencyLevel;
19+
import com.datastax.driver.core.SimpleStatement;
20+
import com.datastax.driver.core.Statement;
2021
import reactor.core.publisher.Mono;
2122

2223
import org.springframework.boot.actuate.health.AbstractReactiveHealthIndicator;
@@ -33,6 +34,9 @@
3334
*/
3435
public class CassandraReactiveHealthIndicator extends AbstractReactiveHealthIndicator {
3536

37+
private static final Statement SELECT = new SimpleStatement("SELECT release_version FROM system.local")
38+
.setConsistencyLevel(ConsistencyLevel.LOCAL_ONE);
39+
3640
private final ReactiveCassandraOperations reactiveCassandraOperations;
3741

3842
/**
@@ -47,8 +51,7 @@ public CassandraReactiveHealthIndicator(ReactiveCassandraOperations reactiveCass
4751

4852
@Override
4953
protected Mono<Health> doHealthCheck(Health.Builder builder) {
50-
Select select = QueryBuilder.select("release_version").from("system", "local");
51-
return this.reactiveCassandraOperations.getReactiveCqlOperations().queryForObject(select, String.class)
54+
return this.reactiveCassandraOperations.getReactiveCqlOperations().queryForObject(SELECT, String.class)
5255
.map((version) -> builder.up().withDetail("version", version).build()).single();
5356
}
5457

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

Lines changed: 4 additions & 3 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.
@@ -15,7 +15,7 @@
1515
*/
1616
package org.springframework.boot.actuate.cassandra;
1717

18-
import com.datastax.driver.core.querybuilder.Select;
18+
import com.datastax.driver.core.Statement;
1919
import org.junit.Test;
2020
import reactor.core.publisher.Mono;
2121
import reactor.test.StepVerifier;
@@ -42,7 +42,8 @@ public class CassandraReactiveHealthIndicatorTests {
4242
@Test
4343
public void testCassandraIsUp() {
4444
ReactiveCqlOperations reactiveCqlOperations = mock(ReactiveCqlOperations.class);
45-
given(reactiveCqlOperations.queryForObject(any(Select.class), eq(String.class))).willReturn(Mono.just("6.0.0"));
45+
given(reactiveCqlOperations.queryForObject(any(Statement.class), eq(String.class)))
46+
.willReturn(Mono.just("6.0.0"));
4647
ReactiveCassandraOperations reactiveCassandraOperations = mock(ReactiveCassandraOperations.class);
4748
given(reactiveCassandraOperations.getReactiveCqlOperations()).willReturn(reactiveCqlOperations);
4849

0 commit comments

Comments
 (0)