Polish "Add reactive health indicator for Cassandra"
Closes gh-13864
This commit is contained in:
parent
61c41555c8
commit
af0aa11d15
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2017 the original author or authors.
|
* Copyright 2012-2018 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.
|
||||||
|
@ -16,55 +16,39 @@
|
||||||
|
|
||||||
package org.springframework.boot.actuate.autoconfigure.cassandra;
|
package org.springframework.boot.actuate.autoconfigure.cassandra;
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import com.datastax.driver.core.Cluster;
|
import com.datastax.driver.core.Cluster;
|
||||||
|
|
||||||
import org.springframework.boot.actuate.autoconfigure.health.CompositeHealthIndicatorConfiguration;
|
|
||||||
import org.springframework.boot.actuate.autoconfigure.health.ConditionalOnEnabledHealthIndicator;
|
import org.springframework.boot.actuate.autoconfigure.health.ConditionalOnEnabledHealthIndicator;
|
||||||
import org.springframework.boot.actuate.autoconfigure.health.HealthIndicatorAutoConfiguration;
|
import org.springframework.boot.actuate.autoconfigure.health.HealthIndicatorAutoConfiguration;
|
||||||
import org.springframework.boot.actuate.cassandra.CassandraHealthIndicator;
|
import org.springframework.boot.actuate.cassandra.CassandraHealthIndicator;
|
||||||
import org.springframework.boot.actuate.health.HealthIndicator;
|
import org.springframework.boot.actuate.cassandra.CassandraReactiveHealthIndicator;
|
||||||
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
|
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
|
||||||
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
|
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
|
||||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||||
import org.springframework.boot.autoconfigure.cassandra.CassandraAutoConfiguration;
|
import org.springframework.boot.autoconfigure.cassandra.CassandraAutoConfiguration;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
|
||||||
import org.springframework.boot.autoconfigure.data.cassandra.CassandraDataAutoConfiguration;
|
import org.springframework.boot.autoconfigure.data.cassandra.CassandraDataAutoConfiguration;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.boot.autoconfigure.data.cassandra.CassandraReactiveDataAutoConfiguration;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.data.cassandra.core.CassandraOperations;
|
import org.springframework.context.annotation.Import;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@link EnableAutoConfiguration Auto-configuration} for
|
* {@link EnableAutoConfiguration Auto-configuration} for {@link CassandraHealthIndicator}
|
||||||
* {@link CassandraHealthIndicator}.
|
* and {@link CassandraReactiveHealthIndicator}.
|
||||||
*
|
*
|
||||||
* @author Julien Dubois
|
* @author Julien Dubois
|
||||||
|
* @author Stephane Nicoll
|
||||||
* @since 2.0.0
|
* @since 2.0.0
|
||||||
*/
|
*/
|
||||||
@Configuration
|
@Configuration
|
||||||
@ConditionalOnClass({ CassandraOperations.class, Cluster.class })
|
@ConditionalOnClass(Cluster.class)
|
||||||
@ConditionalOnBean(CassandraOperations.class)
|
|
||||||
@ConditionalOnEnabledHealthIndicator("cassandra")
|
@ConditionalOnEnabledHealthIndicator("cassandra")
|
||||||
@AutoConfigureBefore(HealthIndicatorAutoConfiguration.class)
|
@AutoConfigureBefore(HealthIndicatorAutoConfiguration.class)
|
||||||
@AutoConfigureAfter({ CassandraAutoConfiguration.class,
|
@AutoConfigureAfter({ CassandraAutoConfiguration.class,
|
||||||
CassandraDataAutoConfiguration.class })
|
CassandraDataAutoConfiguration.class,
|
||||||
public class CassandraHealthIndicatorAutoConfiguration extends
|
CassandraReactiveDataAutoConfiguration.class })
|
||||||
CompositeHealthIndicatorConfiguration<CassandraHealthIndicator, CassandraOperations> {
|
@Import({ CassandraReactiveHealthIndicatorConfiguration.class,
|
||||||
|
CassandraHealthIndicatorConfiguration.class })
|
||||||
private final Map<String, CassandraOperations> cassandraOperations;
|
public class CassandraHealthIndicatorAutoConfiguration {
|
||||||
|
|
||||||
public CassandraHealthIndicatorAutoConfiguration(
|
|
||||||
Map<String, CassandraOperations> cassandraOperations) {
|
|
||||||
this.cassandraOperations = cassandraOperations;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
@ConditionalOnMissingBean(name = "cassandraHealthIndicator")
|
|
||||||
public HealthIndicator cassandraHealthIndicator() {
|
|
||||||
return createHealthIndicator(this.cassandraOperations);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,55 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2012-2018 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.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.springframework.boot.actuate.autoconfigure.cassandra;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.springframework.boot.actuate.autoconfigure.health.CompositeHealthIndicatorConfiguration;
|
||||||
|
import org.springframework.boot.actuate.cassandra.CassandraHealthIndicator;
|
||||||
|
import org.springframework.boot.actuate.health.HealthIndicator;
|
||||||
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
||||||
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||||
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.data.cassandra.core.CassandraOperations;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Configuration for {@link CassandraHealthIndicator}.
|
||||||
|
*
|
||||||
|
* @author Julien Dubois
|
||||||
|
*/
|
||||||
|
@Configuration
|
||||||
|
@ConditionalOnClass(CassandraOperations.class)
|
||||||
|
@ConditionalOnBean(CassandraOperations.class)
|
||||||
|
class CassandraHealthIndicatorConfiguration extends
|
||||||
|
CompositeHealthIndicatorConfiguration<CassandraHealthIndicator, CassandraOperations> {
|
||||||
|
|
||||||
|
private final Map<String, CassandraOperations> cassandraOperations;
|
||||||
|
|
||||||
|
CassandraHealthIndicatorConfiguration(
|
||||||
|
Map<String, CassandraOperations> cassandraOperations) {
|
||||||
|
this.cassandraOperations = cassandraOperations;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
@ConditionalOnMissingBean(name = "cassandraHealthIndicator")
|
||||||
|
public HealthIndicator cassandraHealthIndicator() {
|
||||||
|
return createHealthIndicator(this.cassandraOperations);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2017 the original author or authors.
|
* Copyright 2012-2018 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,45 +15,33 @@
|
||||||
*/
|
*/
|
||||||
package org.springframework.boot.actuate.autoconfigure.cassandra;
|
package org.springframework.boot.actuate.autoconfigure.cassandra;
|
||||||
|
|
||||||
import com.datastax.driver.core.Cluster;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.springframework.boot.actuate.autoconfigure.health.CompositeReactiveHealthIndicatorConfiguration;
|
import org.springframework.boot.actuate.autoconfigure.health.CompositeReactiveHealthIndicatorConfiguration;
|
||||||
import org.springframework.boot.actuate.autoconfigure.health.ConditionalOnEnabledHealthIndicator;
|
|
||||||
import org.springframework.boot.actuate.autoconfigure.health.HealthIndicatorAutoConfiguration;
|
|
||||||
import org.springframework.boot.actuate.cassandra.CassandraReactiveHealthIndicator;
|
import org.springframework.boot.actuate.cassandra.CassandraReactiveHealthIndicator;
|
||||||
import org.springframework.boot.actuate.health.ReactiveHealthIndicator;
|
import org.springframework.boot.actuate.health.ReactiveHealthIndicator;
|
||||||
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
|
|
||||||
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
|
|
||||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
|
||||||
import org.springframework.boot.autoconfigure.cassandra.CassandraAutoConfiguration;
|
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||||
import org.springframework.boot.autoconfigure.data.cassandra.CassandraReactiveDataAutoConfiguration;
|
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.data.cassandra.core.ReactiveCassandraOperations;
|
import org.springframework.data.cassandra.core.ReactiveCassandraOperations;
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@link EnableAutoConfiguration Auto-configuration} for
|
* Configuration for {@link CassandraReactiveHealthIndicator}.
|
||||||
* {@link org.springframework.boot.actuate.cassandra.CassandraReactiveHealthIndicator}.
|
|
||||||
*
|
*
|
||||||
* @author Artsiom Yudovin
|
* @author Artsiom Yudovin
|
||||||
* @since 2.0.0
|
* @author Stephane Nicoll
|
||||||
*/
|
*/
|
||||||
@Configuration
|
@Configuration
|
||||||
@ConditionalOnClass({ReactiveCassandraOperations.class, Cluster.class })
|
@ConditionalOnClass(ReactiveCassandraOperations.class)
|
||||||
@ConditionalOnBean(ReactiveCassandraOperations.class)
|
@ConditionalOnBean(ReactiveCassandraOperations.class)
|
||||||
@ConditionalOnEnabledHealthIndicator("cassandra")
|
class CassandraReactiveHealthIndicatorConfiguration extends
|
||||||
@AutoConfigureBefore(HealthIndicatorAutoConfiguration.class)
|
|
||||||
@AutoConfigureAfter({ CassandraAutoConfiguration.class,
|
|
||||||
CassandraReactiveDataAutoConfiguration.class })
|
|
||||||
public class CassandraReactiveHealthIndicatorAutoConfiguration extends
|
|
||||||
CompositeReactiveHealthIndicatorConfiguration<CassandraReactiveHealthIndicator, ReactiveCassandraOperations> {
|
CompositeReactiveHealthIndicatorConfiguration<CassandraReactiveHealthIndicator, ReactiveCassandraOperations> {
|
||||||
|
|
||||||
private final Map<String, ReactiveCassandraOperations> reactiveCassandraOperations;
|
private final Map<String, ReactiveCassandraOperations> reactiveCassandraOperations;
|
||||||
|
|
||||||
public CassandraReactiveHealthIndicatorAutoConfiguration(
|
CassandraReactiveHealthIndicatorConfiguration(
|
||||||
Map<String, ReactiveCassandraOperations> reactiveCassandraOperations) {
|
Map<String, ReactiveCassandraOperations> reactiveCassandraOperations) {
|
||||||
this.reactiveCassandraOperations = reactiveCassandraOperations;
|
this.reactiveCassandraOperations = reactiveCassandraOperations;
|
||||||
}
|
}
|
||||||
|
@ -63,4 +51,5 @@ public class CassandraReactiveHealthIndicatorAutoConfiguration extends
|
||||||
public ReactiveHealthIndicator cassandraHealthIndicator() {
|
public ReactiveHealthIndicator cassandraHealthIndicator() {
|
||||||
return createHealthIndicator(this.reactiveCassandraOperations);
|
return createHealthIndicator(this.reactiveCassandraOperations);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -5,7 +5,6 @@ org.springframework.boot.actuate.autoconfigure.audit.AuditEventsEndpointAutoConf
|
||||||
org.springframework.boot.actuate.autoconfigure.beans.BeansEndpointAutoConfiguration,\
|
org.springframework.boot.actuate.autoconfigure.beans.BeansEndpointAutoConfiguration,\
|
||||||
org.springframework.boot.actuate.autoconfigure.cache.CachesEndpointAutoConfiguration,\
|
org.springframework.boot.actuate.autoconfigure.cache.CachesEndpointAutoConfiguration,\
|
||||||
org.springframework.boot.actuate.autoconfigure.cassandra.CassandraHealthIndicatorAutoConfiguration,\
|
org.springframework.boot.actuate.autoconfigure.cassandra.CassandraHealthIndicatorAutoConfiguration,\
|
||||||
org.springframework.boot.actuate.autoconfigure.cassandra.CassandraReactiveHealthIndicatorAutoConfiguration,\
|
|
||||||
org.springframework.boot.actuate.autoconfigure.cloudfoundry.servlet.CloudFoundryActuatorAutoConfiguration,\
|
org.springframework.boot.actuate.autoconfigure.cloudfoundry.servlet.CloudFoundryActuatorAutoConfiguration,\
|
||||||
org.springframework.boot.actuate.autoconfigure.cloudfoundry.reactive.ReactiveCloudFoundryActuatorAutoConfiguration,\
|
org.springframework.boot.actuate.autoconfigure.cloudfoundry.reactive.ReactiveCloudFoundryActuatorAutoConfiguration,\
|
||||||
org.springframework.boot.actuate.autoconfigure.condition.ConditionsReportEndpointAutoConfiguration,\
|
org.springframework.boot.actuate.autoconfigure.condition.ConditionsReportEndpointAutoConfiguration,\
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2017 the original author or authors.
|
* Copyright 2012-2018 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.
|
||||||
|
@ -17,12 +17,12 @@
|
||||||
package org.springframework.boot.actuate.autoconfigure.cassandra;
|
package org.springframework.boot.actuate.autoconfigure.cassandra;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import org.springframework.boot.actuate.autoconfigure.health.HealthIndicatorAutoConfiguration;
|
import org.springframework.boot.actuate.autoconfigure.health.HealthIndicatorAutoConfiguration;
|
||||||
import org.springframework.boot.actuate.cassandra.CassandraHealthIndicator;
|
import org.springframework.boot.actuate.cassandra.CassandraHealthIndicator;
|
||||||
import org.springframework.boot.actuate.cassandra.CassandraReactiveHealthIndicator;
|
import org.springframework.boot.actuate.cassandra.CassandraReactiveHealthIndicator;
|
||||||
import org.springframework.boot.actuate.health.ApplicationHealthIndicator;
|
import org.springframework.boot.actuate.health.ApplicationHealthIndicator;
|
||||||
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
||||||
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
|
|
||||||
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
|
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
@ -32,16 +32,17 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests for {@link CassandraReactiveHealthIndicatorAutoConfiguration}.
|
* Tests for {@link CassandraReactiveHealthIndicatorConfiguration}.
|
||||||
*
|
*
|
||||||
* @author Artsiom Yudovin
|
* @author Artsiom Yudovin
|
||||||
|
* @author Stephane Nicoll
|
||||||
*/
|
*/
|
||||||
public class CassandraReactiveHealthIndicatorAutoConfigurationTests {
|
public class CassandraReactiveHealthIndicatorConfigurationTests {
|
||||||
|
|
||||||
private ApplicationContextRunner contextRunner = new ApplicationContextRunner()
|
private ApplicationContextRunner contextRunner = new ApplicationContextRunner()
|
||||||
.withConfiguration(AutoConfigurations.of(CassandraReactiveHealthIndicatorAutoConfigurationTests.CassandraConfiguration.class,
|
.withUserConfiguration(CassandraMockConfiguration.class).withConfiguration(
|
||||||
CassandraReactiveHealthIndicatorAutoConfiguration.class,
|
AutoConfigurations.of(CassandraHealthIndicatorAutoConfiguration.class,
|
||||||
HealthIndicatorAutoConfiguration.class));
|
HealthIndicatorAutoConfiguration.class));
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void runShouldCreateIndicator() {
|
public void runShouldCreateIndicator() {
|
||||||
|
@ -60,8 +61,7 @@ public class CassandraReactiveHealthIndicatorAutoConfigurationTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
@AutoConfigureBefore(CassandraReactiveHealthIndicatorAutoConfiguration.class)
|
protected static class CassandraMockConfiguration {
|
||||||
protected static class CassandraConfiguration {
|
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public ReactiveCassandraOperations cassandraOperations() {
|
public ReactiveCassandraOperations cassandraOperations() {
|
||||||
|
@ -69,4 +69,5 @@ public class CassandraReactiveHealthIndicatorAutoConfigurationTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -17,20 +17,19 @@ package org.springframework.boot.actuate.cassandra;
|
||||||
|
|
||||||
import com.datastax.driver.core.querybuilder.QueryBuilder;
|
import com.datastax.driver.core.querybuilder.QueryBuilder;
|
||||||
import com.datastax.driver.core.querybuilder.Select;
|
import com.datastax.driver.core.querybuilder.Select;
|
||||||
import org.springframework.boot.actuate.health.AbstractReactiveHealthIndicator;
|
|
||||||
import org.springframework.boot.actuate.health.Health;
|
|
||||||
import org.springframework.boot.actuate.health.HealthIndicator;
|
|
||||||
import org.springframework.data.cassandra.ReactiveResultSet;
|
|
||||||
import org.springframework.data.cassandra.core.ReactiveCassandraOperations;
|
|
||||||
import org.springframework.util.Assert;
|
|
||||||
import reactor.core.publisher.Mono;
|
import reactor.core.publisher.Mono;
|
||||||
|
|
||||||
|
import org.springframework.boot.actuate.health.AbstractReactiveHealthIndicator;
|
||||||
|
import org.springframework.boot.actuate.health.Health;
|
||||||
|
import org.springframework.boot.actuate.health.ReactiveHealthIndicator;
|
||||||
|
import org.springframework.data.cassandra.core.ReactiveCassandraOperations;
|
||||||
|
import org.springframework.util.Assert;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Simple implementation of a {@link HealthIndicator} returning status information for
|
* A {@link ReactiveHealthIndicator} for Cassandra.
|
||||||
* Cassandra data stores.
|
|
||||||
*
|
*
|
||||||
* @author Artsiom Yudovin
|
* @author Artsiom Yudovin
|
||||||
* @since 2.0.0
|
* @since 2.1.0
|
||||||
*/
|
*/
|
||||||
public class CassandraReactiveHealthIndicator extends AbstractReactiveHealthIndicator {
|
public class CassandraReactiveHealthIndicator extends AbstractReactiveHealthIndicator {
|
||||||
|
|
||||||
|
@ -40,20 +39,20 @@ public class CassandraReactiveHealthIndicator extends AbstractReactiveHealthIndi
|
||||||
* Create a new {@link CassandraHealthIndicator} instance.
|
* Create a new {@link CassandraHealthIndicator} instance.
|
||||||
* @param reactiveCassandraOperations the Cassandra operations
|
* @param reactiveCassandraOperations the Cassandra operations
|
||||||
*/
|
*/
|
||||||
public CassandraReactiveHealthIndicator(ReactiveCassandraOperations reactiveCassandraOperations) {
|
public CassandraReactiveHealthIndicator(
|
||||||
Assert.notNull(reactiveCassandraOperations, "ReactiveCassandraOperations must not be null");
|
ReactiveCassandraOperations reactiveCassandraOperations) {
|
||||||
|
Assert.notNull(reactiveCassandraOperations,
|
||||||
|
"ReactiveCassandraOperations must not be null");
|
||||||
this.reactiveCassandraOperations = reactiveCassandraOperations;
|
this.reactiveCassandraOperations = reactiveCassandraOperations;
|
||||||
}
|
}
|
||||||
|
|
||||||
@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");
|
Select select = QueryBuilder.select("release_version").from("system", "local");
|
||||||
Mono<String> results = this.reactiveCassandraOperations.getReactiveCqlOperations()
|
return this.reactiveCassandraOperations.getReactiveCqlOperations()
|
||||||
.queryForObject(select, String.class);
|
.queryForObject(select, String.class)
|
||||||
|
.map((version) -> builder.up().withDetail("version", version).build())
|
||||||
return results
|
|
||||||
.map(version -> builder.up().withDetail("version", version).build())
|
|
||||||
.single();
|
.single();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,21 +15,17 @@
|
||||||
*/
|
*/
|
||||||
package org.springframework.boot.actuate.cassandra;
|
package org.springframework.boot.actuate.cassandra;
|
||||||
|
|
||||||
import com.datastax.driver.core.Row;
|
|
||||||
import com.datastax.driver.core.querybuilder.Select;
|
import com.datastax.driver.core.querybuilder.Select;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.springframework.boot.actuate.health.Health;
|
|
||||||
import org.springframework.boot.actuate.health.ReactiveHealthIndicator;
|
|
||||||
import org.springframework.boot.actuate.health.Status;
|
|
||||||
import org.springframework.data.cassandra.CassandraInternalException;
|
|
||||||
import org.springframework.data.cassandra.ReactiveResultSet;
|
|
||||||
import org.springframework.data.cassandra.core.ReactiveCassandraOperations;
|
|
||||||
import org.springframework.data.cassandra.core.cql.ReactiveCqlOperations;
|
|
||||||
import reactor.core.publisher.Flux;
|
|
||||||
import reactor.core.publisher.Mono;
|
import reactor.core.publisher.Mono;
|
||||||
import reactor.test.StepVerifier;
|
import reactor.test.StepVerifier;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.anyOf;
|
import org.springframework.boot.actuate.health.Health;
|
||||||
|
import org.springframework.boot.actuate.health.Status;
|
||||||
|
import org.springframework.data.cassandra.CassandraInternalException;
|
||||||
|
import org.springframework.data.cassandra.core.ReactiveCassandraOperations;
|
||||||
|
import org.springframework.data.cassandra.core.cql.ReactiveCqlOperations;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.mockito.ArgumentMatchers.any;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
import static org.mockito.ArgumentMatchers.eq;
|
import static org.mockito.ArgumentMatchers.eq;
|
||||||
|
@ -37,24 +33,24 @@ import static org.mockito.BDDMockito.given;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A {@link ReactiveHealthIndicator} for Mongo.
|
* Tests for {@link CassandraReactiveHealthIndicatorTests}.
|
||||||
*
|
*
|
||||||
* @author Artsiom Yudovin
|
* @author Artsiom Yudovin
|
||||||
* @since 2.0.0
|
|
||||||
*/
|
*/
|
||||||
public class CassandraReactiveHealthIndicatorTest {
|
public class CassandraReactiveHealthIndicatorTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCassandraIsUp() {
|
public void testCassandraIsUp() {
|
||||||
ReactiveCqlOperations reactiveCqlOperations = mock(ReactiveCqlOperations.class);
|
ReactiveCqlOperations reactiveCqlOperations = mock(ReactiveCqlOperations.class);
|
||||||
ReactiveCassandraOperations reactiveCassandraOperations = mock(ReactiveCassandraOperations.class);
|
|
||||||
|
|
||||||
given(reactiveCqlOperations.queryForObject(any(Select.class), eq(String.class)))
|
given(reactiveCqlOperations.queryForObject(any(Select.class), eq(String.class)))
|
||||||
.willReturn(Mono.just("6.0.0"));
|
.willReturn(Mono.just("6.0.0"));
|
||||||
given(reactiveCassandraOperations.getReactiveCqlOperations()).willReturn(reactiveCqlOperations);
|
ReactiveCassandraOperations reactiveCassandraOperations = mock(
|
||||||
|
ReactiveCassandraOperations.class);
|
||||||
|
given(reactiveCassandraOperations.getReactiveCqlOperations())
|
||||||
|
.willReturn(reactiveCqlOperations);
|
||||||
|
|
||||||
CassandraReactiveHealthIndicator cassandraReactiveHealthIndicator =
|
CassandraReactiveHealthIndicator cassandraReactiveHealthIndicator = new CassandraReactiveHealthIndicator(
|
||||||
new CassandraReactiveHealthIndicator(reactiveCassandraOperations);
|
reactiveCassandraOperations);
|
||||||
Mono<Health> health = cassandraReactiveHealthIndicator.health();
|
Mono<Health> health = cassandraReactiveHealthIndicator.health();
|
||||||
StepVerifier.create(health).consumeNextWith((h) -> {
|
StepVerifier.create(health).consumeNextWith((h) -> {
|
||||||
assertThat(h.getStatus()).isEqualTo(Status.UP);
|
assertThat(h.getStatus()).isEqualTo(Status.UP);
|
||||||
|
@ -65,19 +61,20 @@ public class CassandraReactiveHealthIndicatorTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCassandraIsDown() {
|
public void testCassandraIsDown() {
|
||||||
ReactiveCassandraOperations reactiveCassandraOperations = mock(ReactiveCassandraOperations.class);
|
ReactiveCassandraOperations reactiveCassandraOperations = mock(
|
||||||
|
ReactiveCassandraOperations.class);
|
||||||
given(reactiveCassandraOperations.getReactiveCqlOperations())
|
given(reactiveCassandraOperations.getReactiveCqlOperations())
|
||||||
.willThrow(new CassandraInternalException("Connection failed"));
|
.willThrow(new CassandraInternalException("Connection failed"));
|
||||||
|
|
||||||
CassandraReactiveHealthIndicator cassandraReactiveHealthIndicator =
|
CassandraReactiveHealthIndicator cassandraReactiveHealthIndicator = new CassandraReactiveHealthIndicator(
|
||||||
new CassandraReactiveHealthIndicator(reactiveCassandraOperations);
|
reactiveCassandraOperations);
|
||||||
Mono<Health> health = cassandraReactiveHealthIndicator.health();
|
Mono<Health> health = cassandraReactiveHealthIndicator.health();
|
||||||
StepVerifier.create(health).consumeNextWith((h) -> {
|
StepVerifier.create(health).consumeNextWith((h) -> {
|
||||||
assertThat(h.getStatus()).isEqualTo(Status.DOWN);
|
assertThat(h.getStatus()).isEqualTo(Status.DOWN);
|
||||||
assertThat(h.getDetails()).containsOnlyKeys("error");
|
assertThat(h.getDetails()).containsOnlyKeys("error");
|
||||||
assertThat(h.getDetails().get("error"))
|
assertThat(h.getDetails().get("error")).isEqualTo(
|
||||||
.isEqualTo(CassandraInternalException.class.getName() + ": Connection failed");
|
CassandraInternalException.class.getName() + ": Connection failed");
|
||||||
}).verifyComplete();
|
}).verifyComplete();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -921,6 +921,9 @@ appropriate:
|
||||||
|===
|
|===
|
||||||
|Name |Description
|
|Name |Description
|
||||||
|
|
||||||
|
|{sc-spring-boot-actuator}/cassandra/CassandraReactiveHealthIndicator.{sc-ext}[`CassandraReactiveHealthIndicator`]
|
||||||
|
|Checks that a Cassandra database is up.
|
||||||
|
|
||||||
|{sc-spring-boot-actuator}/mongo/MongoReactiveHealthIndicator.{sc-ext}[`MongoReactiveHealthIndicator`]
|
|{sc-spring-boot-actuator}/mongo/MongoReactiveHealthIndicator.{sc-ext}[`MongoReactiveHealthIndicator`]
|
||||||
|Checks that a Mongo database is up.
|
|Checks that a Mongo database is up.
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue