From b59e0bd3a64851bef0ad48bf9c60147461a17b95 Mon Sep 17 00:00:00 2001 From: Scott Frederick Date: Thu, 8 Oct 2020 14:26:30 -0500 Subject: [PATCH] Replace deprecated API in ElasticsearchReactiveHealthIndicator Fixes gh-23537 --- .../ElasticsearchReactiveHealthIndicator.java | 8 ++++---- .../ElasticsearchReactiveHealthIndicatorTests.java | 5 +---- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/elasticsearch/ElasticsearchReactiveHealthIndicator.java b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/elasticsearch/ElasticsearchReactiveHealthIndicator.java index 67adaa9ebe..5290bfea7d 100644 --- a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/elasticsearch/ElasticsearchReactiveHealthIndicator.java +++ b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/elasticsearch/ElasticsearchReactiveHealthIndicator.java @@ -35,6 +35,7 @@ import org.springframework.web.reactive.function.client.WebClient; * * @author Brian Clozel * @author Aleksander Lech + * @author Scott Frederick * @since 2.3.2 */ public class ElasticsearchReactiveHealthIndicator extends AbstractReactiveHealthIndicator { @@ -53,12 +54,11 @@ public class ElasticsearchReactiveHealthIndicator extends AbstractReactiveHealth @Override protected Mono doHealthCheck(Health.Builder builder) { - return this.client.execute(this::getHealth).flatMap((response) -> doHealthCheck(builder, response)); + return this.client.execute((webClient) -> getHealth(builder, webClient)); } - @SuppressWarnings("deprecation") // Requires an update in ReactiveElasticsearchClient - private Mono getHealth(WebClient webClient) { - return webClient.get().uri("/_cluster/health/").exchange(); + private Mono getHealth(Health.Builder builder, WebClient webClient) { + return webClient.get().uri("/_cluster/health/").exchangeToMono((response) -> doHealthCheck(builder, response)); } private Mono doHealthCheck(Health.Builder builder, ClientResponse response) { diff --git a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/elasticsearch/ElasticsearchReactiveHealthIndicatorTests.java b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/elasticsearch/ElasticsearchReactiveHealthIndicatorTests.java index 00e3b65296..97da21c8cc 100644 --- a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/elasticsearch/ElasticsearchReactiveHealthIndicatorTests.java +++ b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/elasticsearch/ElasticsearchReactiveHealthIndicatorTests.java @@ -32,7 +32,6 @@ import org.springframework.data.elasticsearch.client.reactive.ReactiveElasticsea import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; -import org.springframework.web.reactive.function.client.WebClient; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.entry; @@ -41,20 +40,18 @@ import static org.assertj.core.api.Assertions.entry; * Tests for {@link ElasticsearchReactiveHealthIndicator} * * @author Brian Clozel + * @author Scott Frederick */ class ElasticsearchReactiveHealthIndicatorTests { private MockWebServer server; - private WebClient.Builder builder; - private ElasticsearchReactiveHealthIndicator healthIndicator; @BeforeEach void setup() throws Exception { this.server = new MockWebServer(); this.server.start(); - this.builder = WebClient.builder().baseUrl(this.server.url("/").toString()); ReactiveElasticsearchClient client = DefaultReactiveElasticsearchClient .create(ClientConfiguration.create(this.server.getHostName() + ":" + this.server.getPort())); this.healthIndicator = new ElasticsearchReactiveHealthIndicator(client);