Skip to content

Commit

Permalink
Merge branch '2.6.x' into 2.7.x
Browse files Browse the repository at this point in the history
Closes gh-31818
  • Loading branch information
wilkinsona committed Jul 20, 2022
2 parents 1343174 + ab2b04f commit 2e98caf
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 8 deletions.
Expand Up @@ -77,11 +77,10 @@ HealthEndpointGroups healthEndpointGroups(ApplicationContext applicationContext,
@Bean
@ConditionalOnMissingBean
HealthContributorRegistry healthContributorRegistry(ApplicationContext applicationContext,
HealthEndpointGroups groups) {
Map<String, HealthContributor> healthContributors = new LinkedHashMap<>(
applicationContext.getBeansOfType(HealthContributor.class));
HealthEndpointGroups groups, Map<String, HealthContributor> healthContributors,
Map<String, ReactiveHealthContributor> reactiveHealthContributors) {
if (ClassUtils.isPresent("reactor.core.publisher.Flux", applicationContext.getClassLoader())) {
healthContributors.putAll(new AdaptedReactiveHealthContributors(applicationContext).get());
healthContributors.putAll(new AdaptedReactiveHealthContributors(reactiveHealthContributors).get());
}
return new AutoConfiguredHealthContributorRegistry(healthContributors, groups.getNames());
}
Expand Down Expand Up @@ -137,10 +136,9 @@ private static class AdaptedReactiveHealthContributors {

private final Map<String, HealthContributor> adapted;

AdaptedReactiveHealthContributors(ApplicationContext applicationContext) {
AdaptedReactiveHealthContributors(Map<String, ReactiveHealthContributor> reactiveContributors) {
Map<String, HealthContributor> adapted = new LinkedHashMap<>();
applicationContext.getBeansOfType(ReactiveHealthContributor.class)
.forEach((name, contributor) -> adapted.put(name, adapt(contributor)));
reactiveContributors.forEach((name, contributor) -> adapted.put(name, adapt(contributor)));
this.adapted = Collections.unmodifiableMap(adapted);
}

Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2021 the original author or authors.
* Copyright 2012-2022 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.
Expand All @@ -17,6 +17,7 @@
package org.springframework.boot.actuate.autoconfigure.health;

import java.util.Collections;
import java.util.Map;

import org.junit.jupiter.api.Test;
import reactor.core.publisher.Flux;
Expand Down Expand Up @@ -45,8 +46,10 @@
import org.springframework.boot.actuate.health.ReactiveHealthIndicator;
import org.springframework.boot.actuate.health.Status;
import org.springframework.boot.actuate.health.StatusAggregator;
import org.springframework.boot.actuate.health.SystemHealth;
import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.test.context.FilteredClassLoader;
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
import org.springframework.boot.test.context.runner.ReactiveWebApplicationContextRunner;
import org.springframework.boot.test.context.runner.WebApplicationContextRunner;
import org.springframework.context.annotation.Bean;
Expand Down Expand Up @@ -264,6 +267,32 @@ void runWhenHasHealthEndpointGroupsPostProcessorPerformsProcessing() {
});
}

@Test
void runWithIndicatorsInParentContextFindsIndicators() {
new ApplicationContextRunner().withUserConfiguration(HealthIndicatorsConfiguration.class)
.run((parent) -> new WebApplicationContextRunner().withConfiguration(AutoConfigurations
.of(HealthContributorAutoConfiguration.class, HealthEndpointAutoConfiguration.class))
.withParent(parent).run((context) -> {
HealthComponent health = context.getBean(HealthEndpoint.class).health();
Map<String, HealthComponent> components = ((SystemHealth) health).getComponents();
assertThat(components).containsKeys("additional", "ping", "simple");
}));
}

@Test
void runWithReactiveContextAndIndicatorsInParentContextFindsIndicators() {
new ApplicationContextRunner().withUserConfiguration(HealthIndicatorsConfiguration.class)
.run((parent) -> new ReactiveWebApplicationContextRunner()
.withConfiguration(AutoConfigurations.of(HealthContributorAutoConfiguration.class,
HealthEndpointAutoConfiguration.class, WebEndpointAutoConfiguration.class,
EndpointAutoConfiguration.class))
.withParent(parent).run((context) -> {
HealthComponent health = context.getBean(HealthEndpoint.class).health();
Map<String, HealthComponent> components = ((SystemHealth) health).getComponents();
assertThat(components).containsKeys("additional", "ping", "simple");
}));
}

@Configuration(proxyBeanMethods = false)
static class HealthIndicatorsConfiguration {

Expand Down

0 comments on commit 2e98caf

Please sign in to comment.