Skip to content
Merged
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 @@ -5,9 +5,13 @@
public abstract class RCHealthIndicator {

public Mono<RCHealth> health() {
return doHealthCheck(RCHealth.builder())
var builder = RCHealth.builder();
return doHealthCheck(builder)
.onErrorResume(e ->
Mono.just(RCHealth.builder().down().withDetail("error", e.getMessage()).build())
Mono.just(builder
.down()
.withDetail("error", e.getMessage())
.build())
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
public class ReactiveCommonsHealthIndicator extends AbstractReactiveHealthIndicator {
public static final String DOMAIN = "domain";
public static final String VERSION = "version";
public static final String UNKNOWN = "unknown";
private final ConnectionManager manager;

@Override
Expand All @@ -29,7 +30,7 @@ protected Mono<Health> doHealthCheck(Health.Builder builder) {
}

private Health.Builder reduceHealth(Health.Builder builder, RCHealth health) {
String domain = health.details().get(DOMAIN).toString();
String domain = health.details().getOrDefault(DOMAIN, UNKNOWN).toString();
if (health.status().equals(RCHealth.Status.DOWN)) {
log.error("Broker of domain {} is down", domain);
return builder.down().withDetail(domain, health.details());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,17 @@ void shouldBeDown() {
.expectNextMatches(health -> health.getStatus().toString().equals("DOWN"))
.verifyComplete();
}

@Test
void shouldBeDownAndSetDomain() {
// Arrange
when(brokerProvider.healthCheck()).thenReturn(Mono.just(RCHealth.builder().down().build()));
when(brokerProvider2.healthCheck()).thenReturn(Mono.just(RCHealth.builder().up().build()));
// Act
Mono<Health> flow = healthIndicator.health();
// Assert
StepVerifier.create(flow)
.expectNextMatches(health -> health.getStatus().toString().equals("DOWN"))
.verifyComplete();
}
}