From fead97695255589dab37e5d711cc98c1e29ffa1d Mon Sep 17 00:00:00 2001 From: Scott Frederick Date: Wed, 21 Dec 2022 11:48:39 -0600 Subject: [PATCH] Adapt to changes in Couchbase client See gh-33588 --- .../CouchbaseHealthIndicatorTests.java | 17 ++++++++++------- .../CouchbaseReactiveHealthIndicatorTests.java | 17 ++++++++++------- .../couchbase/CouchbaseAutoConfiguration.java | 15 ++++++--------- 3 files changed, 26 insertions(+), 23 deletions(-) diff --git a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/couchbase/CouchbaseHealthIndicatorTests.java b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/couchbase/CouchbaseHealthIndicatorTests.java index 9fb13227903b..7d2ab2da49b5 100644 --- a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/couchbase/CouchbaseHealthIndicatorTests.java +++ b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/couchbase/CouchbaseHealthIndicatorTests.java @@ -24,6 +24,7 @@ import com.couchbase.client.core.diagnostics.DiagnosticsResult; import com.couchbase.client.core.diagnostics.EndpointDiagnostics; +import com.couchbase.client.core.endpoint.CircuitBreaker; import com.couchbase.client.core.endpoint.EndpointState; import com.couchbase.client.core.service.ServiceType; import com.couchbase.client.java.Cluster; @@ -51,9 +52,9 @@ void couchbaseClusterIsUp() { Cluster cluster = mock(Cluster.class); CouchbaseHealthIndicator healthIndicator = new CouchbaseHealthIndicator(cluster); Map> endpoints = Collections.singletonMap(ServiceType.KV, - 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"), Optional.empty()))); + Collections.singletonList(new EndpointDiagnostics(ServiceType.KV, EndpointState.CONNECTED, + CircuitBreaker.State.DISABLED, "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); @@ -72,10 +73,12 @@ void couchbaseClusterIsDown() { CouchbaseHealthIndicator healthIndicator = new CouchbaseHealthIndicator(cluster); Map> endpoints = Collections.singletonMap(ServiceType.KV, Arrays.asList( - 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()), - 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()))); + new EndpointDiagnostics(ServiceType.KV, EndpointState.CONNECTED, CircuitBreaker.State.DISABLED, + "127.0.0.1", "127.0.0.1", Optional.empty(), Optional.of(1234L), + Optional.of("endpoint-1"), Optional.empty()), + new EndpointDiagnostics(ServiceType.KV, EndpointState.CONNECTING, CircuitBreaker.State.DISABLED, + "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); Health health = healthIndicator.health(); 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 96907bcb545e..fc1315084378 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 @@ -25,6 +25,7 @@ import com.couchbase.client.core.diagnostics.DiagnosticsResult; import com.couchbase.client.core.diagnostics.EndpointDiagnostics; +import com.couchbase.client.core.endpoint.CircuitBreaker; import com.couchbase.client.core.endpoint.EndpointState; import com.couchbase.client.core.service.ServiceType; import com.couchbase.client.java.Cluster; @@ -51,9 +52,9 @@ void couchbaseClusterIsUp() { Cluster cluster = mock(Cluster.class); CouchbaseReactiveHealthIndicator healthIndicator = new CouchbaseReactiveHealthIndicator(cluster); Map> endpoints = Collections.singletonMap(ServiceType.KV, - 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"), Optional.empty()))); + Collections.singletonList(new EndpointDiagnostics(ServiceType.KV, EndpointState.CONNECTED, + CircuitBreaker.State.DISABLED, "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"); ReactiveCluster reactiveCluster = mock(ReactiveCluster.class); given(reactiveCluster.diagnostics()).willReturn(Mono.just(diagnostics)); @@ -73,10 +74,12 @@ void couchbaseClusterIsDown() { CouchbaseReactiveHealthIndicator healthIndicator = new CouchbaseReactiveHealthIndicator(cluster); Map> endpoints = Collections.singletonMap(ServiceType.KV, Arrays.asList( - 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()), - 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()))); + new EndpointDiagnostics(ServiceType.KV, EndpointState.CONNECTED, CircuitBreaker.State.DISABLED, + "127.0.0.1", "127.0.0.1", Optional.empty(), Optional.of(1234L), + Optional.of("endpoint-1"), Optional.empty()), + new EndpointDiagnostics(ServiceType.KV, EndpointState.CONNECTING, CircuitBreaker.State.DISABLED, + "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"); ReactiveCluster reactiveCluster = mock(ReactiveCluster.class); given(reactiveCluster.diagnostics()).willReturn(Mono.just(diagnostics)); diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/couchbase/CouchbaseAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/couchbase/CouchbaseAutoConfiguration.java index 64b2c57714a1..76800e3f134f 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/couchbase/CouchbaseAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/couchbase/CouchbaseAutoConfiguration.java @@ -23,9 +23,6 @@ import javax.net.ssl.KeyManagerFactory; import javax.net.ssl.TrustManagerFactory; -import com.couchbase.client.core.env.IoConfig; -import com.couchbase.client.core.env.SecurityConfig; -import com.couchbase.client.core.env.TimeoutConfig; import com.couchbase.client.java.Cluster; import com.couchbase.client.java.ClusterOptions; import com.couchbase.client.java.codec.JacksonJsonSerializer; @@ -83,16 +80,16 @@ public Cluster couchbaseCluster(CouchbaseProperties properties, ClusterEnvironme private ClusterEnvironment.Builder initializeEnvironmentBuilder(CouchbaseProperties properties) { ClusterEnvironment.Builder builder = ClusterEnvironment.builder(); Timeouts timeouts = properties.getEnv().getTimeouts(); - builder.timeoutConfig(TimeoutConfig.kvTimeout(timeouts.getKeyValue()).analyticsTimeout(timeouts.getAnalytics()) - .kvDurableTimeout(timeouts.getKeyValueDurable()).queryTimeout(timeouts.getQuery()) - .viewTimeout(timeouts.getView()).searchTimeout(timeouts.getSearch()) + builder.timeoutConfig((config) -> config.kvTimeout(timeouts.getKeyValue()) + .analyticsTimeout(timeouts.getAnalytics()).kvDurableTimeout(timeouts.getKeyValueDurable()) + .queryTimeout(timeouts.getQuery()).viewTimeout(timeouts.getView()).searchTimeout(timeouts.getSearch()) .managementTimeout(timeouts.getManagement()).connectTimeout(timeouts.getConnect()) .disconnectTimeout(timeouts.getDisconnect())); CouchbaseProperties.Io io = properties.getEnv().getIo(); - builder.ioConfig(IoConfig.maxHttpConnections(io.getMaxEndpoints()).numKvConnections(io.getMinEndpoints()) - .idleHttpConnectionTimeout(io.getIdleHttpConnectionTimeout())); + builder.ioConfig((config) -> config.maxHttpConnections(io.getMaxEndpoints()) + .numKvConnections(io.getMinEndpoints()).idleHttpConnectionTimeout(io.getIdleHttpConnectionTimeout())); if (properties.getEnv().getSsl().getEnabled()) { - builder.securityConfig(SecurityConfig.enableTls(true) + builder.securityConfig((config) -> config.enableTls(true) .trustManagerFactory(getTrustManagerFactory(properties.getEnv().getSsl()))); } return builder;