Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CouchbaseReactiveHealthIndicator uses blocking API to retrieve the cluster diagnostics #32505

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -46,9 +46,10 @@ public CouchbaseReactiveHealthIndicator(Cluster cluster) {

@Override
protected Mono<Health> doHealthCheck(Health.Builder builder) {
DiagnosticsResult diagnostics = this.cluster.diagnostics();
new CouchbaseHealth(diagnostics).applyTo(builder);
return Mono.just(builder.build());
return this.cluster.reactive().diagnostics().map(diagnostics -> {
new CouchbaseHealth(diagnostics).applyTo(builder);
return builder.build();
});
}

}
Expand Up @@ -28,10 +28,12 @@
import com.couchbase.client.core.endpoint.EndpointState;
import com.couchbase.client.core.service.ServiceType;
import com.couchbase.client.java.Cluster;
import com.couchbase.client.java.ReactiveCluster;
import org.junit.jupiter.api.Test;

import org.springframework.boot.actuate.health.Health;
import org.springframework.boot.actuate.health.Status;
import reactor.core.publisher.Mono;

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.BDDMockito.given;
Expand All @@ -53,13 +55,15 @@ void couchbaseClusterIsUp() {
new EndpointDiagnostics(ServiceType.KV, EndpointState.CONNECTED, "127.0.0.1", "127.0.0.1",
Optional.empty(), Optional.of(1234L), Optional.of("endpoint-1"), Optional.empty())));
DiagnosticsResult diagnostics = new DiagnosticsResult(endpoints, "test-sdk", "test-id");
given(cluster.diagnostics()).willReturn(diagnostics);
ReactiveCluster reactiveCluster = mock(ReactiveCluster.class);
given(reactiveCluster.diagnostics()).willReturn(Mono.just(diagnostics));
given(cluster.reactive()).willReturn(reactiveCluster);
Health health = healthIndicator.health().block(Duration.ofSeconds(30));
assertThat(health.getStatus()).isEqualTo(Status.UP);
assertThat(health.getDetails()).containsEntry("sdk", "test-sdk");
assertThat(health.getDetails()).containsKey("endpoints");
assertThat((List<Map<String, Object>>) health.getDetails().get("endpoints")).hasSize(1);
then(cluster).should().diagnostics();
then(reactiveCluster).should().diagnostics();
}

@Test
Expand All @@ -74,13 +78,15 @@ void couchbaseClusterIsDown() {
new EndpointDiagnostics(ServiceType.KV, EndpointState.CONNECTING, "127.0.0.1", "127.0.0.1",
Optional.empty(), Optional.of(1234L), Optional.of("endpoint-2"), Optional.empty())));
DiagnosticsResult diagnostics = new DiagnosticsResult(endpoints, "test-sdk", "test-id");
given(cluster.diagnostics()).willReturn(diagnostics);
ReactiveCluster reactiveCluster = mock(ReactiveCluster.class);
given(reactiveCluster.diagnostics()).willReturn(Mono.just(diagnostics));
given(cluster.reactive()).willReturn(reactiveCluster);
Health health = healthIndicator.health().block(Duration.ofSeconds(30));
assertThat(health.getStatus()).isEqualTo(Status.DOWN);
assertThat(health.getDetails()).containsEntry("sdk", "test-sdk");
assertThat(health.getDetails()).containsKey("endpoints");
assertThat((List<Map<String, Object>>) health.getDetails().get("endpoints")).hasSize(2);
then(cluster).should().diagnostics();
then(reactiveCluster).should().diagnostics();
}

}