From f51c4c3df0bfd9cec77f048e959672fe6d82d5bb Mon Sep 17 00:00:00 2001 From: Mico Piira <--global> Date: Mon, 26 Sep 2022 21:19:10 +0300 Subject: [PATCH 1/2] Use non-blocking API in CouchbaseReactiveHealthIndicator See gh-32505 --- .../CouchbaseReactiveHealthIndicator.java | 7 ++++--- .../CouchbaseReactiveHealthIndicatorTests.java | 14 ++++++++++---- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/couchbase/CouchbaseReactiveHealthIndicator.java b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/couchbase/CouchbaseReactiveHealthIndicator.java index b368f9306e..363ddc6c9e 100644 --- a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/couchbase/CouchbaseReactiveHealthIndicator.java +++ b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/couchbase/CouchbaseReactiveHealthIndicator.java @@ -46,9 +46,10 @@ public class CouchbaseReactiveHealthIndicator extends AbstractReactiveHealthIndi @Override protected Mono 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(); + }); } } diff --git a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/couchbase/CouchbaseReactiveHealthIndicatorTests.java b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/couchbase/CouchbaseReactiveHealthIndicatorTests.java index adc00a8751..0106c56215 100644 --- a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/couchbase/CouchbaseReactiveHealthIndicatorTests.java +++ b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/couchbase/CouchbaseReactiveHealthIndicatorTests.java @@ -28,10 +28,12 @@ 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 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; @@ -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>) 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>) health.getDetails().get("endpoints")).hasSize(2); - then(cluster).should().diagnostics(); + then(reactiveCluster).should().diagnostics(); } } From 8f598f876bf9ab82ff3de98961ea3a0da2b13e66 Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Tue, 27 Sep 2022 08:34:22 +0200 Subject: [PATCH 2/2] Polish "Use non-blocking API in CouchbaseReactiveHealthIndicator" See gh-32505 --- .../actuate/couchbase/CouchbaseReactiveHealthIndicator.java | 3 +-- .../couchbase/CouchbaseReactiveHealthIndicatorTests.java | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/couchbase/CouchbaseReactiveHealthIndicator.java b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/couchbase/CouchbaseReactiveHealthIndicator.java index 363ddc6c9e..da470f16a0 100644 --- a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/couchbase/CouchbaseReactiveHealthIndicator.java +++ b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/couchbase/CouchbaseReactiveHealthIndicator.java @@ -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,7 +45,7 @@ public class CouchbaseReactiveHealthIndicator extends AbstractReactiveHealthIndi @Override protected Mono doHealthCheck(Health.Builder builder) { - return this.cluster.reactive().diagnostics().map(diagnostics -> { + return this.cluster.reactive().diagnostics().map((diagnostics) -> { new CouchbaseHealth(diagnostics).applyTo(builder); return builder.build(); }); diff --git a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/couchbase/CouchbaseReactiveHealthIndicatorTests.java b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/couchbase/CouchbaseReactiveHealthIndicatorTests.java index 0106c56215..5cf0471472 100644 --- a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/couchbase/CouchbaseReactiveHealthIndicatorTests.java +++ b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/couchbase/CouchbaseReactiveHealthIndicatorTests.java @@ -30,10 +30,10 @@ 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; -import reactor.core.publisher.Mono; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.BDDMockito.given;