Skip to content

Commit 13b95a5

Browse files
committed
Polish Cassandra health auto-configuration
The indicators that require Spring Data were removed. This commit updates the auto-configuration ordering as there's no longer a need for Spring Data Cassandra to have been auto-configured first. It also simplifies the tests as Spring Data no longer needs to be considered. Closes gh-45585
1 parent 7b89fa0 commit 13b95a5

File tree

4 files changed

+12
-48
lines changed

4 files changed

+12
-48
lines changed

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2022 the original author or authors.
2+
* Copyright 2012-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -25,7 +25,6 @@
2525
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
2626
import org.springframework.boot.autoconfigure.cassandra.CassandraAutoConfiguration;
2727
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
28-
import org.springframework.boot.autoconfigure.data.cassandra.CassandraDataAutoConfiguration;
2928
import org.springframework.context.annotation.Import;
3029

3130
/**
@@ -36,8 +35,8 @@
3635
* @author Stephane Nicoll
3736
* @since 2.1.0
3837
*/
39-
@AutoConfiguration(after = { CassandraAutoConfiguration.class, CassandraDataAutoConfiguration.class,
40-
CassandraReactiveHealthContributorAutoConfiguration.class })
38+
@AutoConfiguration(
39+
after = { CassandraAutoConfiguration.class, CassandraReactiveHealthContributorAutoConfiguration.class })
4140
@ConditionalOnClass(CqlSession.class)
4241
@ConditionalOnEnabledHealthIndicator("cassandra")
4342
@Import(CassandraDriverConfiguration.class)

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2022 the original author or authors.
2+
* Copyright 2012-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -24,8 +24,8 @@
2424
import org.springframework.boot.actuate.cassandra.CassandraDriverReactiveHealthIndicator;
2525
import org.springframework.boot.autoconfigure.AutoConfiguration;
2626
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
27+
import org.springframework.boot.autoconfigure.cassandra.CassandraAutoConfiguration;
2728
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
28-
import org.springframework.boot.autoconfigure.data.cassandra.CassandraReactiveDataAutoConfiguration;
2929
import org.springframework.context.annotation.Import;
3030

3131
/**
@@ -36,7 +36,7 @@
3636
* @author Stephane Nicoll
3737
* @since 2.1.0
3838
*/
39-
@AutoConfiguration(after = CassandraReactiveDataAutoConfiguration.class)
39+
@AutoConfiguration(after = CassandraAutoConfiguration.class)
4040
@ConditionalOnClass({ CqlSession.class, Flux.class })
4141
@ConditionalOnEnabledHealthIndicator("cassandra")
4242
@Import(CassandraReactiveDriverConfiguration.class)

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

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2024 the original author or authors.
2+
* Copyright 2012-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -22,9 +22,7 @@
2222
import org.springframework.boot.actuate.autoconfigure.health.HealthContributorAutoConfiguration;
2323
import org.springframework.boot.actuate.cassandra.CassandraDriverHealthIndicator;
2424
import org.springframework.boot.autoconfigure.AutoConfigurations;
25-
import org.springframework.boot.test.context.FilteredClassLoader;
2625
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
27-
import org.springframework.data.cassandra.core.CassandraOperations;
2826

2927
import static org.assertj.core.api.Assertions.assertThat;
3028
import static org.mockito.Mockito.mock;
@@ -42,29 +40,20 @@ class CassandraHealthContributorAutoConfigurationTests {
4240
HealthContributorAutoConfiguration.class));
4341

