Allow CompositeHealthIndicator to be created with a Map as before

See gh-4965
pull/13302/merge
Stephane Nicoll 7 years ago
parent bb69339a82
commit f06627c408

@ -27,7 +27,6 @@ import javax.sql.DataSource;
import org.junit.Test;
import org.springframework.boot.actuate.health.CompositeHealthIndicator;
import org.springframework.boot.actuate.health.DefaultHealthIndicatorRegistry;
import org.springframework.boot.actuate.health.Health;
import org.springframework.boot.actuate.health.HealthEndpoint;
import org.springframework.boot.actuate.health.HealthIndicator;
@ -122,7 +121,7 @@ public class HealthEndpointDocumentationTests extends MockMvcEndpointDocumentati
indicators.put("us2",
() -> Health.up().withDetail("version", "1.0.4").build());
return new CompositeHealthIndicator(new OrderedHealthAggregator(),
new DefaultHealthIndicatorRegistry(indicators));
indicators);
}
}

@ -25,7 +25,6 @@ import org.junit.Test;
import org.springframework.boot.actuate.endpoint.SecurityContext;
import org.springframework.boot.actuate.endpoint.web.WebEndpointResponse;
import org.springframework.boot.actuate.health.CompositeHealthIndicator;
import org.springframework.boot.actuate.health.DefaultHealthIndicatorRegistry;
import org.springframework.boot.actuate.health.Health;
import org.springframework.boot.actuate.health.HealthEndpointWebExtension;
import org.springframework.boot.actuate.health.HealthIndicator;
@ -436,7 +435,7 @@ public class HealthEndpointWebExtensionTests {
nestedIndicators.put("one", simpleHealthIndicator());
nestedIndicators.put("two", () -> Health.up().build());
return new CompositeHealthIndicator(new OrderedHealthAggregator(),
new DefaultHealthIndicatorRegistry(nestedIndicators));
nestedIndicators);
}
}

@ -49,10 +49,7 @@ public class CompositeHealthIndicator implements HealthIndicator {
* @param healthAggregator the health aggregator
* @param indicators a map of {@link HealthIndicator HealthIndicators} with the key
* being used as an indicator name.
* @deprecated since 2.1.0 in favour of
* {@link #CompositeHealthIndicator(HealthAggregator, HealthIndicatorRegistry)}
*/
@Deprecated
public CompositeHealthIndicator(HealthAggregator healthAggregator,
Map<String, HealthIndicator> indicators) {
this(healthAggregator, new DefaultHealthIndicatorRegistry(indicators));

@ -63,7 +63,7 @@ public class CompositeHealthIndicatorTests {
indicators.put("one", this.one);
indicators.put("two", this.two);
CompositeHealthIndicator composite = new CompositeHealthIndicator(
this.healthAggregator, new DefaultHealthIndicatorRegistry(indicators));
this.healthAggregator, indicators);
Health result = composite.health();
assertThat(result.getDetails()).hasSize(2);
assertThat(result.getDetails()).containsEntry("one",
@ -78,10 +78,9 @@ public class CompositeHealthIndicatorTests {
indicators.put("db1", this.one);
indicators.put("db2", this.two);
CompositeHealthIndicator innerComposite = new CompositeHealthIndicator(
this.healthAggregator, new DefaultHealthIndicatorRegistry(indicators));
this.healthAggregator, indicators);
CompositeHealthIndicator composite = new CompositeHealthIndicator(
this.healthAggregator, new DefaultHealthIndicatorRegistry(
Collections.singletonMap("db", innerComposite)));
this.healthAggregator, Collections.singletonMap("db", innerComposite));
Health result = composite.health();
ObjectMapper mapper = new ObjectMapper();
assertThat(mapper.writeValueAsString(result)).isEqualTo(

@ -78,8 +78,8 @@ public class HealthEndpointTests {
@Test
public void statusForComponentInstanceIsExposed() {
CompositeHealthIndicator compositeIndicator = new CompositeHealthIndicator(
new OrderedHealthAggregator(), new DefaultHealthIndicatorRegistry(
Collections.singletonMap("sub", () -> Health.down().build())));
new OrderedHealthAggregator(),
Collections.singletonMap("sub", () -> Health.down().build()));
HealthEndpoint endpoint = new HealthEndpoint(createHealthIndicator(
Collections.singletonMap("test", compositeIndicator)));
Health health = endpoint.healthForComponentInstance("test", "sub");
@ -91,8 +91,8 @@ public class HealthEndpointTests {
@Test
public void statusForUnknownComponentInstanceReturnNull() {
CompositeHealthIndicator compositeIndicator = new CompositeHealthIndicator(
new OrderedHealthAggregator(), new DefaultHealthIndicatorRegistry(
Collections.singletonMap("sub", () -> Health.down().build())));
new OrderedHealthAggregator(),
Collections.singletonMap("sub", () -> Health.down().build()));
HealthEndpoint endpoint = new HealthEndpoint(createHealthIndicator(
Collections.singletonMap("test", compositeIndicator)));
Health health = endpoint.healthForComponentInstance("test", "does-not-exist");
@ -110,7 +110,7 @@ public class HealthEndpointTests {
private HealthIndicator createHealthIndicator(
Map<String, HealthIndicator> healthIndicators) {
return new CompositeHealthIndicator(new OrderedHealthAggregator(),
new DefaultHealthIndicatorRegistry(healthIndicators));
healthIndicators);
}
}

Loading…
Cancel
Save