From 35e069e2cd4b563590ffd5869f78e33324a43961 Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Mon, 15 Jun 2020 11:05:31 +0200 Subject: [PATCH] Polish "Add health indicator for Cassandra that uses the CqlSession" See gh-20887 --- ...verHealthContributorAutoConfiguration.java | 59 ---------- ...iveHealthContributorAutoConfiguration.java | 58 ---------- ...draHealthContributorAutoConfiguration.java | 24 ++--- ...sandraHealthContributorConfigurations.java | 101 ++++++++++++++++++ ...iveHealthContributorAutoConfiguration.java | 25 ++--- .../main/resources/META-INF/spring.factories | 2 - ...althContributorAutoConfigurationTests.java | 89 --------------- ...althContributorAutoConfigurationTests.java | 79 -------------- ...althContributorAutoConfigurationTests.java | 53 +++++---- ...althContributorAutoConfigurationTests.java | 58 +++++++--- .../CassandraDriverHealthIndicator.java | 3 - ...assandraDriverReactiveHealthIndicator.java | 3 - ...draDriverReactiveHealthIndicatorTests.java | 2 - .../asciidoc/production-ready-features.adoc | 4 +- 14 files changed, 192 insertions(+), 368 deletions(-) delete mode 100644 spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/cassandra/CassandraDriverHealthContributorAutoConfiguration.java delete mode 100644 spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/cassandra/CassandraDriverReactiveHealthContributorAutoConfiguration.java create mode 100644 spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/cassandra/CassandraHealthContributorConfigurations.java delete mode 100644 spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/cassandra/CassandraDriverHealthContributorAutoConfigurationTests.java delete mode 100644 spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/cassandra/CassandraDriverReactiveHealthContributorAutoConfigurationTests.java diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/cassandra/CassandraDriverHealthContributorAutoConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/cassandra/CassandraDriverHealthContributorAutoConfiguration.java deleted file mode 100644 index 75fda9deb7..0000000000 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/cassandra/CassandraDriverHealthContributorAutoConfiguration.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * 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. - * You may obtain a copy of the License at - * - * https://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 com.datastax.oss.driver.api.core.CqlSession; - -import org.springframework.boot.actuate.autoconfigure.health.CompositeHealthContributorConfiguration; -import org.springframework.boot.actuate.autoconfigure.health.ConditionalOnEnabledHealthIndicator; -import org.springframework.boot.actuate.cassandra.CassandraDriverHealthIndicator; -import org.springframework.boot.actuate.health.HealthContributor; -import org.springframework.boot.autoconfigure.AutoConfigureAfter; -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.ConditionalOnClass; -import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -/** - * {@link EnableAutoConfiguration Auto-configuration} for - * {@link CassandraDriverHealthIndicator}. - * - * @author Alexandre Dutra - * @since 2.4.0 - */ -@Configuration(proxyBeanMethods = false) -@ConditionalOnClass(CqlSession.class) -@ConditionalOnBean(CqlSession.class) -@ConditionalOnEnabledHealthIndicator("cassandra") -@AutoConfigureAfter({ CassandraAutoConfiguration.class, CassandraReactiveHealthContributorAutoConfiguration.class, - CassandraHealthContributorAutoConfiguration.class, - CassandraDriverReactiveHealthContributorAutoConfiguration.class }) -public class CassandraDriverHealthContributorAutoConfiguration - extends CompositeHealthContributorConfiguration { - - @Bean - @ConditionalOnMissingBean(name = { "cassandraHealthIndicator", "cassandraHealthContributor" }) - public HealthContributor cassandraHealthContributor(Map sessions) { - return createContributor(sessions); - } - -} diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/cassandra/CassandraDriverReactiveHealthContributorAutoConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/cassandra/CassandraDriverReactiveHealthContributorAutoConfiguration.java deleted file mode 100644 index 78964eefe9..0000000000 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/cassandra/CassandraDriverReactiveHealthContributorAutoConfiguration.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * 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. - * You may obtain a copy of the License at - * - * https://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 com.datastax.oss.driver.api.core.CqlSession; -import reactor.core.publisher.Flux; - -import org.springframework.boot.actuate.autoconfigure.health.CompositeReactiveHealthContributorConfiguration; -import org.springframework.boot.actuate.autoconfigure.health.ConditionalOnEnabledHealthIndicator; -import org.springframework.boot.actuate.cassandra.CassandraDriverReactiveHealthIndicator; -import org.springframework.boot.actuate.health.ReactiveHealthContributor; -import org.springframework.boot.autoconfigure.AutoConfigureAfter; -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.ConditionalOnClass; -import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -/** - * {@link EnableAutoConfiguration Auto-configuration} for - * {@link CassandraDriverReactiveHealthIndicator}. - * - * @author Alexandre Dutra - * @since 2.4.0 - */ -@Configuration(proxyBeanMethods = false) -@ConditionalOnClass({ CqlSession.class, Flux.class }) -@ConditionalOnBean(CqlSession.class) -@ConditionalOnEnabledHealthIndicator("cassandra") -@AutoConfigureAfter({ CassandraAutoConfiguration.class, CassandraReactiveHealthContributorAutoConfiguration.class, - CassandraHealthContributorAutoConfiguration.class }) -public class CassandraDriverReactiveHealthContributorAutoConfiguration - extends CompositeReactiveHealthContributorConfiguration { - - @Bean - @ConditionalOnMissingBean(name = { "cassandraHealthIndicator", "cassandraHealthContributor" }) - public ReactiveHealthContributor cassandraHealthContributor(Map sessions) { - return createContributor(sessions); - } - -} diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/cassandra/CassandraHealthContributorAutoConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/cassandra/CassandraHealthContributorAutoConfiguration.java index 0a10ca472c..c15a049c18 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/cassandra/CassandraHealthContributorAutoConfiguration.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/cassandra/CassandraHealthContributorAutoConfiguration.java @@ -16,24 +16,19 @@ package org.springframework.boot.actuate.autoconfigure.cassandra; -import java.util.Map; - import com.datastax.oss.driver.api.core.CqlSession; -import org.springframework.boot.actuate.autoconfigure.health.CompositeHealthContributorConfiguration; +import org.springframework.boot.actuate.autoconfigure.cassandra.CassandraHealthContributorConfigurations.CassandraDriverConfiguration; +import org.springframework.boot.actuate.autoconfigure.cassandra.CassandraHealthContributorConfigurations.CassandraOperationsConfiguration; import org.springframework.boot.actuate.autoconfigure.health.ConditionalOnEnabledHealthIndicator; import org.springframework.boot.actuate.cassandra.CassandraHealthIndicator; -import org.springframework.boot.actuate.health.HealthContributor; import org.springframework.boot.autoconfigure.AutoConfigureAfter; 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.ConditionalOnClass; -import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.data.cassandra.CassandraDataAutoConfiguration; -import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import org.springframework.data.cassandra.core.CassandraOperations; +import org.springframework.context.annotation.Import; /** * {@link EnableAutoConfiguration Auto-configuration} for @@ -44,18 +39,11 @@ import org.springframework.data.cassandra.core.CassandraOperations; * @since 2.1.0 */ @Configuration(proxyBeanMethods = false) -@ConditionalOnClass({ CqlSession.class, CassandraOperations.class }) -@ConditionalOnBean(CassandraOperations.class) +@ConditionalOnClass(CqlSession.class) @ConditionalOnEnabledHealthIndicator("cassandra") @AutoConfigureAfter({ CassandraAutoConfiguration.class, CassandraDataAutoConfiguration.class, CassandraReactiveHealthContributorAutoConfiguration.class }) -public class CassandraHealthContributorAutoConfiguration - extends CompositeHealthContributorConfiguration { - - @Bean - @ConditionalOnMissingBean(name = { "cassandraHealthIndicator", "cassandraHealthContributor" }) - public HealthContributor cassandraHealthContributor(Map cassandraOperations) { - return createContributor(cassandraOperations); - } +@Import({ CassandraOperationsConfiguration.class, CassandraDriverConfiguration.class }) +public class CassandraHealthContributorAutoConfiguration { } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/cassandra/CassandraHealthContributorConfigurations.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/cassandra/CassandraHealthContributorConfigurations.java new file mode 100644 index 0000000000..a618380a4f --- /dev/null +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/cassandra/CassandraHealthContributorConfigurations.java @@ -0,0 +1,101 @@ +/* + * 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. + * You may obtain a copy of the License at + * + * https://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 com.datastax.oss.driver.api.core.CqlSession; + +import org.springframework.boot.actuate.autoconfigure.health.CompositeHealthContributorConfiguration; +import org.springframework.boot.actuate.autoconfigure.health.CompositeReactiveHealthContributorConfiguration; +import org.springframework.boot.actuate.cassandra.CassandraDriverHealthIndicator; +import org.springframework.boot.actuate.cassandra.CassandraDriverReactiveHealthIndicator; +import org.springframework.boot.actuate.cassandra.CassandraHealthIndicator; +import org.springframework.boot.actuate.cassandra.CassandraReactiveHealthIndicator; +import org.springframework.boot.actuate.health.HealthContributor; +import org.springframework.boot.actuate.health.ReactiveHealthContributor; +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; +import org.springframework.data.cassandra.core.ReactiveCassandraOperations; + +/** + * Health contributor options for Cassandra. + * + * @author Stephane Nicoll + */ +class CassandraHealthContributorConfigurations { + + @Configuration(proxyBeanMethods = false) + @ConditionalOnBean(CqlSession.class) + static class CassandraDriverConfiguration + extends CompositeHealthContributorConfiguration { + + @Bean + @ConditionalOnMissingBean(name = { "cassandraHealthIndicator", "cassandraHealthContributor" }) + HealthContributor cassandraHealthContributor(Map sessions) { + return createContributor(sessions); + } + + } + + @Configuration(proxyBeanMethods = false) + @ConditionalOnClass(CassandraOperations.class) + @ConditionalOnBean(CassandraOperations.class) + static class CassandraOperationsConfiguration + extends CompositeHealthContributorConfiguration { + + @Bean + @ConditionalOnMissingBean(name = { "cassandraHealthIndicator", "cassandraHealthContributor" }) + HealthContributor cassandraHealthContributor(Map cassandraOperations) { + return createContributor(cassandraOperations); + } + + } + + @Configuration(proxyBeanMethods = false) + @ConditionalOnBean(CqlSession.class) + static class CassandraReactiveDriverConfiguration extends + CompositeReactiveHealthContributorConfiguration { + + @Bean + @ConditionalOnMissingBean(name = { "cassandraHealthIndicator", "cassandraHealthContributor" }) + ReactiveHealthContributor cassandraHealthContributor(Map sessions) { + return createContributor(sessions); + } + + } + + @Configuration(proxyBeanMethods = false) + @ConditionalOnClass(ReactiveCassandraOperations.class) + @ConditionalOnBean(ReactiveCassandraOperations.class) + static class CassandraReactiveOperationsConfiguration extends + CompositeReactiveHealthContributorConfiguration { + + @Bean + @ConditionalOnMissingBean(name = { "cassandraHealthIndicator", "cassandraHealthContributor" }) + ReactiveHealthContributor cassandraHealthContributor( + Map reactiveCassandraOperations) { + return createContributor(reactiveCassandraOperations); + } + + } + +} diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/cassandra/CassandraReactiveHealthContributorAutoConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/cassandra/CassandraReactiveHealthContributorAutoConfiguration.java index fbe71367b8..b6fbfdd7c8 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/cassandra/CassandraReactiveHealthContributorAutoConfiguration.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/cassandra/CassandraReactiveHealthContributorAutoConfiguration.java @@ -15,24 +15,19 @@ */ package org.springframework.boot.actuate.autoconfigure.cassandra; -import java.util.Map; - import com.datastax.oss.driver.api.core.CqlSession; import reactor.core.publisher.Flux; -import org.springframework.boot.actuate.autoconfigure.health.CompositeReactiveHealthContributorConfiguration; +import org.springframework.boot.actuate.autoconfigure.cassandra.CassandraHealthContributorConfigurations.CassandraReactiveDriverConfiguration; +import org.springframework.boot.actuate.autoconfigure.cassandra.CassandraHealthContributorConfigurations.CassandraReactiveOperationsConfiguration; import org.springframework.boot.actuate.autoconfigure.health.ConditionalOnEnabledHealthIndicator; import org.springframework.boot.actuate.cassandra.CassandraReactiveHealthIndicator; -import org.springframework.boot.actuate.health.ReactiveHealthContributor; import org.springframework.boot.autoconfigure.AutoConfigureAfter; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; -import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; -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.Configuration; -import org.springframework.data.cassandra.core.ReactiveCassandraOperations; +import org.springframework.context.annotation.Import; /** * {@link EnableAutoConfiguration Auto-configuration} for @@ -43,18 +38,10 @@ import org.springframework.data.cassandra.core.ReactiveCassandraOperations; * @since 2.1.0 */ @Configuration(proxyBeanMethods = false) -@ConditionalOnClass({ CqlSession.class, ReactiveCassandraOperations.class, Flux.class }) -@ConditionalOnBean(ReactiveCassandraOperations.class) +@ConditionalOnClass({ CqlSession.class, Flux.class }) @ConditionalOnEnabledHealthIndicator("cassandra") @AutoConfigureAfter(CassandraReactiveDataAutoConfiguration.class) -public class CassandraReactiveHealthContributorAutoConfiguration extends - CompositeReactiveHealthContributorConfiguration { - - @Bean - @ConditionalOnMissingBean(name = { "cassandraHealthIndicator", "cassandraHealthContributor" }) - public ReactiveHealthContributor cassandraHealthContributor( - Map reactiveCassandraOperations) { - return createContributor(reactiveCassandraOperations); - } +@Import({ CassandraReactiveOperationsConfiguration.class, CassandraReactiveDriverConfiguration.class }) +public class CassandraReactiveHealthContributorAutoConfiguration { } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/resources/META-INF/spring.factories b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/resources/META-INF/spring.factories index c1e5089193..e297520518 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/resources/META-INF/spring.factories +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/resources/META-INF/spring.factories @@ -7,8 +7,6 @@ org.springframework.boot.actuate.autoconfigure.beans.BeansEndpointAutoConfigurat org.springframework.boot.actuate.autoconfigure.cache.CachesEndpointAutoConfiguration,\ org.springframework.boot.actuate.autoconfigure.cassandra.CassandraHealthContributorAutoConfiguration,\ org.springframework.boot.actuate.autoconfigure.cassandra.CassandraReactiveHealthContributorAutoConfiguration,\ -org.springframework.boot.actuate.autoconfigure.cassandra.CassandraDriverHealthContributorAutoConfiguration,\ -org.springframework.boot.actuate.autoconfigure.cassandra.CassandraDriverReactiveHealthContributorAutoConfiguration,\ org.springframework.boot.actuate.autoconfigure.cloudfoundry.servlet.CloudFoundryActuatorAutoConfiguration,\ org.springframework.boot.actuate.autoconfigure.cloudfoundry.reactive.ReactiveCloudFoundryActuatorAutoConfiguration,\ org.springframework.boot.actuate.autoconfigure.condition.ConditionsReportEndpointAutoConfiguration,\ diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/cassandra/CassandraDriverHealthContributorAutoConfigurationTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/cassandra/CassandraDriverHealthContributorAutoConfigurationTests.java deleted file mode 100644 index 5bdb934880..0000000000 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/cassandra/CassandraDriverHealthContributorAutoConfigurationTests.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright 2012-2019 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 - * - * https://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 com.datastax.oss.driver.api.core.CqlSession; -import org.junit.jupiter.api.Test; - -import org.springframework.boot.actuate.autoconfigure.health.HealthContributorAutoConfiguration; -import org.springframework.boot.actuate.cassandra.CassandraDriverHealthIndicator; -import org.springframework.boot.actuate.cassandra.CassandraDriverReactiveHealthIndicator; -import org.springframework.boot.actuate.cassandra.CassandraHealthIndicator; -import org.springframework.boot.actuate.cassandra.CassandraReactiveHealthIndicator; -import org.springframework.boot.autoconfigure.AutoConfigurations; -import org.springframework.boot.test.context.runner.ApplicationContextRunner; -import org.springframework.data.cassandra.core.CassandraOperations; -import org.springframework.data.cassandra.core.ReactiveCassandraOperations; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.mock; - -/** - * Tests for {@link CassandraDriverHealthContributorAutoConfiguration}. - * - * @author Alexandre Dutra - * @since 2.4.0 - */ -class CassandraDriverHealthContributorAutoConfigurationTests { - - private ApplicationContextRunner contextRunner = new ApplicationContextRunner() - .withBean(CqlSession.class, () -> mock(CqlSession.class)).withConfiguration(AutoConfigurations.of( - CassandraDriverHealthContributorAutoConfiguration.class, HealthContributorAutoConfiguration.class)); - - @Test - void runShouldCreateDriverIndicator() { - this.contextRunner.run((context) -> assertThat(context).hasSingleBean(CassandraDriverHealthIndicator.class) - .hasBean("cassandraHealthContributor").doesNotHaveBean(CassandraHealthIndicator.class) - .doesNotHaveBean(CassandraReactiveHealthIndicator.class) - .doesNotHaveBean(CassandraDriverReactiveHealthIndicator.class)); - } - - @Test - void runWhenDisabledShouldNotCreateDriverIndicator() { - this.contextRunner.withPropertyValues("management.health.cassandra.enabled:false") - .run((context) -> assertThat(context).doesNotHaveBean(CassandraDriverHealthIndicator.class) - .doesNotHaveBean("cassandraHealthContributor")); - } - - @Test - void runWhenSpringDataPresentShouldNotCreateDriverIndicator() { - this.contextRunner.withConfiguration(AutoConfigurations.of(CassandraHealthContributorAutoConfiguration.class)) - .withBean(CassandraOperations.class, () -> mock(CassandraOperations.class)) - .run((context) -> assertThat(context).doesNotHaveBean(CassandraDriverHealthIndicator.class) - .hasSingleBean(CassandraHealthIndicator.class).hasBean("cassandraHealthContributor")); - } - - @Test - void runWhenReactorPresentShouldNotCreateDriverIndicator() { - this.contextRunner - .withConfiguration( - AutoConfigurations.of(CassandraDriverReactiveHealthContributorAutoConfiguration.class)) - .run((context) -> assertThat(context).doesNotHaveBean(CassandraDriverHealthIndicator.class) - .hasSingleBean(CassandraDriverReactiveHealthIndicator.class) - .hasBean("cassandraHealthContributor")); - } - - @Test - void runWhenSpringDataAndReactorPresentShouldNotCreateDriverIndicator() { - this.contextRunner - .withConfiguration(AutoConfigurations.of(CassandraReactiveHealthContributorAutoConfiguration.class)) - .withBean(ReactiveCassandraOperations.class, () -> mock(ReactiveCassandraOperations.class)) - .run((context) -> assertThat(context).doesNotHaveBean(CassandraDriverHealthIndicator.class) - .hasSingleBean(CassandraReactiveHealthIndicator.class).hasBean("cassandraHealthContributor")); - } - -} diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/cassandra/CassandraDriverReactiveHealthContributorAutoConfigurationTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/cassandra/CassandraDriverReactiveHealthContributorAutoConfigurationTests.java deleted file mode 100644 index bf2d8edb36..0000000000 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/cassandra/CassandraDriverReactiveHealthContributorAutoConfigurationTests.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright 2012-2019 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 - * - * https://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 com.datastax.oss.driver.api.core.CqlSession; -import org.junit.jupiter.api.Test; - -import org.springframework.boot.actuate.autoconfigure.health.HealthContributorAutoConfiguration; -import org.springframework.boot.actuate.cassandra.CassandraDriverReactiveHealthIndicator; -import org.springframework.boot.actuate.cassandra.CassandraHealthIndicator; -import org.springframework.boot.actuate.cassandra.CassandraReactiveHealthIndicator; -import org.springframework.boot.autoconfigure.AutoConfigurations; -import org.springframework.boot.test.context.runner.ApplicationContextRunner; -import org.springframework.data.cassandra.core.CassandraOperations; -import org.springframework.data.cassandra.core.ReactiveCassandraOperations; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.mock; - -/** - * Tests for {@link CassandraDriverReactiveHealthContributorAutoConfiguration}. - * - * @author Alexandre Dutra - * @since 2.4.0 - */ -class CassandraDriverReactiveHealthContributorAutoConfigurationTests { - - private ApplicationContextRunner contextRunner = new ApplicationContextRunner() - .withBean(CqlSession.class, () -> mock(CqlSession.class)) - .withConfiguration(AutoConfigurations.of(CassandraDriverReactiveHealthContributorAutoConfiguration.class, - HealthContributorAutoConfiguration.class)); - - @Test - void runShouldCreateDriverReactiveIndicator() { - this.contextRunner - .run((context) -> assertThat(context).hasSingleBean(CassandraDriverReactiveHealthIndicator.class) - .hasBean("cassandraHealthContributor").doesNotHaveBean(CassandraHealthIndicator.class) - .doesNotHaveBean(CassandraReactiveHealthIndicator.class)); - } - - @Test - void runWhenDisabledShouldNotCreateDriverReactiveIndicator() { - this.contextRunner.withPropertyValues("management.health.cassandra.enabled:false") - .run((context) -> assertThat(context).doesNotHaveBean(CassandraDriverReactiveHealthIndicator.class) - .doesNotHaveBean("cassandraHealthContributor")); - } - - @Test - void runWhenSpringDataPresentShouldNotCreateDriverReactiveIndicator() { - this.contextRunner.withConfiguration(AutoConfigurations.of(CassandraHealthContributorAutoConfiguration.class)) - .withBean(CassandraOperations.class, () -> mock(CassandraOperations.class)) - .run((context) -> assertThat(context).doesNotHaveBean(CassandraDriverReactiveHealthIndicator.class) - .hasSingleBean(CassandraHealthIndicator.class).hasBean("cassandraHealthContributor")); - } - - @Test - void runWhenSpringDataAndReactorPresentShouldNotCreateDriverReactiveIndicator() { - this.contextRunner - .withConfiguration(AutoConfigurations.of(CassandraReactiveHealthContributorAutoConfiguration.class)) - .withBean(ReactiveCassandraOperations.class, () -> mock(ReactiveCassandraOperations.class)) - .run((context) -> assertThat(context).doesNotHaveBean(CassandraDriverReactiveHealthIndicator.class) - .hasSingleBean(CassandraReactiveHealthIndicator.class).hasBean("cassandraHealthContributor")); - } - -} diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/cassandra/CassandraHealthContributorAutoConfigurationTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/cassandra/CassandraHealthContributorAutoConfigurationTests.java index 65baa9377b..3b96f1a201 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/cassandra/CassandraHealthContributorAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/cassandra/CassandraHealthContributorAutoConfigurationTests.java @@ -16,15 +16,15 @@ package org.springframework.boot.actuate.autoconfigure.cassandra; +import com.datastax.oss.driver.api.core.CqlSession; import org.junit.jupiter.api.Test; import org.springframework.boot.actuate.autoconfigure.health.HealthContributorAutoConfiguration; +import org.springframework.boot.actuate.cassandra.CassandraDriverHealthIndicator; import org.springframework.boot.actuate.cassandra.CassandraHealthIndicator; import org.springframework.boot.autoconfigure.AutoConfigurations; -import org.springframework.boot.autoconfigure.AutoConfigureBefore; +import org.springframework.boot.test.context.FilteredClassLoader; import org.springframework.boot.test.context.runner.ApplicationContextRunner; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; import org.springframework.data.cassandra.core.CassandraOperations; import static org.assertj.core.api.Assertions.assertThat; @@ -34,33 +34,50 @@ import static org.mockito.Mockito.mock; * Tests for {@link CassandraHealthContributorAutoConfiguration}. * * @author Phillip Webb + * @author Stephane Nicoll */ class CassandraHealthContributorAutoConfigurationTests { - private ApplicationContextRunner contextRunner = new ApplicationContextRunner() - .withConfiguration(AutoConfigurations.of(CassandraConfiguration.class, - CassandraHealthContributorAutoConfiguration.class, HealthContributorAutoConfiguration.class)); + private final ApplicationContextRunner contextRunner = new ApplicationContextRunner() + .withConfiguration(AutoConfigurations.of(CassandraHealthContributorAutoConfiguration.class, + HealthContributorAutoConfiguration.class)); @Test - void runShouldCreateIndicator() { - this.contextRunner.run((context) -> assertThat(context).hasSingleBean(CassandraHealthIndicator.class)); + void runWithoutCqlSessionOrCassandraOperationsShouldNotCreateIndicator() { + this.contextRunner.run((context) -> assertThat(context).doesNotHaveBean("cassandraHealthContributor") + .doesNotHaveBean(CassandraHealthIndicator.class).doesNotHaveBean(CassandraDriverHealthIndicator.class)); } @Test - void runWhenDisabledShouldNotCreateIndicator() { - this.contextRunner.withPropertyValues("management.health.cassandra.enabled:false") - .run((context) -> assertThat(context).doesNotHaveBean(CassandraHealthIndicator.class)); + void runWithCassandraOperationsShouldCreateRegularIndicator() { + this.contextRunner.withBean(CqlSession.class, () -> mock(CqlSession.class)) + .withBean(CassandraOperations.class, () -> mock(CassandraOperations.class)) + .run((context) -> assertThat(context).hasSingleBean(CassandraHealthIndicator.class) + .doesNotHaveBean(CassandraDriverHealthIndicator.class)); } - @Configuration(proxyBeanMethods = false) - @AutoConfigureBefore(CassandraHealthContributorAutoConfiguration.class) - static class CassandraConfiguration { + @Test + void runWithCqlSessionOnlyShouldCreateDriverIndicator() { + this.contextRunner.withBean(CqlSession.class, () -> mock(CqlSession.class)).run((context) -> assertThat(context) + .hasSingleBean(CassandraDriverHealthIndicator.class).doesNotHaveBean(CassandraHealthIndicator.class)); + } - @Bean - CassandraOperations cassandraOperations() { - return mock(CassandraOperations.class); - } + @Test + void runWithCqlSessionAndSpringDataAbsentShouldCreateDriverIndicator() { + this.contextRunner.withBean(CqlSession.class, () -> mock(CqlSession.class)) + .withClassLoader(new FilteredClassLoader("org.springframework.data")) + .run((context) -> assertThat(context).hasSingleBean(CassandraDriverHealthIndicator.class) + .doesNotHaveBean(CassandraHealthIndicator.class)); + } + @Test + void runWhenDisabledShouldNotCreateIndicator() { + this.contextRunner.withBean(CqlSession.class, () -> mock(CqlSession.class)) + .withBean(CassandraOperations.class, () -> mock(CassandraOperations.class)) + .withPropertyValues("management.health.cassandra.enabled:false") + .run((context) -> assertThat(context).doesNotHaveBean("cassandraHealthContributor") + .doesNotHaveBean(CassandraHealthIndicator.class) + .doesNotHaveBean(CassandraDriverHealthIndicator.class)); } } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/cassandra/CassandraReactiveHealthContributorAutoConfigurationTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/cassandra/CassandraReactiveHealthContributorAutoConfigurationTests.java index 94d5495135..2b28ae8706 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/cassandra/CassandraReactiveHealthContributorAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/cassandra/CassandraReactiveHealthContributorAutoConfigurationTests.java @@ -16,14 +16,18 @@ package org.springframework.boot.actuate.autoconfigure.cassandra; +import com.datastax.oss.driver.api.core.CqlSession; import org.junit.jupiter.api.Test; -import org.springframework.boot.actuate.autoconfigure.cassandra.CassandraHealthContributorAutoConfigurationTests.CassandraConfiguration; import org.springframework.boot.actuate.autoconfigure.health.HealthContributorAutoConfiguration; +import org.springframework.boot.actuate.cassandra.CassandraDriverHealthIndicator; +import org.springframework.boot.actuate.cassandra.CassandraDriverReactiveHealthIndicator; import org.springframework.boot.actuate.cassandra.CassandraHealthIndicator; import org.springframework.boot.actuate.cassandra.CassandraReactiveHealthIndicator; import org.springframework.boot.autoconfigure.AutoConfigurations; +import org.springframework.boot.test.context.FilteredClassLoader; import org.springframework.boot.test.context.runner.ApplicationContextRunner; +import org.springframework.data.cassandra.core.CassandraOperations; import org.springframework.data.cassandra.core.ReactiveCassandraOperations; import static org.assertj.core.api.Assertions.assertThat; @@ -37,31 +41,53 @@ import static org.mockito.Mockito.mock; */ class CassandraReactiveHealthContributorAutoConfigurationTests { - private ApplicationContextRunner contextRunner = new ApplicationContextRunner() - .withBean(ReactiveCassandraOperations.class, () -> mock(ReactiveCassandraOperations.class)) + private final ApplicationContextRunner contextRunner = new ApplicationContextRunner() .withConfiguration(AutoConfigurations.of(CassandraReactiveHealthContributorAutoConfiguration.class, - HealthContributorAutoConfiguration.class)); + CassandraHealthContributorAutoConfiguration.class, HealthContributorAutoConfiguration.class)); @Test - void runShouldCreateIndicator() { - this.contextRunner.run((context) -> assertThat(context).hasSingleBean(CassandraReactiveHealthIndicator.class) - .hasBean("cassandraHealthContributor")); + void runWithoutCqlSessionOrReactiveCassandraOperationsShouldNotCreateIndicator() { + this.contextRunner.run((context) -> assertThat(context).doesNotHaveBean("cassandraHealthContributor") + .doesNotHaveBean(CassandraReactiveHealthIndicator.class) + .doesNotHaveBean(CassandraDriverReactiveHealthIndicator.class)); } @Test - void runWithRegularIndicatorShouldOnlyCreateReactiveIndicator() { - this.contextRunner - .withConfiguration(AutoConfigurations.of(CassandraConfiguration.class, - CassandraHealthContributorAutoConfiguration.class)) - .run((context) -> assertThat(context).hasSingleBean(CassandraReactiveHealthIndicator.class) - .hasBean("cassandraHealthContributor").doesNotHaveBean(CassandraHealthIndicator.class)); + void runWithReactiveCassandraOperationsShouldOnlyCreateReactiveIndicator() { + this.contextRunner.withBean(CqlSession.class, () -> mock(CqlSession.class)) + .withBean(ReactiveCassandraOperations.class, () -> mock(ReactiveCassandraOperations.class)) + .withBean(CassandraOperations.class, () -> mock(CassandraOperations.class)) + .run((context) -> assertThat(context).hasBean("cassandraHealthContributor") + .hasSingleBean(CassandraReactiveHealthIndicator.class) + .doesNotHaveBean(CassandraDriverReactiveHealthIndicator.class) + .doesNotHaveBean(CassandraHealthIndicator.class) + .doesNotHaveBean(CassandraDriverHealthIndicator.class)); + } + + @Test + void runWithCqlSessionShouldCreateDriverIndicator() { + this.contextRunner.withBean(CqlSession.class, () -> mock(CqlSession.class)) + .run((context) -> assertThat(context).hasBean("cassandraHealthContributor") + .hasSingleBean(CassandraDriverReactiveHealthIndicator.class) + .doesNotHaveBean(CassandraReactiveHealthIndicator.class)); + } + + @Test + void runWithCqlSessionAndSpringDataAbsentShouldACreateDriverIndicator() { + this.contextRunner.withBean(CqlSession.class, () -> mock(CqlSession.class)) + .withClassLoader(new FilteredClassLoader("org.springframework.data")) + .run((context) -> assertThat(context).hasBean("cassandraHealthContributor") + .hasSingleBean(CassandraDriverReactiveHealthIndicator.class) + .doesNotHaveBean(CassandraReactiveHealthIndicator.class)); } @Test void runWhenDisabledShouldNotCreateIndicator() { - this.contextRunner.withPropertyValues("management.health.cassandra.enabled:false") - .run((context) -> assertThat(context).doesNotHaveBean(CassandraReactiveHealthIndicator.class) - .doesNotHaveBean("cassandraHealthContributor")); + this.contextRunner.withBean(CqlSession.class, () -> mock(CqlSession.class)) + .withBean(ReactiveCassandraOperations.class, () -> mock(ReactiveCassandraOperations.class)) + .withPropertyValues("management.health.cassandra.enabled:false") + .run((context) -> assertThat(context).doesNotHaveBean("cassandraHealthContributor") + .doesNotHaveBean(CassandraReactiveHealthIndicator.class)); } } diff --git a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/cassandra/CassandraDriverHealthIndicator.java b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/cassandra/CassandraDriverHealthIndicator.java index 75f262d51f..bbb1468c0e 100644 --- a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/cassandra/CassandraDriverHealthIndicator.java +++ b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/cassandra/CassandraDriverHealthIndicator.java @@ -30,9 +30,6 @@ import org.springframework.util.Assert; * Simple implementation of a {@link HealthIndicator} returning status information for * Cassandra data stores. * - * This health indicator is automatically used when Spring Data Cassandra is not present, - * but the Cassandra driver is. - * * @author Alexandre Dutra * @since 2.4.0 */ diff --git a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/cassandra/CassandraDriverReactiveHealthIndicator.java b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/cassandra/CassandraDriverReactiveHealthIndicator.java index 04533afdc1..40483ca04e 100644 --- a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/cassandra/CassandraDriverReactiveHealthIndicator.java +++ b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/cassandra/CassandraDriverReactiveHealthIndicator.java @@ -29,9 +29,6 @@ import org.springframework.util.Assert; * Simple implementation of a {@link ReactiveHealthIndicator} returning status information * for Cassandra data stores. * - * This health indicator is automatically used when Spring Data Cassandra is not present, - * but the Cassandra driver is. - * * @author Alexandre Dutra * @since 2.4.0 */ diff --git a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/cassandra/CassandraDriverReactiveHealthIndicatorTests.java b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/cassandra/CassandraDriverReactiveHealthIndicatorTests.java index a6c1537091..6cf98f77ec 100644 --- a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/cassandra/CassandraDriverReactiveHealthIndicatorTests.java +++ b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/cassandra/CassandraDriverReactiveHealthIndicatorTests.java @@ -58,7 +58,6 @@ class CassandraDriverReactiveHealthIndicatorTests { given(session.executeReactive(any(SimpleStatement.class))).willReturn(results); doAnswer(mockReactiveResultSetBehavior(row)).when(results).subscribe(any()); given(row.getString(0)).willReturn("6.0.0"); - CassandraDriverReactiveHealthIndicator cassandraReactiveHealthIndicator = new CassandraDriverReactiveHealthIndicator( session); Mono health = cassandraReactiveHealthIndicator.health(); @@ -74,7 +73,6 @@ class CassandraDriverReactiveHealthIndicatorTests { CqlSession session = mock(CqlSession.class); given(session.executeReactive(any(SimpleStatement.class))) .willThrow(new DriverTimeoutException("Test Exception")); - CassandraDriverReactiveHealthIndicator cassandraReactiveHealthIndicator = new CassandraDriverReactiveHealthIndicator( session); Mono health = cassandraReactiveHealthIndicator.health(); diff --git a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/production-ready-features.adoc b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/production-ready-features.adoc index a7488c79dd..446a5eb5ba 100644 --- a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/production-ready-features.adoc +++ b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/production-ready-features.adoc @@ -655,7 +655,7 @@ The following `HealthIndicators` are auto-configured by Spring Boot when appropr |=== | Name | Description -| {spring-boot-actuator-module-code}/cassandra/CassandraHealthIndicator.java[`CassandraHealthIndicator`] +| {spring-boot-actuator-module-code}/cassandra/CassandraHealthIndicator.java[`CassandraHealthIndicator`] or {spring-boot-actuator-module-code}/cassandra/CassandraDriverHealthIndicator.java[`CassandraDriverHealthIndicator`] | Checks that a Cassandra database is up. | {spring-boot-actuator-module-code}/couchbase/CouchbaseHealthIndicator.java[`CouchbaseHealthIndicator`] @@ -830,7 +830,7 @@ The following `ReactiveHealthIndicators` are auto-configured by Spring Boot when |=== | Name | Description -| {spring-boot-actuator-module-code}/cassandra/CassandraReactiveHealthIndicator.java[`CassandraReactiveHealthIndicator`] +| {spring-boot-actuator-module-code}/cassandra/CassandraReactiveHealthIndicator.java[`CassandraReactiveHealthIndicator`] or {spring-boot-actuator-module-code}/cassandra/CassandraDriverReactiveHealthIndicator.java[`CassandraDriverReactiveHealthIndicator`] | Checks that a Cassandra database is up. | {spring-boot-actuator-module-code}/couchbase/CouchbaseReactiveHealthIndicator.java[`CouchbaseReactiveHealthIndicator`]