Skip to content

Commit f06627c

Browse files
committed
Allow CompositeHealthIndicator to be created with a Map as before
See gh-4965
1 parent bb69339 commit f06627c

File tree

5 files changed

+10
-16
lines changed

5 files changed

+10
-16
lines changed

spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/documentation/HealthEndpointDocumentationTests.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import org.junit.Test;
2828

2929
import org.springframework.boot.actuate.health.CompositeHealthIndicator;
30-
import org.springframework.boot.actuate.health.DefaultHealthIndicatorRegistry;
3130
import org.springframework.boot.actuate.health.Health;
3231
import org.springframework.boot.actuate.health.HealthEndpoint;
3332
import org.springframework.boot.actuate.health.HealthIndicator;
@@ -122,7 +121,7 @@ public CompositeHealthIndicator brokerHealthIndicator() {
122121
indicators.put("us2",
123122
() -> Health.up().withDetail("version", "1.0.4").build());
124123
return new CompositeHealthIndicator(new OrderedHealthAggregator(),
125-
new DefaultHealthIndicatorRegistry(indicators));
124+
indicators);
126125
}
127126

128127
}

spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/health/HealthEndpointWebExtensionTests.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import org.springframework.boot.actuate.endpoint.SecurityContext;
2626
import org.springframework.boot.actuate.endpoint.web.WebEndpointResponse;
2727
import org.springframework.boot.actuate.health.CompositeHealthIndicator;
28-
import org.springframework.boot.actuate.health.DefaultHealthIndicatorRegistry;
2928
import org.springframework.boot.actuate.health.Health;
3029
import org.springframework.boot.actuate.health.HealthEndpointWebExtension;
3130
import org.springframework.boot.actuate.health.HealthIndicator;
@@ -436,7 +435,7 @@ public HealthIndicator compositeHealthIndicator() {
436435
nestedIndicators.put("one", simpleHealthIndicator());
437436
nestedIndicators.put("two", () -> Health.up().build());
438437
return new CompositeHealthIndicator(new OrderedHealthAggregator(),
439-
new DefaultHealthIndicatorRegistry(nestedIndicators));
438+
nestedIndicators);
440439
}
441440

442441
}

spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/CompositeHealthIndicator.java

-3
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,7 @@ public CompositeHealthIndicator(HealthAggregator healthAggregator) {
4949
* @param healthAggregator the health aggregator
5050
* @param indicators a map of {@link HealthIndicator HealthIndicators} with the key
5151
* being used as an indicator name.
52-
* @deprecated since 2.1.0 in favour of
53-
* {@link #CompositeHealthIndicator(HealthAggregator, HealthIndicatorRegistry)}
5452
*/
55-
@Deprecated
5653
public CompositeHealthIndicator(HealthAggregator healthAggregator,
5754
Map<String, HealthIndicator> indicators) {
5855
this(healthAggregator, new DefaultHealthIndicatorRegistry(indicators));

spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/CompositeHealthIndicatorTests.java

+3-4
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public void createWithIndicators() {
6363
indicators.put("one", this.one);
6464
indicators.put("two", this.two);
6565
CompositeHealthIndicator composite = new CompositeHealthIndicator(
66-
this.healthAggregator, new DefaultHealthIndicatorRegistry(indicators));
66+
this.healthAggregator, indicators);
6767
Health result = composite.health();
6868
assertThat(result.getDetails()).hasSize(2);
6969
assertThat(result.getDetails()).containsEntry("one",
@@ -78,10 +78,9 @@ public void testSerialization() throws Exception {
7878
indicators.put("db1", this.one);
7979
indicators.put("db2", this.two);
8080
CompositeHealthIndicator innerComposite = new CompositeHealthIndicator(
81-
this.healthAggregator, new DefaultHealthIndicatorRegistry(indicators));
81+
this.healthAggregator, indicators);
8282
CompositeHealthIndicator composite = new CompositeHealthIndicator(
83-
this.healthAggregator, new DefaultHealthIndicatorRegistry(
84-
Collections.singletonMap("db", innerComposite)));
83+
this.healthAggregator, Collections.singletonMap("db", innerComposite));
8584
Health result = composite.health();
8685
ObjectMapper mapper = new ObjectMapper();
8786
assertThat(mapper.writeValueAsString(result)).isEqualTo(

spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/HealthEndpointTests.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ public void statusForUnknownComponentReturnNull() {
7878
@Test
7979
public void statusForComponentInstanceIsExposed() {
8080
CompositeHealthIndicator compositeIndicator = new CompositeHealthIndicator(
81-
new OrderedHealthAggregator(), new DefaultHealthIndicatorRegistry(
82-
Collections.singletonMap("sub", () -> Health.down().build())));
81+
new OrderedHealthAggregator(),
82+
Collections.singletonMap("sub", () -> Health.down().build()));
8383
HealthEndpoint endpoint = new HealthEndpoint(createHealthIndicator(
8484
Collections.singletonMap("test", compositeIndicator)));
8585
Health health = endpoint.healthForComponentInstance("test", "sub");
@@ -91,8 +91,8 @@ public void statusForComponentInstanceIsExposed() {
9191
@Test
9292
public void statusForUnknownComponentInstanceReturnNull() {
9393
CompositeHealthIndicator compositeIndicator = new CompositeHealthIndicator(
94-
new OrderedHealthAggregator(), new DefaultHealthIndicatorRegistry(
95-
Collections.singletonMap("sub", () -> Health.down().build())));
94+
new OrderedHealthAggregator(),
95+
Collections.singletonMap("sub", () -> Health.down().build()));
9696
HealthEndpoint endpoint = new HealthEndpoint(createHealthIndicator(
9797
Collections.singletonMap("test", compositeIndicator)));
9898
Health health = endpoint.healthForComponentInstance("test", "does-not-exist");
@@ -110,7 +110,7 @@ public void statusForComponentInstanceThatIsNotACompositeReturnNull() {
110110
private HealthIndicator createHealthIndicator(
111111
Map<String, HealthIndicator> healthIndicators) {
112112
return new CompositeHealthIndicator(new OrderedHealthAggregator(),
113-
new DefaultHealthIndicatorRegistry(healthIndicators));
113+
healthIndicators);
114114
}
115115

116116
}

0 commit comments

Comments
 (0)