mirror of
https://github.com/spring-projects/spring-boot.git
synced 2026-09-17 12:09:16 +00:00
Merge pull request #50799 from xfocus3
* gh-50791-grpc-health-overall: Polish "Honor gRPC overall health setting" Honor gRPC overall health setting Closes gh-50799
This commit is contained in:
+3
-3
@@ -51,7 +51,7 @@ import org.springframework.util.ObjectUtils;
|
||||
*/
|
||||
class AutoConfiguredHealthCheckedGrpcComponents implements HealthCheckedGrpcComponents {
|
||||
|
||||
private final HealthCheckedGrpcComponent server;
|
||||
private final @Nullable HealthCheckedGrpcComponent server;
|
||||
|
||||
private final Map<String, HealthCheckedGrpcComponent> services;
|
||||
|
||||
@@ -68,8 +68,8 @@ class AutoConfiguredHealthCheckedGrpcComponents implements HealthCheckedGrpcComp
|
||||
() -> StatusAggregator.of(properties.getStatus().getOrder()));
|
||||
StatusMapper statusMapper = getNonQualifiedBean(beanFactory, StatusMapper.class,
|
||||
() -> StatusMapper.of(properties.getStatus().getMapping()));
|
||||
this.server = new AutoConfiguredHealthCheckedGrpcComponent(HealthContributorMembership.always(),
|
||||
statusAggregator, statusMapper);
|
||||
this.server = (properties.isIncludeOverallHealth()) ? new AutoConfiguredHealthCheckedGrpcComponent(
|
||||
HealthContributorMembership.always(), statusAggregator, statusMapper) : null;
|
||||
this.services = createServices(properties.getService(), beanFactory, statusAggregator, statusMapper);
|
||||
}
|
||||
|
||||
|
||||
+9
@@ -59,6 +59,15 @@ class AutoConfiguredHealthCheckedGrpcComponentsTests {
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void getServerWhenIncludeOverallHealthIsFalseReturnsNull() {
|
||||
this.contextRunner.withPropertyValues("spring.grpc.server.health.include-overall-health=false")
|
||||
.run((context) -> {
|
||||
HealthCheckedGrpcComponents components = context.getBean(HealthCheckedGrpcComponents.class);
|
||||
assertThat(components.getServer()).isNull();
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void getServiceNamesReturnsServiceNames() {
|
||||
this.contextRunner
|
||||
|
||||
+11
@@ -302,6 +302,17 @@ class GrpcServerHealthAutoConfigurationTests {
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void whenIncludeOverallHealthIsFalseDoesNotReportOverallHealth() {
|
||||
this.contextRunner.withPropertyValues("spring.grpc.server.health.include-overall-health=false")
|
||||
.run((context) -> {
|
||||
GrpcServerHealth serverHealth = context.getBean(GrpcServerHealth.class);
|
||||
Map<String, ServingStatus> result = new LinkedHashMap<>();
|
||||
serverHealth.update(result::put);
|
||||
assertThat(result).isEmpty();
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void whenHasGrpcServerHealthBeanDoesNotCreateAdditional() {
|
||||
this.contextRunner.withUserConfiguration(GrpcServerHealthConfiguration.class).run((context) -> {
|
||||
|
||||
Reference in New Issue
Block a user