Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
*/
class AutoConfiguredHealthCheckedGrpcComponents implements HealthCheckedGrpcComponents {

private final HealthCheckedGrpcComponent server;
private final @Nullable HealthCheckedGrpcComponent server;

private final Map<String, HealthCheckedGrpcComponent> services;

Expand All @@ -68,8 +68,10 @@ 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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,15 @@ void getServerMatchesAllMembers() {
});
}

@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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,16 @@ void createsGrpcServerHealth() {
});
}

@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) -> {
Expand Down