Replace deprecated API in ElasticsearchReactiveHealthIndicator

Fixes gh-23537
This commit is contained in:
Scott Frederick
2020-10-08 14:26:30 -05:00
parent 3f7b4ed890
commit b59e0bd3a6
2 changed files with 5 additions and 8 deletions

View File

@@ -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<Health> 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<ClientResponse> getHealth(WebClient webClient) {
return webClient.get().uri("/_cluster/health/").exchange();
private Mono<Health> getHealth(Health.Builder builder, WebClient webClient) {
return webClient.get().uri("/_cluster/health/").exchangeToMono((response) -> doHealthCheck(builder, response));
}
private Mono<Health> doHealthCheck(Health.Builder builder, ClientResponse response) {

View File

@@ -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);