mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-08-29 03:06:45 +08:00
Merge pull request #32505 from micopiira
* pr/32505: Polish "Use non-blocking API in CouchbaseReactiveHealthIndicator" Use non-blocking API in CouchbaseReactiveHealthIndicator Closes gh-32505
This commit is contained in:
commit
1928177da2
@ -16,7 +16,6 @@
|
||||
|
||||
package org.springframework.boot.actuate.couchbase;
|
||||
|
||||
import com.couchbase.client.core.diagnostics.DiagnosticsResult;
|
||||
import com.couchbase.client.java.Cluster;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
@ -46,9 +45,10 @@ public class CouchbaseReactiveHealthIndicator extends AbstractReactiveHealthIndi
|
||||
|
||||
@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();
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -28,7 +28,9 @@ import com.couchbase.client.core.diagnostics.EndpointDiagnostics;
|
||||
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 reactor.core.publisher.Mono;
|
||||
|
||||
import org.springframework.boot.actuate.health.Health;
|
||||
import org.springframework.boot.actuate.health.Status;
|
||||
@ -52,13 +54,15 @@ class CouchbaseReactiveHealthIndicatorTests {
|
||||
Collections.singletonList(new EndpointDiagnostics(ServiceType.KV, EndpointState.CONNECTED, "127.0.0.1",
|
||||
"127.0.0.1", Optional.empty(), Optional.of(1234L), Optional.of("endpoint-1"))));
|
||||
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
|
||||
@ -73,13 +77,15 @@ class CouchbaseReactiveHealthIndicatorTests {
|
||||
new EndpointDiagnostics(ServiceType.KV, EndpointState.CONNECTING, "127.0.0.1", "127.0.0.1",
|
||||
Optional.empty(), Optional.of(1234L), Optional.of("endpoint-2"))));
|
||||
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();
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user