4442
@Test
45-
void runWithoutCqlSessionOrCassandraOperationsShouldNotCreateIndicator() {
43+
void runWithoutCqlSessionShouldNotCreateIndicator() {
4644
this.contextRunner.run((context) -> assertThat(context).doesNotHaveBean("cassandraHealthContributor")
4745
.doesNotHaveBean(CassandraDriverHealthIndicator.class));
4846
}
4947

5048
@Test
51-
void runWithCqlSessionOnlyShouldCreateDriverIndicator() {
49+
void runWithCqlSessionShouldCreateDriverIndicator() {
5250
this.contextRunner.withBean(CqlSession.class, () -> mock(CqlSession.class))
5351
.run((context) -> assertThat(context).hasSingleBean(CassandraDriverHealthIndicator.class));
5452
}
5553

56-
@Test
57-
@SuppressWarnings("resource")
58-
void runWithCqlSessionAndSpringDataAbsentShouldCreateDriverIndicator() {
59-
this.contextRunner.withBean(CqlSession.class, () -> mock(CqlSession.class))
60-
.withClassLoader(new FilteredClassLoader("org.springframework.data"))
61-
.run((context) -> assertThat(context).hasSingleBean(CassandraDriverHealthIndicator.class));
62-
}
63-
6454
@Test
6555
void runWhenDisabledShouldNotCreateIndicator() {
6656
this.contextRunner.withBean(CqlSession.class, () -> mock(CqlSession.class))
67-
.withBean(CassandraOperations.class, () -> mock(CassandraOperations.class))
6857
.withPropertyValues("management.health.cassandra.enabled:false")
6958
.run((context) -> assertThat(context).doesNotHaveBean("cassandraHealthContributor")
7059
.doesNotHaveBean(CassandraDriverHealthIndicator.class));

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

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2024 the original author or authors.
2+
* Copyright 2012-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -20,13 +20,9 @@
2020
import org.junit.jupiter.api.Test;
2121

2222
import org.springframework.boot.actuate.autoconfigure.health.HealthContributorAutoConfiguration;
23-
import org.springframework.boot.actuate.cassandra.CassandraDriverHealthIndicator;
2423
import org.springframework.boot.actuate.cassandra.CassandraDriverReactiveHealthIndicator;
2524
import org.springframework.boot.autoconfigure.AutoConfigurations;
26-
import org.springframework.boot.test.context.FilteredClassLoader;
2725
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
28-
import org.springframework.data.cassandra.core.CassandraOperations;
29-
import org.springframework.data.cassandra.core.ReactiveCassandraOperations;
3026

3127
import static org.assertj.core.api.Assertions.assertThat;
3228
import static org.mockito.Mockito.mock;
@@ -44,41 +40,21 @@ class CassandraReactiveHealthContributorAutoConfigurationTests {
4440
CassandraHealthContributorAutoConfiguration.class, HealthContributorAutoConfiguration.class));
4541

4642
@Test
47-
void runWithoutCqlSessionOrReactiveCassandraOperationsShouldNotCreateIndicator() {
43+
void runWithoutCqlSessionShouldNotCreateIndicator() {
4844
this.contextRunner.run((context) -> assertThat(context).doesNotHaveBean("cassandraHealthContributor")
4945
.doesNotHaveBean(CassandraDriverReactiveHealthIndicator.class));
5046
}
5147

5248
@Test
53-
void runWithCqlSessionOnlyShouldCreateDriverIndicator() {
49+
void runWithCqlSessionShouldCreateIndicator() {
5450
this.contextRunner.withBean(CqlSession.class, () -> mock(CqlSession.class))
5551
.run((context) -> assertThat(context).hasBean("cassandraHealthContributor")
5652
.hasSingleBean(CassandraDriverReactiveHealthIndicator.class));
5753
}
5854

59-
@Test
60-
void runWithCqlSessionAndReactiveCassandraOperationsShouldCreateDriverIndicator() {
61-
this.contextRunner.withBean(CqlSession.class, () -> mock(CqlSession.class))
62-
.withBean(ReactiveCassandraOperations.class, () -> mock(ReactiveCassandraOperations.class))
63-
.withBean(CassandraOperations.class, () -> mock(CassandraOperations.class))
64-
.run((context) -> assertThat(context).hasBean("cassandraHealthContributor")
65-
.hasSingleBean(CassandraDriverReactiveHealthIndicator.class)
66-
.doesNotHaveBean(CassandraDriverHealthIndicator.class));
67-
}
68-
69-
@Test
70-
@SuppressWarnings("resource")
71-
void runWithCqlSessionAndSpringDataAbsentShouldCreateDriverIndicator() {
72-
this.contextRunner.withBean(CqlSession.class, () -> mock(CqlSession.class))
73-
.withClassLoader(new FilteredClassLoader("org.springframework.data"))
74-
.run((context) -> assertThat(context).hasBean("cassandraHealthContributor")
75-
.hasSingleBean(CassandraDriverReactiveHealthIndicator.class));
76-
}
77-
7855
@Test
7956
void runWhenDisabledShouldNotCreateIndicator() {
8057
this.contextRunner.withBean(CqlSession.class, () -> mock(CqlSession.class))
81-
.withBean(ReactiveCassandraOperations.class, () -> mock(ReactiveCassandraOperations.class))
8258
.withPropertyValues("management.health.cassandra.enabled:false")
8359
.run((context) -> assertThat(context).doesNotHaveBean("cassandraHealthContributor"));
8460
}

0 commit comments

Comments
 (0)