Polish "Add health indicator for Cassandra that uses the CqlSession"
See gh-20887pull/21936/head
parent
dad9ec86d5
commit
35e069e2cd
@ -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<CassandraDriverHealthIndicator, CqlSession> {
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean(name = { "cassandraHealthIndicator", "cassandraHealthContributor" })
|
||||
public HealthContributor cassandraHealthContributor(Map<String, CqlSession> sessions) {
|
||||
return createContributor(sessions);
|
||||
}
|
||||
|
||||
}
|
@ -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<CassandraDriverReactiveHealthIndicator, CqlSession> {
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean(name = { "cassandraHealthIndicator", "cassandraHealthContributor" })
|
||||
public ReactiveHealthContributor cassandraHealthContributor(Map<String, CqlSession> sessions) {
|
||||
return createContributor(sessions);
|
||||
}
|
||||
|
||||
}
|
@ -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<CassandraDriverHealthIndicator, CqlSession> {
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean(name = { "cassandraHealthIndicator", "cassandraHealthContributor" })
|
||||
HealthContributor cassandraHealthContributor(Map<String, CqlSession> sessions) {
|
||||
return createContributor(sessions);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
@ConditionalOnClass(CassandraOperations.class)
|
||||
@ConditionalOnBean(CassandraOperations.class)
|
||||
static class CassandraOperationsConfiguration
|
||||
extends CompositeHealthContributorConfiguration<CassandraHealthIndicator, CassandraOperations> {
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean(name = { "cassandraHealthIndicator", "cassandraHealthContributor" })
|
||||
HealthContributor cassandraHealthContributor(Map<String, CassandraOperations> cassandraOperations) {
|
||||
return createContributor(cassandraOperations);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
@ConditionalOnBean(CqlSession.class)
|
||||
static class CassandraReactiveDriverConfiguration extends
|
||||
CompositeReactiveHealthContributorConfiguration<CassandraDriverReactiveHealthIndicator, CqlSession> {
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean(name = { "cassandraHealthIndicator", "cassandraHealthContributor" })
|
||||
ReactiveHealthContributor cassandraHealthContributor(Map<String, CqlSession> sessions) {
|
||||
return createContributor(sessions);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
@ConditionalOnClass(ReactiveCassandraOperations.class)
|
||||
@ConditionalOnBean(ReactiveCassandraOperations.class)
|
||||
static class CassandraReactiveOperationsConfiguration extends
|
||||
CompositeReactiveHealthContributorConfiguration<CassandraReactiveHealthIndicator, ReactiveCassandraOperations> {
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean(name = { "cassandraHealthIndicator", "cassandraHealthContributor" })
|
||||
ReactiveHealthContributor cassandraHealthContributor(
|
||||
Map<String, ReactiveCassandraOperations> reactiveCassandraOperations) {
|
||||
return createContributor(reactiveCassandraOperations);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -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"));
|
||||
}
|
||||
|
||||
}
|
@ -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"));
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue