From 74b4ee0ca619e9c463dbebfc15f80cba07532cef Mon Sep 17 00:00:00 2001 From: Mikalai Lushchytski Date: Fri, 27 Jul 2018 15:23:37 +0300 Subject: [PATCH 1/7] added reactive health indicator for Couchbase --- ...hbaseHealthIndicatorAutoConfiguration.java | 42 +++---- ...CouchbaseHealthIndicatorConfiguration.java | 54 +++++++++ ...eReactiveHealthIndicatorConfiguration.java | 54 +++++++++ ...baseHealthIndicatorConfigurationTests.java | 70 +++++++++++ ...tiveHealthIndicatorConfigurationTests.java | 71 ++++++++++++ .../spring-boot-actuator/pom.xml | 5 + .../CouchbaseReactiveHealthIndicator.java | 73 ++++++++++++ ...CouchbaseReactiveHealthIndicatorTests.java | 109 ++++++++++++++++++ 8 files changed, 451 insertions(+), 27 deletions(-) create mode 100644 spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/couchbase/CouchbaseHealthIndicatorConfiguration.java create mode 100644 spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/couchbase/CouchbaseReactiveHealthIndicatorConfiguration.java create mode 100644 spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/couchbase/CouchbaseHealthIndicatorConfigurationTests.java create mode 100644 spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/couchbase/CouchbaseReactiveHealthIndicatorConfigurationTests.java create mode 100644 spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/couchbase/CouchbaseReactiveHealthIndicator.java create mode 100644 spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/couchbase/CouchbaseReactiveHealthIndicatorTests.java 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 252aaea3742b..c593eda6cb21 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 @@ -16,53 +16,41 @@ package org.springframework.boot.actuate.autoconfigure.couchbase; -import java.util.Map; - import com.couchbase.client.java.Bucket; - -import org.springframework.boot.actuate.autoconfigure.health.CompositeHealthIndicatorConfiguration; import org.springframework.boot.actuate.autoconfigure.health.ConditionalOnEnabledHealthIndicator; import org.springframework.boot.actuate.autoconfigure.health.HealthIndicatorAutoConfiguration; import org.springframework.boot.actuate.couchbase.CouchbaseHealthIndicator; -import org.springframework.boot.actuate.health.HealthIndicator; import org.springframework.boot.autoconfigure.AutoConfigureAfter; import org.springframework.boot.autoconfigure.AutoConfigureBefore; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; -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.context.annotation.Bean; +import org.springframework.boot.autoconfigure.data.couchbase.CouchbaseReactiveDataAutoConfiguration; import org.springframework.context.annotation.Configuration; -import org.springframework.data.couchbase.core.CouchbaseOperations; +import org.springframework.context.annotation.Import; /** * {@link EnableAutoConfiguration Auto-configuration} for * {@link CouchbaseHealthIndicator}. * * @author EddĂș MelĂ©ndez + * @author Mikalai Lushchytski * @since 2.0.0 */ @Configuration -@ConditionalOnClass({ CouchbaseOperations.class, Bucket.class }) -@ConditionalOnBean(CouchbaseOperations.class) +@ConditionalOnClass(Bucket.class) @ConditionalOnEnabledHealthIndicator("couchbase") @AutoConfigureBefore(HealthIndicatorAutoConfiguration.class) -@AutoConfigureAfter(CouchbaseDataAutoConfiguration.class) -public class CouchbaseHealthIndicatorAutoConfiguration extends - CompositeHealthIndicatorConfiguration { - - private final Map couchbaseOperations; - - public CouchbaseHealthIndicatorAutoConfiguration( - Map couchbaseOperations) { - this.couchbaseOperations = couchbaseOperations; - } - - @Bean - @ConditionalOnMissingBean(name = "couchbaseHealthIndicator") - public HealthIndicator couchbaseHealthIndicator() { - return createHealthIndicator(this.couchbaseOperations); - } +@AutoConfigureAfter({ + CouchbaseAutoConfiguration.class, + CouchbaseDataAutoConfiguration.class, + CouchbaseReactiveDataAutoConfiguration.class +}) +@Import({ + CouchbaseHealthIndicatorConfiguration.class, + CouchbaseReactiveHealthIndicatorConfiguration.class +}) +public class CouchbaseHealthIndicatorAutoConfiguration { } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/couchbase/CouchbaseHealthIndicatorConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/couchbase/CouchbaseHealthIndicatorConfiguration.java new file mode 100644 index 000000000000..e048080ba0aa --- /dev/null +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/couchbase/CouchbaseHealthIndicatorConfiguration.java @@ -0,0 +1,54 @@ +/* + * 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.springframework.boot.actuate.autoconfigure.health.CompositeHealthIndicatorConfiguration; +import org.springframework.boot.actuate.couchbase.CouchbaseHealthIndicator; +import org.springframework.boot.actuate.health.HealthIndicator; +import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; +import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.data.couchbase.core.CouchbaseOperations; + +import java.util.Map; + +/** + * Configuration for {@link CouchbaseHealthIndicator}. + * + * @author Mikalai Lushchytski + * @since 2.1.0 + */ +@Configuration +@ConditionalOnClass(CouchbaseOperations.class) +@ConditionalOnBean(CouchbaseOperations.class) +public class CouchbaseHealthIndicatorConfiguration extends + CompositeHealthIndicatorConfiguration { + + private final Map couchbaseOperations; + + CouchbaseHealthIndicatorConfiguration( + Map couchbaseOperations) { + this.couchbaseOperations = couchbaseOperations; + } + + @Bean + @ConditionalOnMissingBean(name = "couchbaseHealthIndicator") + public HealthIndicator couchbaseHealthIndicator() { + return createHealthIndicator(this.couchbaseOperations); + } +} diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/couchbase/CouchbaseReactiveHealthIndicatorConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/couchbase/CouchbaseReactiveHealthIndicatorConfiguration.java new file mode 100644 index 000000000000..fce1cece960e --- /dev/null +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/couchbase/CouchbaseReactiveHealthIndicatorConfiguration.java @@ -0,0 +1,54 @@ +/* ++ * 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.springframework.boot.actuate.autoconfigure.health.CompositeReactiveHealthIndicatorConfiguration; +import org.springframework.boot.actuate.couchbase.CouchbaseReactiveHealthIndicator; +import org.springframework.boot.actuate.health.ReactiveHealthIndicator; +import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; +import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.data.couchbase.core.RxJavaCouchbaseOperations; + +import java.util.Map; + +/** + * Configuration for {@link org.springframework.boot.actuate.couchbase.CouchbaseReactiveHealthIndicator}. + * + * @author Mikalai Lushchytski + * @since 2.1.0 + */ +@Configuration +@ConditionalOnClass(RxJavaCouchbaseOperations.class) +@ConditionalOnBean(RxJavaCouchbaseOperations.class) +public class CouchbaseReactiveHealthIndicatorConfiguration extends + CompositeReactiveHealthIndicatorConfiguration { + + private final Map couchbaseOperations; + + CouchbaseReactiveHealthIndicatorConfiguration( + Map couchbaseOperations) { + this.couchbaseOperations = couchbaseOperations; + } + + @Bean + @ConditionalOnMissingBean(name = "couchbaseReactiveHealthIndicator") + public ReactiveHealthIndicator couchbaseReactiveHealthIndicator() { + return createHealthIndicator(this.couchbaseOperations); + } +} diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/couchbase/CouchbaseHealthIndicatorConfigurationTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/couchbase/CouchbaseHealthIndicatorConfigurationTests.java new file mode 100644 index 000000000000..59d18699cdcf --- /dev/null +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/couchbase/CouchbaseHealthIndicatorConfigurationTests.java @@ -0,0 +1,70 @@ +/* + * 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.couchbase.CouchbaseReactiveHealthIndicator; +import org.springframework.boot.actuate.health.ApplicationHealthIndicator; +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 static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.mock; + +/** + * Tests for {@link CouchbaseHealthIndicatorConfiguration}. + * + * @author Mikalai Lushchytski + */ +public class CouchbaseHealthIndicatorConfigurationTests { + + private ApplicationContextRunner contextRunner = new ApplicationContextRunner() + .withUserConfiguration(CouchbaseMockConfiguration.class) + .withConfiguration(AutoConfigurations.of( + CouchbaseHealthIndicatorAutoConfiguration.class, + HealthIndicatorAutoConfiguration.class)); + + @Test + public void runShouldCreateIndicator() { + this.contextRunner.run((context) -> assertThat(context) + .hasSingleBean(CouchbaseHealthIndicator.class) + .doesNotHaveBean(CouchbaseReactiveHealthIndicator.class) + .doesNotHaveBean(ApplicationHealthIndicator.class)); + } + + @Test + public void runWhenDisabledShouldNotCreateIndicator() { + this.contextRunner.withPropertyValues("management.health.couchbase.enabled:false") + .run((context) -> assertThat(context) + .doesNotHaveBean(CouchbaseHealthIndicator.class) + .hasSingleBean(ApplicationHealthIndicator.class)); + } + + @Configuration + protected static class CouchbaseMockConfiguration { + + @Bean + public CouchbaseOperations couchbaseOperations() { + return mock(CouchbaseOperations.class); + } + + } +} \ No newline at end of file diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/couchbase/CouchbaseReactiveHealthIndicatorConfigurationTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/couchbase/CouchbaseReactiveHealthIndicatorConfigurationTests.java new file mode 100644 index 000000000000..87cdcb6a43e8 --- /dev/null +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/couchbase/CouchbaseReactiveHealthIndicatorConfigurationTests.java @@ -0,0 +1,71 @@ +/* + * 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.couchbase.CouchbaseReactiveHealthIndicator; +import org.springframework.boot.actuate.health.ApplicationHealthIndicator; +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.RxJavaCouchbaseOperations; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.mock; + +/** + * Tests for {@link CouchbaseReactiveHealthIndicatorConfiguration}. + * + * @author Mikalai Lushchytski + */ +public class CouchbaseReactiveHealthIndicatorConfigurationTests { + + private ApplicationContextRunner contextRunner = new ApplicationContextRunner() + .withUserConfiguration(CouchbaseMockConfiguration.class) + .withConfiguration(AutoConfigurations.of( + CouchbaseHealthIndicatorAutoConfiguration.class, + HealthIndicatorAutoConfiguration.class)); + + @Test + public void runShouldCreateIndicator() { + this.contextRunner.run((context) -> assertThat(context) + .hasSingleBean(CouchbaseReactiveHealthIndicator.class) + .doesNotHaveBean(CouchbaseHealthIndicator.class) + .doesNotHaveBean(ApplicationHealthIndicator.class)); + } + + @Test + public void runWhenDisabledShouldNotCreateIndicator() { + this.contextRunner.withPropertyValues("management.health.couchbase.enabled:false") + .run((context) -> assertThat(context) + .doesNotHaveBean(CouchbaseReactiveHealthIndicator.class) + .hasSingleBean(ApplicationHealthIndicator.class)); + } + + @Configuration + protected static class CouchbaseMockConfiguration { + + @Bean + public RxJavaCouchbaseOperations couchbaseOperations() { + return mock(RxJavaCouchbaseOperations.class); + } + + } + +} \ No newline at end of file diff --git a/spring-boot-project/spring-boot-actuator/pom.xml b/spring-boot-project/spring-boot-actuator/pom.xml index 055feabaf396..cb8d8806df80 100644 --- a/spring-boot-project/spring-boot-actuator/pom.xml +++ b/spring-boot-project/spring-boot-actuator/pom.xml @@ -77,6 +77,11 @@ + + io.reactivex + rxjava-reactive-streams + true + javax.cache cache-api 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 new file mode 100644 index 000000000000..945724ecbfcc --- /dev/null +++ b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/couchbase/CouchbaseReactiveHealthIndicator.java @@ -0,0 +1,73 @@ +/* + * 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.couchbase; + +import com.couchbase.client.java.bucket.BucketInfo; +import com.couchbase.client.java.cluster.ClusterInfo; +import org.springframework.boot.actuate.health.AbstractReactiveHealthIndicator; +import org.springframework.boot.actuate.health.Health; +import org.springframework.data.couchbase.core.RxJavaCouchbaseOperations; +import org.springframework.util.StringUtils; +import reactor.core.publisher.Mono; +import rx.Observable; +import rx.RxReactiveStreams; +import rx.Single; + +/** + * A {@link org.springframework.boot.actuate.health.ReactiveHealthIndicator} for Couchbase. + * + * @author Mikalai Lushchytski + * @since 2.1.0 + */ +public class CouchbaseReactiveHealthIndicator extends AbstractReactiveHealthIndicator { + + private final RxJavaCouchbaseOperations couchbaseOperations; + + /** + * Create a new {@link CouchbaseReactiveHealthIndicator} instance. + * @param couchbaseOperations Reactive couchbase client. + */ + public CouchbaseReactiveHealthIndicator( + RxJavaCouchbaseOperations couchbaseOperations) { + this.couchbaseOperations = couchbaseOperations; + } + + @Override + protected Mono doHealthCheck(Health.Builder builder) { + ClusterInfo cluster = this.couchbaseOperations.getCouchbaseClusterInfo(); + String versions = StringUtils + .collectionToCommaDelimitedString(cluster.getAllVersions()); + Observable bucket = this.couchbaseOperations.getCouchbaseBucket() + .bucketManager() + .async() + .info(); + Single health = bucket + .map(BucketInfo::nodeList) + .map(StringUtils::collectionToCommaDelimitedString) + .map(nodes -> up(builder, versions, nodes)) + .onErrorReturn(error -> down(builder, error)) + .toSingle(); + 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(); + } +} 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 new file mode 100644 index 000000000000..9346aef9d139 --- /dev/null +++ b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/couchbase/CouchbaseReactiveHealthIndicatorTests.java @@ -0,0 +1,109 @@ +/* + * 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.couchbase; + +import com.couchbase.client.java.Bucket; +import com.couchbase.client.java.bucket.AsyncBucketManager; +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.error.TranscodingException; +import com.couchbase.client.java.util.features.Version; +import org.junit.Test; +import org.springframework.boot.actuate.health.Health; +import org.springframework.boot.actuate.health.Status; +import org.springframework.data.couchbase.core.RxJavaCouchbaseOperations; +import reactor.core.publisher.Mono; +import reactor.test.StepVerifier; +import rx.Observable; + +import java.net.InetAddress; +import java.util.Arrays; +import java.util.Collections; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.BDDMockito.given; +import static org.mockito.Mockito.mock; + +/** + * Tests for {@link CouchbaseReactiveHealthIndicator}. + */ +public class CouchbaseReactiveHealthIndicatorTests { + + @Test + public void testCouchbaseIsUp() { + ClusterInfo clusterInfo = mock(ClusterInfo.class); + RxJavaCouchbaseOperations rxJavaCouchbaseOperations = mock(RxJavaCouchbaseOperations.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); + BucketInfo info = mock(BucketInfo.class); + given(asyncBucketManager.info()).willReturn(Observable.just(info)); + + InetAddress node1Address = mock(InetAddress.class); + InetAddress node2Address = mock(InetAddress.class); + given(info.nodeList()).willReturn(Arrays.asList(node1Address, node2Address)); + given(node1Address.toString()).willReturn("127.0.0.1"); + given(node2Address.toString()).willReturn("127.0.0.2"); + + CouchbaseReactiveHealthIndicator couchbaseReactiveHealthIndicator = new CouchbaseReactiveHealthIndicator( + rxJavaCouchbaseOperations); + + Mono health = couchbaseReactiveHealthIndicator.health(); + StepVerifier.create(health).consumeNextWith((h) -> { + assertThat(h.getStatus()).isEqualTo(Status.UP); + assertThat(h.getDetails()).containsKeys("versions", "nodes"); + assertThat(h.getDetails().get("versions")).isEqualTo("5.5.0,6.0.0"); + assertThat(h.getDetails().get("nodes")).isEqualTo("127.0.0.1,127.0.0.2"); + }).verifyComplete(); + } + + @Test + public void testCouchbaseIsDown() { + ClusterInfo clusterInfo = mock(ClusterInfo.class); + RxJavaCouchbaseOperations rxJavaCouchbaseOperations = mock(RxJavaCouchbaseOperations.class); + given(rxJavaCouchbaseOperations.getCouchbaseClusterInfo()) + .willReturn(clusterInfo); + given(clusterInfo.getAllVersions()).willReturn(Collections.singletonList( + new Version(5, 5, 0) + )); + BucketManager bucketManager = mock(BucketManager.class); + AsyncBucketManager asyncBucketManager = mock(AsyncBucketManager.class); + Bucket bucket = mock(Bucket.class); + given(rxJavaCouchbaseOperations.getCouchbaseBucket()).willReturn(bucket); + given(bucket.bucketManager()).willReturn(bucketManager); + given(bucketManager.async()).willReturn(asyncBucketManager); + given(asyncBucketManager.info()).willReturn(Observable.error(new TranscodingException("Failure"))); + CouchbaseReactiveHealthIndicator couchbaseReactiveHealthIndicator = new CouchbaseReactiveHealthIndicator( + rxJavaCouchbaseOperations); + + 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")).isEqualTo( + TranscodingException.class.getName() + ": Failure"); + }).verifyComplete(); + } +} \ No newline at end of file From a2eb82267dc0ebfd91b8617f448f3bd924b324ae Mon Sep 17 00:00:00 2001 From: Mikalai Lushchytski Date: Sat, 28 Jul 2018 11:59:28 +0300 Subject: [PATCH 2/7] checkstyle fixes --- .../couchbase/CouchbaseReactiveHealthIndicator.java | 13 +++++++------ .../CouchbaseReactiveHealthIndicatorTests.java | 9 +++++---- 2 files changed, 12 insertions(+), 10 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 945724ecbfcc..638149276d68 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 @@ -17,15 +17,16 @@ import com.couchbase.client.java.bucket.BucketInfo; import com.couchbase.client.java.cluster.ClusterInfo; -import org.springframework.boot.actuate.health.AbstractReactiveHealthIndicator; -import org.springframework.boot.actuate.health.Health; -import org.springframework.data.couchbase.core.RxJavaCouchbaseOperations; -import org.springframework.util.StringUtils; import reactor.core.publisher.Mono; import rx.Observable; import rx.RxReactiveStreams; import rx.Single; +import org.springframework.boot.actuate.health.AbstractReactiveHealthIndicator; +import org.springframework.boot.actuate.health.Health; +import org.springframework.data.couchbase.core.RxJavaCouchbaseOperations; +import org.springframework.util.StringUtils; + /** * A {@link org.springframework.boot.actuate.health.ReactiveHealthIndicator} for Couchbase. * @@ -57,8 +58,8 @@ protected Mono doHealthCheck(Health.Builder builder) { Single health = bucket .map(BucketInfo::nodeList) .map(StringUtils::collectionToCommaDelimitedString) - .map(nodes -> up(builder, versions, nodes)) - .onErrorReturn(error -> down(builder, error)) + .map((nodes) -> up(builder, versions, nodes)) + .onErrorReturn((error) -> down(builder, error)) .toSingle(); return Mono.from(RxReactiveStreams.toPublisher(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 9346aef9d139..4ab0a133dc21 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 @@ -23,13 +23,14 @@ import com.couchbase.client.java.error.TranscodingException; import com.couchbase.client.java.util.features.Version; import org.junit.Test; -import org.springframework.boot.actuate.health.Health; -import org.springframework.boot.actuate.health.Status; -import org.springframework.data.couchbase.core.RxJavaCouchbaseOperations; import reactor.core.publisher.Mono; import reactor.test.StepVerifier; import rx.Observable; +import org.springframework.boot.actuate.health.Health; +import org.springframework.boot.actuate.health.Status; +import org.springframework.data.couchbase.core.RxJavaCouchbaseOperations; + import java.net.InetAddress; import java.util.Arrays; import java.util.Collections; @@ -106,4 +107,4 @@ public void testCouchbaseIsDown() { TranscodingException.class.getName() + ": Failure"); }).verifyComplete(); } -} \ No newline at end of file +} From 6979c14865250c3850fea9200f8da43e728d2461 Mon Sep 17 00:00:00 2001 From: Mikalai Lushchytski Date: Sun, 29 Jul 2018 09:33:39 +0300 Subject: [PATCH 3/7] checkstyle fixes --- .../couchbase/CouchbaseReactiveHealthIndicatorTests.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) 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 4ab0a133dc21..c4d2549fec2c 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 @@ -27,14 +27,14 @@ import reactor.test.StepVerifier; import rx.Observable; -import org.springframework.boot.actuate.health.Health; -import org.springframework.boot.actuate.health.Status; -import org.springframework.data.couchbase.core.RxJavaCouchbaseOperations; - import java.net.InetAddress; import java.util.Arrays; import java.util.Collections; +import org.springframework.boot.actuate.health.Health; +import org.springframework.boot.actuate.health.Status; +import org.springframework.data.couchbase.core.RxJavaCouchbaseOperations; + import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.BDDMockito.given; import static org.mockito.Mockito.mock; From 18486268bf554d75963700abdec63e88fe44c175 Mon Sep 17 00:00:00 2001 From: Mikalai Lushchytski Date: Mon, 30 Jul 2018 09:57:44 +0300 Subject: [PATCH 4/7] checkstyle fixes --- .../couchbase/CouchbaseReactiveHealthIndicatorTests.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) 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 c4d2549fec2c..2130eb8eb43f 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 @@ -22,15 +22,16 @@ import com.couchbase.client.java.cluster.ClusterInfo; import com.couchbase.client.java.error.TranscodingException; import com.couchbase.client.java.util.features.Version; -import org.junit.Test; -import reactor.core.publisher.Mono; -import reactor.test.StepVerifier; -import rx.Observable; import java.net.InetAddress; import java.util.Arrays; import java.util.Collections; +import org.junit.Test; +import reactor.core.publisher.Mono; +import reactor.test.StepVerifier; +import rx.Observable; + import org.springframework.boot.actuate.health.Health; import org.springframework.boot.actuate.health.Status; import org.springframework.data.couchbase.core.RxJavaCouchbaseOperations; From ab6add5797331d21c5988b1a5f5cd09ffdec6683 Mon Sep 17 00:00:00 2001 From: Mikalai Lushchytski Date: Mon, 30 Jul 2018 10:23:11 +0300 Subject: [PATCH 5/7] checkstyle fixes --- .../couchbase/CouchbaseReactiveHealthIndicatorTests.java | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) 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 2130eb8eb43f..331269e95390 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 @@ -15,6 +15,10 @@ */ package org.springframework.boot.actuate.couchbase; +import java.net.InetAddress; +import java.util.Arrays; +import java.util.Collections; + import com.couchbase.client.java.Bucket; import com.couchbase.client.java.bucket.AsyncBucketManager; import com.couchbase.client.java.bucket.BucketInfo; @@ -22,11 +26,6 @@ import com.couchbase.client.java.cluster.ClusterInfo; import com.couchbase.client.java.error.TranscodingException; import com.couchbase.client.java.util.features.Version; - -import java.net.InetAddress; -import java.util.Arrays; -import java.util.Collections; - import org.junit.Test; import reactor.core.publisher.Mono; import reactor.test.StepVerifier; From 88b2a48468080ee4e8ad5720eeefa16bfb66875f Mon Sep 17 00:00:00 2001 From: Mikalai Lushchytski Date: Mon, 30 Jul 2018 10:48:01 +0300 Subject: [PATCH 6/7] code formatting --- ...hbaseHealthIndicatorAutoConfiguration.java | 12 ++++------ ...CouchbaseHealthIndicatorConfiguration.java | 1 + ...eReactiveHealthIndicatorConfiguration.java | 4 +++- ...baseHealthIndicatorConfigurationTests.java | 8 +++---- ...tiveHealthIndicatorConfigurationTests.java | 7 +++--- .../CouchbaseReactiveHealthIndicator.java | 17 +++++++------ ...CouchbaseReactiveHealthIndicatorTests.java | 24 ++++++++++--------- 7 files changed, 36 insertions(+), 37 deletions(-) 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 c593eda6cb21..9286a980fc7e 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 @@ -42,15 +42,11 @@ @ConditionalOnClass(Bucket.class) @ConditionalOnEnabledHealthIndicator("couchbase") @AutoConfigureBefore(HealthIndicatorAutoConfiguration.class) -@AutoConfigureAfter({ - CouchbaseAutoConfiguration.class, +@AutoConfigureAfter({ CouchbaseAutoConfiguration.class, CouchbaseDataAutoConfiguration.class, - CouchbaseReactiveDataAutoConfiguration.class -}) -@Import({ - CouchbaseHealthIndicatorConfiguration.class, - CouchbaseReactiveHealthIndicatorConfiguration.class -}) + CouchbaseReactiveDataAutoConfiguration.class }) +@Import({ CouchbaseHealthIndicatorConfiguration.class, + CouchbaseReactiveHealthIndicatorConfiguration.class }) public class CouchbaseHealthIndicatorAutoConfiguration { } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/couchbase/CouchbaseHealthIndicatorConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/couchbase/CouchbaseHealthIndicatorConfiguration.java index e048080ba0aa..8c65590384ba 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/couchbase/CouchbaseHealthIndicatorConfiguration.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/couchbase/CouchbaseHealthIndicatorConfiguration.java @@ -51,4 +51,5 @@ public class CouchbaseHealthIndicatorConfiguration extends public HealthIndicator couchbaseHealthIndicator() { return createHealthIndicator(this.couchbaseOperations); } + } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/couchbase/CouchbaseReactiveHealthIndicatorConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/couchbase/CouchbaseReactiveHealthIndicatorConfiguration.java index fce1cece960e..e1e5ae9b330a 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/couchbase/CouchbaseReactiveHealthIndicatorConfiguration.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/couchbase/CouchbaseReactiveHealthIndicatorConfiguration.java @@ -28,7 +28,8 @@ import java.util.Map; /** - * Configuration for {@link org.springframework.boot.actuate.couchbase.CouchbaseReactiveHealthIndicator}. + * Configuration for + * {@link org.springframework.boot.actuate.couchbase.CouchbaseReactiveHealthIndicator}. * * @author Mikalai Lushchytski * @since 2.1.0 @@ -51,4 +52,5 @@ public class CouchbaseReactiveHealthIndicatorConfiguration extends public ReactiveHealthIndicator couchbaseReactiveHealthIndicator() { return createHealthIndicator(this.couchbaseOperations); } + } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/couchbase/CouchbaseHealthIndicatorConfigurationTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/couchbase/CouchbaseHealthIndicatorConfigurationTests.java index 59d18699cdcf..1c76b8fbd10b 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/couchbase/CouchbaseHealthIndicatorConfigurationTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/couchbase/CouchbaseHealthIndicatorConfigurationTests.java @@ -37,10 +37,9 @@ public class CouchbaseHealthIndicatorConfigurationTests { private ApplicationContextRunner contextRunner = new ApplicationContextRunner() - .withUserConfiguration(CouchbaseMockConfiguration.class) - .withConfiguration(AutoConfigurations.of( - CouchbaseHealthIndicatorAutoConfiguration.class, - HealthIndicatorAutoConfiguration.class)); + .withUserConfiguration(CouchbaseMockConfiguration.class).withConfiguration( + AutoConfigurations.of(CouchbaseHealthIndicatorAutoConfiguration.class, + HealthIndicatorAutoConfiguration.class)); @Test public void runShouldCreateIndicator() { @@ -67,4 +66,5 @@ public CouchbaseOperations couchbaseOperations() { } } + } \ No newline at end of file diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/couchbase/CouchbaseReactiveHealthIndicatorConfigurationTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/couchbase/CouchbaseReactiveHealthIndicatorConfigurationTests.java index 87cdcb6a43e8..aa2e8b0b2426 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/couchbase/CouchbaseReactiveHealthIndicatorConfigurationTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/couchbase/CouchbaseReactiveHealthIndicatorConfigurationTests.java @@ -37,10 +37,9 @@ public class CouchbaseReactiveHealthIndicatorConfigurationTests { private ApplicationContextRunner contextRunner = new ApplicationContextRunner() - .withUserConfiguration(CouchbaseMockConfiguration.class) - .withConfiguration(AutoConfigurations.of( - CouchbaseHealthIndicatorAutoConfiguration.class, - HealthIndicatorAutoConfiguration.class)); + .withUserConfiguration(CouchbaseMockConfiguration.class).withConfiguration( + AutoConfigurations.of(CouchbaseHealthIndicatorAutoConfiguration.class, + HealthIndicatorAutoConfiguration.class)); @Test public void runShouldCreateIndicator() { 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 638149276d68..9f43994c0aff 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 @@ -28,7 +28,8 @@ import org.springframework.util.StringUtils; /** - * A {@link org.springframework.boot.actuate.health.ReactiveHealthIndicator} for Couchbase. + * A {@link org.springframework.boot.actuate.health.ReactiveHealthIndicator} for + * Couchbase. * * @author Mikalai Lushchytski * @since 2.1.0 @@ -52,23 +53,21 @@ protected Mono doHealthCheck(Health.Builder builder) { String versions = StringUtils .collectionToCommaDelimitedString(cluster.getAllVersions()); Observable bucket = this.couchbaseOperations.getCouchbaseBucket() - .bucketManager() - .async() - .info(); - Single health = bucket - .map(BucketInfo::nodeList) + .bucketManager().async().info(); + Single health = bucket.map(BucketInfo::nodeList) .map(StringUtils::collectionToCommaDelimitedString) .map((nodes) -> up(builder, versions, nodes)) - .onErrorReturn((error) -> down(builder, error)) - .toSingle(); + .onErrorReturn((error) -> down(builder, error)).toSingle(); 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(); + return builder.up().withDetail("versions", versions).withDetail("nodes", nodes) + .build(); } private Health down(Health.Builder builder, Throwable error) { return builder.down(error).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 331269e95390..f728a42f62ce 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 @@ -47,12 +47,12 @@ public class CouchbaseReactiveHealthIndicatorTests { @Test public void testCouchbaseIsUp() { ClusterInfo clusterInfo = mock(ClusterInfo.class); - RxJavaCouchbaseOperations rxJavaCouchbaseOperations = mock(RxJavaCouchbaseOperations.class); + RxJavaCouchbaseOperations rxJavaCouchbaseOperations = mock( + RxJavaCouchbaseOperations.class); given(rxJavaCouchbaseOperations.getCouchbaseClusterInfo()) .willReturn(clusterInfo); - given(clusterInfo.getAllVersions()).willReturn(Arrays.asList( - new Version(5, 5, 0), new Version(6, 0, 0) - )); + 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); @@ -83,19 +83,20 @@ public void testCouchbaseIsUp() { @Test public void testCouchbaseIsDown() { ClusterInfo clusterInfo = mock(ClusterInfo.class); - RxJavaCouchbaseOperations rxJavaCouchbaseOperations = mock(RxJavaCouchbaseOperations.class); + RxJavaCouchbaseOperations rxJavaCouchbaseOperations = mock( + RxJavaCouchbaseOperations.class); given(rxJavaCouchbaseOperations.getCouchbaseClusterInfo()) .willReturn(clusterInfo); - given(clusterInfo.getAllVersions()).willReturn(Collections.singletonList( - new Version(5, 5, 0) - )); + given(clusterInfo.getAllVersions()) + .willReturn(Collections.singletonList(new Version(5, 5, 0))); BucketManager bucketManager = mock(BucketManager.class); AsyncBucketManager asyncBucketManager = mock(AsyncBucketManager.class); Bucket bucket = mock(Bucket.class); given(rxJavaCouchbaseOperations.getCouchbaseBucket()).willReturn(bucket); given(bucket.bucketManager()).willReturn(bucketManager); given(bucketManager.async()).willReturn(asyncBucketManager); - given(asyncBucketManager.info()).willReturn(Observable.error(new TranscodingException("Failure"))); + given(asyncBucketManager.info()) + .willReturn(Observable.error(new TranscodingException("Failure"))); CouchbaseReactiveHealthIndicator couchbaseReactiveHealthIndicator = new CouchbaseReactiveHealthIndicator( rxJavaCouchbaseOperations); @@ -103,8 +104,9 @@ public void testCouchbaseIsDown() { StepVerifier.create(health).consumeNextWith((h) -> { assertThat(h.getStatus()).isEqualTo(Status.DOWN); assertThat(h.getDetails()).containsOnlyKeys("error"); - assertThat(h.getDetails().get("error")).isEqualTo( - TranscodingException.class.getName() + ": Failure"); + assertThat(h.getDetails().get("error")) + .isEqualTo(TranscodingException.class.getName() + ": Failure"); }).verifyComplete(); } + } From 052b40991c4e1c0a9d59325b2230ec2ec446fe58 Mon Sep 17 00:00:00 2001 From: Mikalai Lushchytski Date: Mon, 30 Jul 2018 11:19:21 +0300 Subject: [PATCH 7/7] checkstyle fixes --- ...hbaseHealthIndicatorAutoConfiguration.java | 1 + ...CouchbaseHealthIndicatorConfiguration.java | 4 +-- ...eReactiveHealthIndicatorConfiguration.java | 32 +++++++++---------- ...baseHealthIndicatorConfigurationTests.java | 3 +- ...tiveHealthIndicatorConfigurationTests.java | 3 +- 5 files changed, 23 insertions(+), 20 deletions(-) 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 9286a980fc7e..5512da403deb 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,6 +17,7 @@ package org.springframework.boot.actuate.autoconfigure.couchbase; import com.couchbase.client.java.Bucket; + import org.springframework.boot.actuate.autoconfigure.health.ConditionalOnEnabledHealthIndicator; import org.springframework.boot.actuate.autoconfigure.health.HealthIndicatorAutoConfiguration; import org.springframework.boot.actuate.couchbase.CouchbaseHealthIndicator; diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/couchbase/CouchbaseHealthIndicatorConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/couchbase/CouchbaseHealthIndicatorConfiguration.java index 8c65590384ba..5ac3cb79e2b6 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/couchbase/CouchbaseHealthIndicatorConfiguration.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/couchbase/CouchbaseHealthIndicatorConfiguration.java @@ -15,6 +15,8 @@ */ package org.springframework.boot.actuate.autoconfigure.couchbase; +import java.util.Map; + import org.springframework.boot.actuate.autoconfigure.health.CompositeHealthIndicatorConfiguration; import org.springframework.boot.actuate.couchbase.CouchbaseHealthIndicator; import org.springframework.boot.actuate.health.HealthIndicator; @@ -25,8 +27,6 @@ import org.springframework.context.annotation.Configuration; import org.springframework.data.couchbase.core.CouchbaseOperations; -import java.util.Map; - /** * Configuration for {@link CouchbaseHealthIndicator}. * diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/couchbase/CouchbaseReactiveHealthIndicatorConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/couchbase/CouchbaseReactiveHealthIndicatorConfiguration.java index e1e5ae9b330a..9a85bb87c1bb 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/couchbase/CouchbaseReactiveHealthIndicatorConfiguration.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/couchbase/CouchbaseReactiveHealthIndicatorConfiguration.java @@ -1,20 +1,22 @@ /* -+ * 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. -+ */ + * 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.util.Map; + import org.springframework.boot.actuate.autoconfigure.health.CompositeReactiveHealthIndicatorConfiguration; import org.springframework.boot.actuate.couchbase.CouchbaseReactiveHealthIndicator; import org.springframework.boot.actuate.health.ReactiveHealthIndicator; @@ -25,8 +27,6 @@ import org.springframework.context.annotation.Configuration; import org.springframework.data.couchbase.core.RxJavaCouchbaseOperations; -import java.util.Map; - /** * Configuration for * {@link org.springframework.boot.actuate.couchbase.CouchbaseReactiveHealthIndicator}. diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/couchbase/CouchbaseHealthIndicatorConfigurationTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/couchbase/CouchbaseHealthIndicatorConfigurationTests.java index 1c76b8fbd10b..c90a6bd20fe5 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/couchbase/CouchbaseHealthIndicatorConfigurationTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/couchbase/CouchbaseHealthIndicatorConfigurationTests.java @@ -16,6 +16,7 @@ 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.couchbase.CouchbaseReactiveHealthIndicator; @@ -67,4 +68,4 @@ public CouchbaseOperations couchbaseOperations() { } -} \ No newline at end of file +} diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/couchbase/CouchbaseReactiveHealthIndicatorConfigurationTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/couchbase/CouchbaseReactiveHealthIndicatorConfigurationTests.java index aa2e8b0b2426..04b1d61ab853 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/couchbase/CouchbaseReactiveHealthIndicatorConfigurationTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/couchbase/CouchbaseReactiveHealthIndicatorConfigurationTests.java @@ -16,6 +16,7 @@ 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.couchbase.CouchbaseReactiveHealthIndicator; @@ -67,4 +68,4 @@ public RxJavaCouchbaseOperations couchbaseOperations() { } -} \ No newline at end of file +}