Commit c9e32aaa authored by Stephane Nicoll's avatar Stephane Nicoll

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
parent 1f2a6551
/* /*
* 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -15,8 +15,9 @@ ...@@ -15,8 +15,9 @@
*/ */
package org.springframework.boot.actuate.cassandra; package org.springframework.boot.actuate.cassandra;
import com.datastax.driver.core.querybuilder.QueryBuilder; import com.datastax.driver.core.ConsistencyLevel;
import com.datastax.driver.core.querybuilder.Select; import com.datastax.driver.core.SimpleStatement;
import com.datastax.driver.core.Statement;
import reactor.core.publisher.Mono; import reactor.core.publisher.Mono;
import org.springframework.boot.actuate.health.AbstractReactiveHealthIndicator; import org.springframework.boot.actuate.health.AbstractReactiveHealthIndicator;
...@@ -33,6 +34,9 @@ import org.springframework.util.Assert; ...@@ -33,6 +34,9 @@ import org.springframework.util.Assert;
*/ */
public class CassandraReactiveHealthIndicator extends AbstractReactiveHealthIndicator { public class CassandraReactiveHealthIndicator extends AbstractReactiveHealthIndicator {
private static final Statement SELECT = new SimpleStatement("SELECT release_version FROM system.local")
.setConsistencyLevel(ConsistencyLevel.LOCAL_ONE);
private final ReactiveCassandraOperations reactiveCassandraOperations; private final ReactiveCassandraOperations reactiveCassandraOperations;
/** /**
...@@ -47,8 +51,7 @@ public class CassandraReactiveHealthIndicator extends AbstractReactiveHealthIndi ...@@ -47,8 +51,7 @@ public class CassandraReactiveHealthIndicator extends AbstractReactiveHealthIndi
@Override @Override
protected Mono<Health> doHealthCheck(Health.Builder builder) { protected Mono<Health> doHealthCheck(Health.Builder builder) {
Select select = QueryBuilder.select("release_version").from("system", "local"); return this.reactiveCassandraOperations.getReactiveCqlOperations().queryForObject(SELECT, String.class)
return this.reactiveCassandraOperations.getReactiveCqlOperations().queryForObject(select, String.class)
.map((version) -> builder.up().withDetail("version", version).build()).single(); .map((version) -> builder.up().withDetail("version", version).build()).single();
} }
......
/* /*
* 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
*/ */
package org.springframework.boot.actuate.cassandra; package org.springframework.boot.actuate.cassandra;
import com.datastax.driver.core.querybuilder.Select; import com.datastax.driver.core.Statement;
import org.junit.Test; import org.junit.Test;
import reactor.core.publisher.Mono; import reactor.core.publisher.Mono;
import reactor.test.StepVerifier; import reactor.test.StepVerifier;
...@@ -42,7 +42,8 @@ public class CassandraReactiveHealthIndicatorTests { ...@@ -42,7 +42,8 @@ public class CassandraReactiveHealthIndicatorTests {
@Test @Test
public void testCassandraIsUp() { public void testCassandraIsUp() {
ReactiveCqlOperations reactiveCqlOperations = mock(ReactiveCqlOperations.class); ReactiveCqlOperations reactiveCqlOperations = mock(ReactiveCqlOperations.class);
given(reactiveCqlOperations.queryForObject(any(Select.class), eq(String.class))).willReturn(Mono.just("6.0.0")); given(reactiveCqlOperations.queryForObject(any(Statement.class), eq(String.class)))
.willReturn(Mono.just("6.0.0"));
ReactiveCassandraOperations reactiveCassandraOperations = mock(ReactiveCassandraOperations.class); ReactiveCassandraOperations reactiveCassandraOperations = mock(ReactiveCassandraOperations.class);
given(reactiveCassandraOperations.getReactiveCqlOperations()).willReturn(reactiveCqlOperations); given(reactiveCassandraOperations.getReactiveCqlOperations()).willReturn(reactiveCqlOperations);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment