diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/couchbase/CouchbaseHealthIndicatorAutoConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/couchbase/CouchbaseHealthIndicatorAutoConfiguration.java index 3b6d9c0294..cc1c2b839b 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/couchbase/CouchbaseHealthIndicatorAutoConfiguration.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/couchbase/CouchbaseHealthIndicatorAutoConfiguration.java @@ -17,7 +17,7 @@ package org.springframework.boot.actuate.autoconfigure.couchbase; import java.util.Map; -import com.couchbase.client.java.Bucket; +import com.couchbase.client.java.Cluster; import org.springframework.boot.actuate.autoconfigure.health.CompositeHealthIndicatorConfiguration; import org.springframework.boot.actuate.autoconfigure.health.ConditionalOnEnabledHealthIndicator; @@ -31,11 +31,8 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.couchbase.CouchbaseAutoConfiguration; -import org.springframework.boot.autoconfigure.data.couchbase.CouchbaseDataAutoConfiguration; -import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import org.springframework.data.couchbase.core.CouchbaseOperations; /** * {@link EnableAutoConfiguration Auto-configuration} for @@ -43,42 +40,33 @@ import org.springframework.data.couchbase.core.CouchbaseOperations; * * @author EddĂș MelĂ©ndez * @author Stephane Nicoll - * @since 2.1.0 + * @author Andy Wilkinson Nicoll + * @since 2.0.0 */ @Configuration -@ConditionalOnClass({ Bucket.class, CouchbaseOperations.class }) -@ConditionalOnBean(CouchbaseOperations.class) +@ConditionalOnClass(Cluster.class) +@ConditionalOnBean(Cluster.class) @ConditionalOnEnabledHealthIndicator("couchbase") @AutoConfigureBefore(HealthIndicatorAutoConfiguration.class) -@AutoConfigureAfter({ CouchbaseAutoConfiguration.class, - CouchbaseDataAutoConfiguration.class, - CouchbaseReactiveHealthIndicatorAutoConfiguration.class }) -@EnableConfigurationProperties(CouchbaseHealthIndicatorProperties.class) -public class CouchbaseHealthIndicatorAutoConfiguration extends - CompositeHealthIndicatorConfiguration { +@AutoConfigureAfter(CouchbaseAutoConfiguration.class) +public class CouchbaseHealthIndicatorAutoConfiguration + extends CompositeHealthIndicatorConfiguration { - private final Map couchbaseOperations; + private final Map clusters; - private final CouchbaseHealthIndicatorProperties properties; - - public CouchbaseHealthIndicatorAutoConfiguration( - Map couchbaseOperations, - CouchbaseHealthIndicatorProperties properties) { - this.couchbaseOperations = couchbaseOperations; - this.properties = properties; + public CouchbaseHealthIndicatorAutoConfiguration(Map clusters) { + this.clusters = clusters; } @Bean @ConditionalOnMissingBean(name = "couchbaseHealthIndicator") public HealthIndicator couchbaseHealthIndicator() { - return createHealthIndicator(this.couchbaseOperations); + return createHealthIndicator(this.clusters); } @Override - protected CouchbaseHealthIndicator createHealthIndicator( - CouchbaseOperations couchbaseOperations) { - return new CouchbaseHealthIndicator(couchbaseOperations, - this.properties.getTimeout()); + protected CouchbaseHealthIndicator createHealthIndicator(Cluster cluster) { + return new CouchbaseHealthIndicator(cluster); } } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/couchbase/CouchbaseHealthIndicatorProperties.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/couchbase/CouchbaseHealthIndicatorProperties.java deleted file mode 100644 index 2b4c3162a2..0000000000 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/couchbase/CouchbaseHealthIndicatorProperties.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright 2012-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.boot.actuate.autoconfigure.couchbase; - -import java.time.Duration; - -import org.springframework.boot.actuate.couchbase.CouchbaseHealthIndicator; -import org.springframework.boot.context.properties.ConfigurationProperties; - -/** - * Configuration properties for {@link CouchbaseHealthIndicator}. - * - * @author Stephane Nicoll - * @since 2.0.5 - */ -@ConfigurationProperties(prefix = "management.health.couchbase") -public class CouchbaseHealthIndicatorProperties { - - /** - * Timeout for getting the Bucket information from the server. - */ - private Duration timeout = Duration.ofMillis(1000); - - public Duration getTimeout() { - return this.timeout; - } - - public void setTimeout(Duration timeout) { - this.timeout = timeout; - } - -} diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/couchbase/CouchbaseReactiveHealthIndicatorAutoConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/couchbase/CouchbaseReactiveHealthIndicatorAutoConfiguration.java index bbd02e0b30..405e09a495 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/couchbase/CouchbaseReactiveHealthIndicatorAutoConfiguration.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/couchbase/CouchbaseReactiveHealthIndicatorAutoConfiguration.java @@ -32,7 +32,6 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.data.couchbase.CouchbaseReactiveDataAutoConfiguration; -import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.data.couchbase.core.RxJavaCouchbaseOperations; @@ -51,19 +50,14 @@ import org.springframework.data.couchbase.core.RxJavaCouchbaseOperations; @ConditionalOnEnabledHealthIndicator("couchbase") @AutoConfigureBefore(HealthIndicatorAutoConfiguration.class) @AutoConfigureAfter(CouchbaseReactiveDataAutoConfiguration.class) -@EnableConfigurationProperties(CouchbaseHealthIndicatorProperties.class) public class CouchbaseReactiveHealthIndicatorAutoConfiguration extends CompositeReactiveHealthIndicatorConfiguration { private final Map couchbaseOperations; - private final CouchbaseHealthIndicatorProperties properties; - public CouchbaseReactiveHealthIndicatorAutoConfiguration( - Map couchbaseOperations, - CouchbaseHealthIndicatorProperties properties) { + Map couchbaseOperations) { this.couchbaseOperations = couchbaseOperations; - this.properties = properties; } @Bean @@ -75,8 +69,7 @@ public class CouchbaseReactiveHealthIndicatorAutoConfiguration extends @Override protected CouchbaseReactiveHealthIndicator createHealthIndicator( RxJavaCouchbaseOperations couchbaseOperations) { - return new CouchbaseReactiveHealthIndicator(couchbaseOperations, - this.properties.getTimeout()); + return new CouchbaseReactiveHealthIndicator(couchbaseOperations); } } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/couchbase/CouchbaseHealthIndicatorAutoConfigurationTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/couchbase/CouchbaseHealthIndicatorAutoConfigurationTests.java index 19ae1f8490..527dc9b513 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/couchbase/CouchbaseHealthIndicatorAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/couchbase/CouchbaseHealthIndicatorAutoConfigurationTests.java @@ -15,6 +15,7 @@ */ package org.springframework.boot.actuate.autoconfigure.couchbase; +import com.couchbase.client.java.Cluster; import org.junit.Test; import org.springframework.boot.actuate.autoconfigure.health.HealthIndicatorAutoConfiguration; @@ -25,8 +26,6 @@ import org.springframework.boot.autoconfigure.AutoConfigurations; import org.springframework.boot.test.context.runner.ApplicationContextRunner; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import org.springframework.data.couchbase.core.CouchbaseOperations; -import org.springframework.test.util.ReflectionTestUtils; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; @@ -52,17 +51,6 @@ public class CouchbaseHealthIndicatorAutoConfigurationTests { .doesNotHaveBean(ApplicationHealthIndicator.class)); } - @Test - public void runWithCustomTimeoutShouldCreateIndicator() { - this.contextRunner.withPropertyValues("management.health.couchbase.timeout=2s") - .run((context) -> { - assertThat(context).hasSingleBean(CouchbaseHealthIndicator.class); - assertThat(ReflectionTestUtils.getField( - context.getBean(CouchbaseHealthIndicator.class), "timeout")) - .isEqualTo(2000L); - }); - } - @Test public void runWhenDisabledShouldNotCreateIndicator() { this.contextRunner.withPropertyValues("management.health.couchbase.enabled:false") @@ -75,8 +63,8 @@ public class CouchbaseHealthIndicatorAutoConfigurationTests { protected static class CouchbaseMockConfiguration { @Bean - public CouchbaseOperations couchbaseOperations() { - return mock(CouchbaseOperations.class); + public Cluster cluster() { + return mock(Cluster.class); } } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/couchbase/CouchbaseReactiveHealthIndicatorAutoConfigurationTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/couchbase/CouchbaseReactiveHealthIndicatorAutoConfigurationTests.java index e558f32d4a..51ffb334da 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/couchbase/CouchbaseReactiveHealthIndicatorAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/couchbase/CouchbaseReactiveHealthIndicatorAutoConfigurationTests.java @@ -15,8 +15,6 @@ */ package org.springframework.boot.actuate.autoconfigure.couchbase; -import java.time.Duration; - import org.junit.Test; import org.springframework.boot.actuate.autoconfigure.health.HealthIndicatorAutoConfiguration; @@ -53,18 +51,6 @@ public class CouchbaseReactiveHealthIndicatorAutoConfigurationTests { .doesNotHaveBean(ApplicationHealthIndicator.class)); } - @Test - public void runWithCustomTimeoutShouldCreateIndicator() { - this.contextRunner.withPropertyValues("management.health.couchbase.timeout=2s") - .run((context) -> { - assertThat(context) - .hasSingleBean(CouchbaseReactiveHealthIndicator.class); - assertThat(context.getBean(CouchbaseReactiveHealthIndicator.class)) - .hasFieldOrPropertyWithValue("timeout", - Duration.ofSeconds(2)); - }); - } - @Test public void runWhenDisabledShouldNotCreateIndicator() { this.contextRunner.withPropertyValues("management.health.couchbase.enabled:false") diff --git a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/couchbase/CouchbaseHealthIndicator.java b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/couchbase/CouchbaseHealthIndicator.java index 742ba896d7..22f7757e47 100644 --- a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/couchbase/CouchbaseHealthIndicator.java +++ b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/couchbase/CouchbaseHealthIndicator.java @@ -16,19 +16,19 @@ package org.springframework.boot.actuate.couchbase; -import java.time.Duration; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.TimeoutException; +import java.util.HashMap; +import java.util.Map; +import java.util.stream.Collectors; -import com.couchbase.client.java.bucket.BucketInfo; -import com.couchbase.client.java.cluster.ClusterInfo; +import com.couchbase.client.core.message.internal.DiagnosticsReport; +import com.couchbase.client.core.message.internal.EndpointHealth; +import com.couchbase.client.core.state.LifecycleState; +import com.couchbase.client.java.Cluster; import org.springframework.boot.actuate.health.AbstractHealthIndicator; import org.springframework.boot.actuate.health.Health; import org.springframework.boot.actuate.health.HealthIndicator; -import org.springframework.data.couchbase.core.CouchbaseOperations; import org.springframework.util.Assert; -import org.springframework.util.StringUtils; /** * {@link HealthIndicator} for Couchbase. @@ -39,46 +39,52 @@ import org.springframework.util.StringUtils; */ public class CouchbaseHealthIndicator extends AbstractHealthIndicator { - private final CouchbaseOperations operations; - - private final long timeout; + private final Cluster cluster; /** - * Create an indicator with the specified {@link CouchbaseOperations} and - * {@code timeout}. - * @param couchbaseOperations the couchbase operations - * @param timeout the request timeout + * Create an indicator with the specified {@link Cluster}. + * @param cluster the Couchbase Cluster + * @since 2.0.6 */ - public CouchbaseHealthIndicator(CouchbaseOperations couchbaseOperations, - Duration timeout) { + public CouchbaseHealthIndicator(Cluster cluster) { super("Couchbase health check failed"); - Assert.notNull(couchbaseOperations, "CouchbaseOperations must not be null"); - Assert.notNull(timeout, "Timeout must not be null"); - this.operations = couchbaseOperations; - this.timeout = timeout.toMillis(); + Assert.notNull(cluster, "Cluster must not be null"); + this.cluster = cluster; } @Override protected void doHealthCheck(Health.Builder builder) throws Exception { - ClusterInfo cluster = this.operations.getCouchbaseClusterInfo(); - BucketInfo bucket = getBucketInfo(); - String versions = StringUtils - .collectionToCommaDelimitedString(cluster.getAllVersions()); - String nodes = StringUtils.collectionToCommaDelimitedString(bucket.nodeList()); - builder.up().withDetail("versions", versions).withDetail("nodes", nodes); + DiagnosticsReport diagnostics = this.cluster.diagnostics(); + if (isCouchbaseUp(diagnostics)) { + builder.up(); + } + else { + builder.down(); + } + builder.withDetail("sdk", diagnostics.sdk()); + builder.withDetail("endpoints", diagnostics.endpoints().stream() + .map(this::describe).collect(Collectors.toList())); } - private BucketInfo getBucketInfo() throws Exception { - try { - return this.operations.getCouchbaseBucket().bucketManager().info(this.timeout, - TimeUnit.MILLISECONDS); - } - catch (RuntimeException ex) { - if (ex.getCause() instanceof TimeoutException) { - throw (TimeoutException) ex.getCause(); + private boolean isCouchbaseUp(DiagnosticsReport diagnostics) { + for (EndpointHealth health : diagnostics.endpoints()) { + LifecycleState state = health.state(); + if (state != LifecycleState.CONNECTED && state != LifecycleState.IDLE) { + return false; } - throw ex; } + return true; + } + + private Map describe(EndpointHealth endpointHealth) { + Map map = new HashMap<>(); + map.put("id", endpointHealth.id()); + map.put("lastActivity", endpointHealth.lastActivity()); + map.put("local", endpointHealth.local().toString()); + map.put("remote", endpointHealth.remote().toString()); + map.put("state", endpointHealth.state()); + map.put("type", endpointHealth.type()); + return map; } } 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 218cb26a2a..854368651e 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 @@ -15,9 +15,6 @@ */ package org.springframework.boot.actuate.couchbase; -import java.time.Duration; -import java.util.concurrent.TimeUnit; - import com.couchbase.client.java.bucket.BucketInfo; import com.couchbase.client.java.cluster.ClusterInfo; import reactor.core.publisher.Mono; @@ -42,17 +39,13 @@ public class CouchbaseReactiveHealthIndicator extends AbstractReactiveHealthIndi private final RxJavaCouchbaseOperations couchbaseOperations; - private final Duration timeout; - /** * Create a new {@link CouchbaseReactiveHealthIndicator} instance. * @param couchbaseOperations the reactive couchbase operations - * @param timeout the request timeout */ - public CouchbaseReactiveHealthIndicator(RxJavaCouchbaseOperations couchbaseOperations, - Duration timeout) { + public CouchbaseReactiveHealthIndicator( + RxJavaCouchbaseOperations couchbaseOperations) { this.couchbaseOperations = couchbaseOperations; - this.timeout = timeout; } @Override @@ -61,8 +54,7 @@ public class CouchbaseReactiveHealthIndicator extends AbstractReactiveHealthIndi String versions = StringUtils .collectionToCommaDelimitedString(cluster.getAllVersions()); Observable bucket = this.couchbaseOperations.getCouchbaseBucket() - .bucketManager().async().info() - .timeout(this.timeout.toMillis(), TimeUnit.MILLISECONDS); + .bucketManager().async().info(); Single health = bucket.map(BucketInfo::nodeList) .map(StringUtils::collectionToCommaDelimitedString) .map((nodes) -> builder.up().withDetail("versions", versions) 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 bacd129116..701e46206f 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 @@ -16,26 +16,22 @@ package org.springframework.boot.actuate.couchbase; -import java.net.InetAddress; -import java.net.UnknownHostException; -import java.time.Duration; -import java.util.Collections; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.TimeoutException; +import java.net.InetSocketAddress; +import java.util.Arrays; +import java.util.List; +import java.util.Map; -import com.couchbase.client.java.Bucket; -import com.couchbase.client.java.bucket.BucketInfo; -import com.couchbase.client.java.bucket.BucketManager; -import com.couchbase.client.java.cluster.ClusterInfo; -import com.couchbase.client.java.util.features.Version; +import com.couchbase.client.core.message.internal.DiagnosticsReport; +import com.couchbase.client.core.message.internal.EndpointHealth; +import com.couchbase.client.core.service.ServiceType; +import com.couchbase.client.core.state.LifecycleState; +import com.couchbase.client.java.Cluster; import org.junit.Test; import org.springframework.boot.actuate.health.Health; import org.springframework.boot.actuate.health.Status; -import org.springframework.data.couchbase.core.CouchbaseOperations; import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.entry; import static org.mockito.BDDMockito.given; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; @@ -49,57 +45,47 @@ import static org.mockito.Mockito.verify; public class CouchbaseHealthIndicatorTests { @Test - public void couchbaseIsUp() throws UnknownHostException { - BucketInfo bucketInfo = mock(BucketInfo.class); - given(bucketInfo.nodeList()).willReturn( - Collections.singletonList(InetAddress.getByName("127.0.0.1"))); - BucketManager bucketManager = mock(BucketManager.class); - given(bucketManager.info(2000, TimeUnit.MILLISECONDS)).willReturn(bucketInfo); - Bucket bucket = mock(Bucket.class); - given(bucket.bucketManager()).willReturn(bucketManager); - ClusterInfo clusterInfo = mock(ClusterInfo.class); - given(clusterInfo.getAllVersions()) - .willReturn(Collections.singletonList(new Version(1, 2, 3))); - CouchbaseOperations couchbaseOperations = mock(CouchbaseOperations.class); - given(couchbaseOperations.getCouchbaseBucket()).willReturn(bucket); - given(couchbaseOperations.getCouchbaseClusterInfo()).willReturn(clusterInfo); - CouchbaseHealthIndicator healthIndicator = new CouchbaseHealthIndicator( - couchbaseOperations, Duration.ofSeconds(2)); + @SuppressWarnings("unchecked") + public void couchbaseClusterIsUp() { + Cluster cluster = mock(Cluster.class); + CouchbaseHealthIndicator healthIndicator = new CouchbaseHealthIndicator(cluster); + List endpoints = Arrays.asList(new EndpointHealth( + ServiceType.BINARY, LifecycleState.CONNECTED, new InetSocketAddress(0), + new InetSocketAddress(0), 1234, "endpoint-1")); + DiagnosticsReport diagnostics = new DiagnosticsReport(endpoints, "test-sdk", + "test-id", null); + given(cluster.diagnostics()).willReturn(diagnostics); Health health = healthIndicator.health(); assertThat(health.getStatus()).isEqualTo(Status.UP); - assertThat(health.getDetails()).containsOnly(entry("versions", "1.2.3"), - entry("nodes", "/127.0.0.1")); - verify(clusterInfo).getAllVersions(); - verify(bucketInfo).nodeList(); + assertThat(health.getDetails()).containsEntry("sdk", "test-sdk"); + assertThat(health.getDetails()).containsKey("endpoints"); + assertThat((List>) health.getDetails().get("endpoints")) + .hasSize(1); + verify(cluster).diagnostics(); } @Test - public void couchbaseTimeout() { - BucketManager bucketManager = mock(BucketManager.class); - given(bucketManager.info(1500, TimeUnit.MILLISECONDS)).willThrow( - new RuntimeException(new TimeoutException("timeout, expected"))); - Bucket bucket = mock(Bucket.class); - given(bucket.bucketManager()).willReturn(bucketManager); - CouchbaseOperations couchbaseOperations = mock(CouchbaseOperations.class); - given(couchbaseOperations.getCouchbaseBucket()).willReturn(bucket); - CouchbaseHealthIndicator healthIndicator = new CouchbaseHealthIndicator( - couchbaseOperations, Duration.ofMillis(1500)); - Health health = healthIndicator.health(); - assertThat((String) health.getDetails().get("error")) - .contains("timeout, expected"); - } - - @Test - public void couchbaseIsDown() { - CouchbaseOperations couchbaseOperations = mock(CouchbaseOperations.class); - given(couchbaseOperations.getCouchbaseClusterInfo()) - .willThrow(new IllegalStateException("test, expected")); - CouchbaseHealthIndicator healthIndicator = new CouchbaseHealthIndicator( - couchbaseOperations, Duration.ofSeconds(1)); + @SuppressWarnings("unchecked") + public void couchbaseClusterIsDown() { + Cluster cluster = mock(Cluster.class); + CouchbaseHealthIndicator healthIndicator = new CouchbaseHealthIndicator(cluster); + List endpoints = Arrays.asList( + new EndpointHealth(ServiceType.BINARY, LifecycleState.CONNECTED, + new InetSocketAddress(0), new InetSocketAddress(0), 1234, + "endpoint-1"), + new EndpointHealth(ServiceType.BINARY, LifecycleState.CONNECTING, + new InetSocketAddress(0), new InetSocketAddress(0), 1234, + "endpoint-2")); + DiagnosticsReport diagnostics = new DiagnosticsReport(endpoints, "test-sdk", + "test-id", null); + given(cluster.diagnostics()).willReturn(diagnostics); Health health = healthIndicator.health(); assertThat(health.getStatus()).isEqualTo(Status.DOWN); - assertThat((String) health.getDetails().get("error")).contains("test, expected"); - verify(couchbaseOperations).getCouchbaseClusterInfo(); + assertThat(health.getDetails()).containsEntry("sdk", "test-sdk"); + assertThat(health.getDetails()).containsKey("endpoints"); + assertThat((List>) health.getDetails().get("endpoints")) + .hasSize(2); + verify(cluster).diagnostics(); } } 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 4edd07b700..8b714a791b 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 @@ -16,10 +16,7 @@ package org.springframework.boot.actuate.couchbase; import java.net.InetAddress; -import java.time.Duration; import java.util.Arrays; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.TimeoutException; import com.couchbase.client.java.Bucket; import com.couchbase.client.java.bucket.AsyncBucketManager; @@ -60,7 +57,7 @@ public class CouchbaseReactiveHealthIndicatorTests { given(node2Address.toString()).willReturn("127.0.0.2"); given(asyncBucketManager.info()).willReturn(Observable.just(info)); CouchbaseReactiveHealthIndicator couchbaseReactiveHealthIndicator = new CouchbaseReactiveHealthIndicator( - rxJavaCouchbaseOperations, Duration.ofSeconds(2)); + rxJavaCouchbaseOperations); Mono health = couchbaseReactiveHealthIndicator.health(); StepVerifier.create(health).consumeNextWith((h) -> { assertThat(h.getStatus()).isEqualTo(Status.UP); @@ -70,25 +67,6 @@ public class CouchbaseReactiveHealthIndicatorTests { }).verifyComplete(); } - @Test - public void couchbaseTimeout() { - RxJavaCouchbaseOperations rxJavaCouchbaseOperations = mock( - RxJavaCouchbaseOperations.class); - AsyncBucketManager asyncBucketManager = mockAsyncBucketManager( - rxJavaCouchbaseOperations); - given(asyncBucketManager.info()).willReturn( - Observable.just(mock(BucketInfo.class)).delay(20, TimeUnit.MILLISECONDS)); - CouchbaseReactiveHealthIndicator couchbaseReactiveHealthIndicator = new CouchbaseReactiveHealthIndicator( - rxJavaCouchbaseOperations, Duration.ofMillis(10)); - Mono health = couchbaseReactiveHealthIndicator.health(); - StepVerifier.create(health).consumeNextWith((h) -> { - assertThat(h.getStatus()).isEqualTo(Status.DOWN); - assertThat(h.getDetails()).containsOnlyKeys("error"); - assertThat(h.getDetails().get("error")).asString() - .contains(TimeoutException.class.getName()); - }).verifyComplete(); - } - @Test public void couchbaseIsDown() { RxJavaCouchbaseOperations rxJavaCouchbaseOperations = mock( @@ -98,7 +76,7 @@ public class CouchbaseReactiveHealthIndicatorTests { given(asyncBucketManager.info()) .willReturn(Observable.error(new TranscodingException("Failure"))); CouchbaseReactiveHealthIndicator couchbaseReactiveHealthIndicator = new CouchbaseReactiveHealthIndicator( - rxJavaCouchbaseOperations, Duration.ofSeconds(2)); + rxJavaCouchbaseOperations); Mono health = couchbaseReactiveHealthIndicator.health(); StepVerifier.create(health).consumeNextWith((h) -> { assertThat(h.getStatus()).isEqualTo(Status.DOWN); diff --git a/spring-boot-project/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc b/spring-boot-project/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc index 522d577c1a..47af1609fa 100644 --- a/spring-boot-project/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc +++ b/spring-boot-project/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc @@ -1346,7 +1346,6 @@ content into your application. Rather, pick only the properties that you need. management.health.db.enabled=true # Whether to enable database health check. management.health.cassandra.enabled=true # Whether to enable Cassandra health check. management.health.couchbase.enabled=true # Whether to enable Couchbase health check. - management.health.couchbase.timeout=1000ms # Timeout for getting the Bucket information from the server. management.health.defaults.enabled=true # Whether to enable default health indicators. management.health.diskspace.enabled=true # Whether to enable disk space health check. management.health.diskspace.path= # Path used to compute the available disk space.