Commit 91b4dc2f authored by Stephane Nicoll's avatar Stephane Nicoll

Polish "Add reactive health indicator for Couchbase"

Closes gh-13926
parent 20ff0d97
...@@ -46,8 +46,8 @@ import org.springframework.context.annotation.Import; ...@@ -46,8 +46,8 @@ import org.springframework.context.annotation.Import;
@AutoConfigureAfter({ CouchbaseAutoConfiguration.class, @AutoConfigureAfter({ CouchbaseAutoConfiguration.class,
CouchbaseDataAutoConfiguration.class, CouchbaseDataAutoConfiguration.class,
CouchbaseReactiveDataAutoConfiguration.class }) CouchbaseReactiveDataAutoConfiguration.class })
@Import({ CouchbaseHealthIndicatorConfiguration.class, @Import({ CouchbaseReactiveHealthIndicatorConfiguration.class,
CouchbaseReactiveHealthIndicatorConfiguration.class }) CouchbaseHealthIndicatorConfiguration.class })
public class CouchbaseHealthIndicatorAutoConfiguration { public class CouchbaseHealthIndicatorAutoConfiguration {
} }
...@@ -31,8 +31,9 @@ import org.springframework.data.couchbase.core.CouchbaseOperations; ...@@ -31,8 +31,9 @@ import org.springframework.data.couchbase.core.CouchbaseOperations;
/** /**
* Configuration for {@link CouchbaseHealthIndicator}. * Configuration for {@link CouchbaseHealthIndicator}.
* *
* @author Mikalai Lushchytski * @author Eddú Meléndez
* @since 2.1.0 * @author Stephane Nicoll
* @since 2.0.0
*/ */
@Configuration @Configuration
@ConditionalOnClass(CouchbaseOperations.class) @ConditionalOnClass(CouchbaseOperations.class)
......
...@@ -17,34 +17,42 @@ package org.springframework.boot.actuate.autoconfigure.couchbase; ...@@ -17,34 +17,42 @@ package org.springframework.boot.actuate.autoconfigure.couchbase;
import java.util.Map; import java.util.Map;
import reactor.core.publisher.Flux;
import org.springframework.boot.actuate.autoconfigure.health.CompositeReactiveHealthIndicatorConfiguration; import org.springframework.boot.actuate.autoconfigure.health.CompositeReactiveHealthIndicatorConfiguration;
import org.springframework.boot.actuate.couchbase.CouchbaseReactiveHealthIndicator; import org.springframework.boot.actuate.couchbase.CouchbaseReactiveHealthIndicator;
import org.springframework.boot.actuate.health.ReactiveHealthIndicator; import org.springframework.boot.actuate.health.ReactiveHealthIndicator;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.data.couchbase.core.RxJavaCouchbaseOperations; import org.springframework.data.couchbase.core.RxJavaCouchbaseOperations;
/** /**
* Configuration for * Configuration for {@link CouchbaseReactiveHealthIndicator}.
* {@link org.springframework.boot.actuate.couchbase.CouchbaseReactiveHealthIndicator}.
* *
* @author Mikalai Lushchytski * @author Mikalai Lushchytski
* @author Stephane Nicoll
* @since 2.1.0 * @since 2.1.0
*/ */
@Configuration @Configuration
@ConditionalOnClass(RxJavaCouchbaseOperations.class) @ConditionalOnClass({ RxJavaCouchbaseOperations.class, Flux.class })
@ConditionalOnBean(RxJavaCouchbaseOperations.class) @ConditionalOnBean(RxJavaCouchbaseOperations.class)
@EnableConfigurationProperties(CouchbaseHealthIndicatorProperties.class)
public class CouchbaseReactiveHealthIndicatorConfiguration extends public class CouchbaseReactiveHealthIndicatorConfiguration extends
CompositeReactiveHealthIndicatorConfiguration<CouchbaseReactiveHealthIndicator, RxJavaCouchbaseOperations> { CompositeReactiveHealthIndicatorConfiguration<CouchbaseReactiveHealthIndicator, RxJavaCouchbaseOperations> {
private final Map<String, RxJavaCouchbaseOperations> couchbaseOperations; private final Map<String, RxJavaCouchbaseOperations> couchbaseOperations;
private final CouchbaseHealthIndicatorProperties properties;
CouchbaseReactiveHealthIndicatorConfiguration( CouchbaseReactiveHealthIndicatorConfiguration(
Map<String, RxJavaCouchbaseOperations> couchbaseOperations) { Map<String, RxJavaCouchbaseOperations> couchbaseOperations,
CouchbaseHealthIndicatorProperties properties) {
this.couchbaseOperations = couchbaseOperations; this.couchbaseOperations = couchbaseOperations;
this.properties = properties;
} }
@Bean @Bean
...@@ -53,4 +61,11 @@ public class CouchbaseReactiveHealthIndicatorConfiguration extends ...@@ -53,4 +61,11 @@ public class CouchbaseReactiveHealthIndicatorConfiguration extends
return createHealthIndicator(this.couchbaseOperations); return createHealthIndicator(this.couchbaseOperations);
} }
@Override
protected CouchbaseReactiveHealthIndicator createHealthIndicator(
RxJavaCouchbaseOperations couchbaseOperations) {
return new CouchbaseReactiveHealthIndicator(couchbaseOperations,
this.properties.getTimeout());
}
} }
/*
* 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 org.junit.Test;
import org.springframework.boot.actuate.autoconfigure.health.HealthIndicatorAutoConfiguration;
import org.springframework.boot.actuate.couchbase.CouchbaseHealthIndicator;
import org.springframework.boot.actuate.health.ApplicationHealthIndicator;
import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
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;
/**
* Tests for {@link CouchbaseHealthIndicatorAutoConfiguration}.
*
* @author Phillip Webb
* @author Stephane Nicoll
*/
public class CouchbaseHealthIndicatorAutoConfigurationTests {
private ApplicationContextRunner contextRunner = new ApplicationContextRunner()
.withConfiguration(AutoConfigurations.of(CouchbaseConfiguration.class,
CouchbaseHealthIndicatorAutoConfiguration.class,
HealthIndicatorAutoConfiguration.class));
@Test
public void runShouldCreateIndicator() {
this.contextRunner.run((context) -> assertThat(context)
.hasSingleBean(CouchbaseHealthIndicator.class)
.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")
.run((context) -> assertThat(context)
.doesNotHaveBean(CouchbaseHealthIndicator.class)
.hasSingleBean(ApplicationHealthIndicator.class));
}
@Configuration
@AutoConfigureBefore(CouchbaseHealthIndicatorAutoConfiguration.class)
protected static class CouchbaseConfiguration {
@Bean
public CouchbaseOperations couchbaseOperations() {
return mock(CouchbaseOperations.class);
}
}
}
...@@ -26,6 +26,7 @@ import org.springframework.boot.test.context.runner.ApplicationContextRunner; ...@@ -26,6 +26,7 @@ import org.springframework.boot.test.context.runner.ApplicationContextRunner;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.data.couchbase.core.CouchbaseOperations; import org.springframework.data.couchbase.core.CouchbaseOperations;
import org.springframework.test.util.ReflectionTestUtils;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
...@@ -33,7 +34,8 @@ import static org.mockito.Mockito.mock; ...@@ -33,7 +34,8 @@ import static org.mockito.Mockito.mock;
/** /**
* Tests for {@link CouchbaseHealthIndicatorConfiguration}. * Tests for {@link CouchbaseHealthIndicatorConfiguration}.
* *
* @author Mikalai Lushchytski * @author Phillip Webb
* @author Stephane Nicoll
*/ */
public class CouchbaseHealthIndicatorConfigurationTests { public class CouchbaseHealthIndicatorConfigurationTests {
...@@ -50,6 +52,17 @@ public class CouchbaseHealthIndicatorConfigurationTests { ...@@ -50,6 +52,17 @@ public class CouchbaseHealthIndicatorConfigurationTests {
.doesNotHaveBean(ApplicationHealthIndicator.class)); .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 @Test
public void runWhenDisabledShouldNotCreateIndicator() { public void runWhenDisabledShouldNotCreateIndicator() {
this.contextRunner.withPropertyValues("management.health.couchbase.enabled:false") this.contextRunner.withPropertyValues("management.health.couchbase.enabled:false")
......
...@@ -15,6 +15,8 @@ ...@@ -15,6 +15,8 @@
*/ */
package org.springframework.boot.actuate.autoconfigure.couchbase; package org.springframework.boot.actuate.autoconfigure.couchbase;
import java.time.Duration;
import org.junit.Test; import org.junit.Test;
import org.springframework.boot.actuate.autoconfigure.health.HealthIndicatorAutoConfiguration; import org.springframework.boot.actuate.autoconfigure.health.HealthIndicatorAutoConfiguration;
...@@ -50,6 +52,18 @@ public class CouchbaseReactiveHealthIndicatorConfigurationTests { ...@@ -50,6 +52,18 @@ public class CouchbaseReactiveHealthIndicatorConfigurationTests {
.doesNotHaveBean(ApplicationHealthIndicator.class)); .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 @Test
public void runWhenDisabledShouldNotCreateIndicator() { public void runWhenDisabledShouldNotCreateIndicator() {
this.contextRunner.withPropertyValues("management.health.couchbase.enabled:false") this.contextRunner.withPropertyValues("management.health.couchbase.enabled:false")
......
...@@ -61,6 +61,11 @@ ...@@ -61,6 +61,11 @@
<artifactId>micrometer-registry-prometheus</artifactId> <artifactId>micrometer-registry-prometheus</artifactId>
<optional>true</optional> <optional>true</optional>
</dependency> </dependency>
<dependency>
<groupId>io.reactivex</groupId>
<artifactId>rxjava-reactive-streams</artifactId>
<optional>true</optional>
</dependency>
<dependency> <dependency>
<groupId>io.searchbox</groupId> <groupId>io.searchbox</groupId>
<artifactId>jest</artifactId> <artifactId>jest</artifactId>
...@@ -77,11 +82,6 @@ ...@@ -77,11 +82,6 @@
</exclusion> </exclusion>
</exclusions> </exclusions>
</dependency> </dependency>
<dependency>
<groupId>io.reactivex</groupId>
<artifactId>rxjava-reactive-streams</artifactId>
<optional>true</optional>
</dependency>
<dependency> <dependency>
<groupId>javax.cache</groupId> <groupId>javax.cache</groupId>
<artifactId>cache-api</artifactId> <artifactId>cache-api</artifactId>
......
...@@ -15,6 +15,9 @@ ...@@ -15,6 +15,9 @@
*/ */
package org.springframework.boot.actuate.couchbase; 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.bucket.BucketInfo;
import com.couchbase.client.java.cluster.ClusterInfo; import com.couchbase.client.java.cluster.ClusterInfo;
import reactor.core.publisher.Mono; import reactor.core.publisher.Mono;
...@@ -24,27 +27,32 @@ import rx.Single; ...@@ -24,27 +27,32 @@ import rx.Single;
import org.springframework.boot.actuate.health.AbstractReactiveHealthIndicator; import org.springframework.boot.actuate.health.AbstractReactiveHealthIndicator;
import org.springframework.boot.actuate.health.Health; import org.springframework.boot.actuate.health.Health;
import org.springframework.boot.actuate.health.ReactiveHealthIndicator;
import org.springframework.data.couchbase.core.RxJavaCouchbaseOperations; import org.springframework.data.couchbase.core.RxJavaCouchbaseOperations;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
/** /**
* A {@link org.springframework.boot.actuate.health.ReactiveHealthIndicator} for * A {@link ReactiveHealthIndicator} for Couchbase.
* Couchbase.
* *
* @author Mikalai Lushchytski * @author Mikalai Lushchytski
* @author Stephane Nicoll
* @since 2.1.0 * @since 2.1.0
*/ */
public class CouchbaseReactiveHealthIndicator extends AbstractReactiveHealthIndicator { public class CouchbaseReactiveHealthIndicator extends AbstractReactiveHealthIndicator {
private final RxJavaCouchbaseOperations couchbaseOperations; private final RxJavaCouchbaseOperations couchbaseOperations;
private final Duration timeout;
/** /**
* Create a new {@link CouchbaseReactiveHealthIndicator} instance. * Create a new {@link CouchbaseReactiveHealthIndicator} instance.
* @param couchbaseOperations Reactive couchbase client. * @param couchbaseOperations the reactive couchbase operations
* @param timeout the request timeout
*/ */
public CouchbaseReactiveHealthIndicator( public CouchbaseReactiveHealthIndicator(RxJavaCouchbaseOperations couchbaseOperations,
RxJavaCouchbaseOperations couchbaseOperations) { Duration timeout) {
this.couchbaseOperations = couchbaseOperations; this.couchbaseOperations = couchbaseOperations;
this.timeout = timeout;
} }
@Override @Override
...@@ -53,21 +61,14 @@ public class CouchbaseReactiveHealthIndicator extends AbstractReactiveHealthIndi ...@@ -53,21 +61,14 @@ public class CouchbaseReactiveHealthIndicator extends AbstractReactiveHealthIndi
String versions = StringUtils String versions = StringUtils
.collectionToCommaDelimitedString(cluster.getAllVersions()); .collectionToCommaDelimitedString(cluster.getAllVersions());
Observable<BucketInfo> bucket = this.couchbaseOperations.getCouchbaseBucket() Observable<BucketInfo> bucket = this.couchbaseOperations.getCouchbaseBucket()
.bucketManager().async().info(); .bucketManager().async().info()
.timeout(this.timeout.toMillis(), TimeUnit.MILLISECONDS);
Single<Health> health = bucket.map(BucketInfo::nodeList) Single<Health> health = bucket.map(BucketInfo::nodeList)
.map(StringUtils::collectionToCommaDelimitedString) .map(StringUtils::collectionToCommaDelimitedString)
.map((nodes) -> up(builder, versions, nodes)) .map((nodes) -> builder.up().withDetail("versions", versions)
.onErrorReturn((error) -> down(builder, error)).toSingle(); .withDetail("nodes", nodes).build())
.toSingle();
return Mono.from(RxReactiveStreams.toPublisher(health)); return Mono.from(RxReactiveStreams.toPublisher(health));
} }
private Health up(Health.Builder builder, String versions, String nodes) {
return builder.up().withDetail("versions", versions).withDetail("nodes", nodes)
.build();
}
private Health down(Health.Builder builder, Throwable error) {
return builder.down(error).build();
}
} }
...@@ -16,8 +16,10 @@ ...@@ -16,8 +16,10 @@
package org.springframework.boot.actuate.couchbase; package org.springframework.boot.actuate.couchbase;
import java.net.InetAddress; import java.net.InetAddress;
import java.time.Duration;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import com.couchbase.client.java.Bucket; import com.couchbase.client.java.Bucket;
import com.couchbase.client.java.bucket.AsyncBucketManager; import com.couchbase.client.java.bucket.AsyncBucketManager;
...@@ -45,32 +47,20 @@ import static org.mockito.Mockito.mock; ...@@ -45,32 +47,20 @@ import static org.mockito.Mockito.mock;
public class CouchbaseReactiveHealthIndicatorTests { public class CouchbaseReactiveHealthIndicatorTests {
@Test @Test
public void testCouchbaseIsUp() { public void couchbaseIsUp() {
ClusterInfo clusterInfo = mock(ClusterInfo.class);
RxJavaCouchbaseOperations rxJavaCouchbaseOperations = mock( RxJavaCouchbaseOperations rxJavaCouchbaseOperations = mock(
RxJavaCouchbaseOperations.class); RxJavaCouchbaseOperations.class);
given(rxJavaCouchbaseOperations.getCouchbaseClusterInfo()) AsyncBucketManager asyncBucketManager = mockAsyncBucketManager(
.willReturn(clusterInfo); rxJavaCouchbaseOperations);
given(clusterInfo.getAllVersions())
.willReturn(Arrays.asList(new Version(5, 5, 0), new Version(6, 0, 0)));
Bucket bucket = mock(Bucket.class);
BucketManager bucketManager = mock(BucketManager.class);
AsyncBucketManager asyncBucketManager = mock(AsyncBucketManager.class);
given(rxJavaCouchbaseOperations.getCouchbaseBucket()).willReturn(bucket);
given(bucket.bucketManager()).willReturn(bucketManager);
given(bucketManager.async()).willReturn(asyncBucketManager);
BucketInfo info = mock(BucketInfo.class); BucketInfo info = mock(BucketInfo.class);
given(asyncBucketManager.info()).willReturn(Observable.just(info));
InetAddress node1Address = mock(InetAddress.class); InetAddress node1Address = mock(InetAddress.class);
InetAddress node2Address = mock(InetAddress.class); InetAddress node2Address = mock(InetAddress.class);
given(info.nodeList()).willReturn(Arrays.asList(node1Address, node2Address)); given(info.nodeList()).willReturn(Arrays.asList(node1Address, node2Address));
given(node1Address.toString()).willReturn("127.0.0.1"); given(node1Address.toString()).willReturn("127.0.0.1");
given(node2Address.toString()).willReturn("127.0.0.2"); given(node2Address.toString()).willReturn("127.0.0.2");
given(asyncBucketManager.info()).willReturn(Observable.just(info));
CouchbaseReactiveHealthIndicator couchbaseReactiveHealthIndicator = new CouchbaseReactiveHealthIndicator( CouchbaseReactiveHealthIndicator couchbaseReactiveHealthIndicator = new CouchbaseReactiveHealthIndicator(
rxJavaCouchbaseOperations); rxJavaCouchbaseOperations, Duration.ofSeconds(2));
Mono<Health> health = couchbaseReactiveHealthIndicator.health(); Mono<Health> health = couchbaseReactiveHealthIndicator.health();
StepVerifier.create(health).consumeNextWith((h) -> { StepVerifier.create(health).consumeNextWith((h) -> {
assertThat(h.getStatus()).isEqualTo(Status.UP); assertThat(h.getStatus()).isEqualTo(Status.UP);
...@@ -81,25 +71,34 @@ public class CouchbaseReactiveHealthIndicatorTests { ...@@ -81,25 +71,34 @@ public class CouchbaseReactiveHealthIndicatorTests {
} }
@Test @Test
public void testCouchbaseIsDown() { public void couchbaseTimeout() {
ClusterInfo clusterInfo = mock(ClusterInfo.class);
RxJavaCouchbaseOperations rxJavaCouchbaseOperations = mock( RxJavaCouchbaseOperations rxJavaCouchbaseOperations = mock(
RxJavaCouchbaseOperations.class); RxJavaCouchbaseOperations.class);
given(rxJavaCouchbaseOperations.getCouchbaseClusterInfo()) AsyncBucketManager asyncBucketManager = mockAsyncBucketManager(
.willReturn(clusterInfo); rxJavaCouchbaseOperations);
given(clusterInfo.getAllVersions()) given(asyncBucketManager.info()).willReturn(
.willReturn(Collections.singletonList(new Version(5, 5, 0))); Observable.just(mock(BucketInfo.class)).delay(20, TimeUnit.MILLISECONDS));
BucketManager bucketManager = mock(BucketManager.class); CouchbaseReactiveHealthIndicator couchbaseReactiveHealthIndicator = new CouchbaseReactiveHealthIndicator(
AsyncBucketManager asyncBucketManager = mock(AsyncBucketManager.class); rxJavaCouchbaseOperations, Duration.ofMillis(10));
Bucket bucket = mock(Bucket.class); Mono<Health> health = couchbaseReactiveHealthIndicator.health();
given(rxJavaCouchbaseOperations.getCouchbaseBucket()).willReturn(bucket); StepVerifier.create(health).consumeNextWith((h) -> {
given(bucket.bucketManager()).willReturn(bucketManager); assertThat(h.getStatus()).isEqualTo(Status.DOWN);
given(bucketManager.async()).willReturn(asyncBucketManager); assertThat(h.getDetails()).containsOnlyKeys("error");
assertThat(h.getDetails().get("error")).asString()
.contains(TimeoutException.class.getName());
}).verifyComplete();
}
@Test
public void couchbaseIsDown() {
RxJavaCouchbaseOperations rxJavaCouchbaseOperations = mock(
RxJavaCouchbaseOperations.class);
AsyncBucketManager asyncBucketManager = mockAsyncBucketManager(
rxJavaCouchbaseOperations);
given(asyncBucketManager.info()) given(asyncBucketManager.info())
.willReturn(Observable.error(new TranscodingException("Failure"))); .willReturn(Observable.error(new TranscodingException("Failure")));
CouchbaseReactiveHealthIndicator couchbaseReactiveHealthIndicator = new CouchbaseReactiveHealthIndicator( CouchbaseReactiveHealthIndicator couchbaseReactiveHealthIndicator = new CouchbaseReactiveHealthIndicator(
rxJavaCouchbaseOperations); rxJavaCouchbaseOperations, Duration.ofSeconds(2));
Mono<Health> health = couchbaseReactiveHealthIndicator.health(); Mono<Health> health = couchbaseReactiveHealthIndicator.health();
StepVerifier.create(health).consumeNextWith((h) -> { StepVerifier.create(health).consumeNextWith((h) -> {
assertThat(h.getStatus()).isEqualTo(Status.DOWN); assertThat(h.getStatus()).isEqualTo(Status.DOWN);
...@@ -109,4 +108,20 @@ public class CouchbaseReactiveHealthIndicatorTests { ...@@ -109,4 +108,20 @@ public class CouchbaseReactiveHealthIndicatorTests {
}).verifyComplete(); }).verifyComplete();
} }
private AsyncBucketManager mockAsyncBucketManager(
RxJavaCouchbaseOperations rxJavaCouchbaseOperations) {
ClusterInfo clusterInfo = mock(ClusterInfo.class);
given(rxJavaCouchbaseOperations.getCouchbaseClusterInfo())
.willReturn(clusterInfo);
given(clusterInfo.getAllVersions())
.willReturn(Arrays.asList(new Version(5, 5, 0), new Version(6, 0, 0)));
Bucket bucket = mock(Bucket.class);
BucketManager bucketManager = mock(BucketManager.class);
AsyncBucketManager asyncBucketManager = mock(AsyncBucketManager.class);
given(rxJavaCouchbaseOperations.getCouchbaseBucket()).willReturn(bucket);
given(bucket.bucketManager()).willReturn(bucketManager);
given(bucketManager.async()).willReturn(asyncBucketManager);
return asyncBucketManager;
}
} }
...@@ -926,6 +926,9 @@ appropriate: ...@@ -926,6 +926,9 @@ appropriate:
|{sc-spring-boot-actuator}/cassandra/CassandraReactiveHealthIndicator.{sc-ext}[`CassandraReactiveHealthIndicator`] |{sc-spring-boot-actuator}/cassandra/CassandraReactiveHealthIndicator.{sc-ext}[`CassandraReactiveHealthIndicator`]
|Checks that a Cassandra database is up. |Checks that a Cassandra database is up.
|{sc-spring-boot-actuator}/couchbase/CouchbaseReactiveHealthIndicator.{sc-ext}[`CouchbaseReactiveHealthIndicator`]
|Checks that a Couchbase cluster is up.
|{sc-spring-boot-actuator}/mongo/MongoReactiveHealthIndicator.{sc-ext}[`MongoReactiveHealthIndicator`] |{sc-spring-boot-actuator}/mongo/MongoReactiveHealthIndicator.{sc-ext}[`MongoReactiveHealthIndicator`]
|Checks that a Mongo database is up. |Checks that a Mongo database is up.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment