diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/elasticsearch/ElasticsearchProperties.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/elasticsearch/ElasticsearchProperties.java index da805fe3ca..8c99316de5 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/elasticsearch/ElasticsearchProperties.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/elasticsearch/ElasticsearchProperties.java @@ -57,16 +57,16 @@ public class ElasticsearchProperties { */ private Duration socketTimeout = Duration.ofSeconds(30); - /** - * Prefix added to the path of every request sent to Elasticsearch. - */ - private String pathPrefix; - /** * Whether to enable socket keep alive between client and Elasticsearch. */ private boolean socketKeepAlive = false; + /** + * Prefix added to the path of every request sent to Elasticsearch. + */ + private String pathPrefix; + private final Restclient restclient = new Restclient(); public List getUris() { @@ -109,14 +109,6 @@ public class ElasticsearchProperties { this.socketTimeout = socketTimeout; } - public String getPathPrefix() { - return this.pathPrefix; - } - - public void setPathPrefix(String pathPrefix) { - this.pathPrefix = pathPrefix; - } - public boolean isSocketKeepAlive() { return this.socketKeepAlive; } @@ -125,6 +117,14 @@ public class ElasticsearchProperties { this.socketKeepAlive = socketKeepAlive; } + public String getPathPrefix() { + return this.pathPrefix; + } + + public void setPathPrefix(String pathPrefix) { + this.pathPrefix = pathPrefix; + } + public Restclient getRestclient() { return this.restclient; } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/elasticsearch/ElasticsearchRestClientConfigurations.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/elasticsearch/ElasticsearchRestClientConfigurations.java index 9cf91cfb0d..24b197d6ab 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/elasticsearch/ElasticsearchRestClientConfigurations.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/elasticsearch/ElasticsearchRestClientConfigurations.java @@ -156,8 +156,8 @@ class ElasticsearchRestClientConfigurations { @Override public void customize(HttpAsyncClientBuilder builder) { builder.setDefaultCredentialsProvider(new PropertiesCredentialsProvider(this.properties)); - map.from(this.properties::isSocketKeepAlive).whenTrue() - .to(keepalive -> builder.setDefaultIOReactorConfig(IOReactorConfig.custom().setSoKeepAlive(keepalive).build())); + map.from(this.properties::isSocketKeepAlive).to((keepAlive) -> builder + .setDefaultIOReactorConfig(IOReactorConfig.custom().setSoKeepAlive(keepAlive).build())); } @Override diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/elasticsearch/ElasticsearchRestClientAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/elasticsearch/ElasticsearchRestClientAutoConfigurationTests.java index fa67f021ea..38b11a60c5 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/elasticsearch/ElasticsearchRestClientAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/elasticsearch/ElasticsearchRestClientAutoConfigurationTests.java @@ -184,20 +184,19 @@ class ElasticsearchRestClientAutoConfigurationTests { } @Test - void socketKeepAliveDefaults() { + void configureWithNoSocketKeepAliveApplyDefault() { RestClient client = RestClient.builder(new HttpHost("localhost", 9201, "http")).build(); assertThat(client.getHttpClient()).extracting("connmgr.ioReactor.config.soKeepAlive").isEqualTo(Boolean.FALSE); } @Test void configureWithCustomSocketKeepAlive() { - this.contextRunner.withPropertyValues("spring.elasticsearch.socket-keep-alive=true").run( - context -> { - assertThat(context).hasSingleBean(RestClient.class); - RestClient client = context.getBean(RestClient.class); - assertThat(client.getHttpClient()).extracting("connmgr.ioReactor.config.soKeepAlive").isEqualTo(Boolean.TRUE); - } - ); + this.contextRunner.withPropertyValues("spring.elasticsearch.socket-keep-alive=true").run((context) -> { + assertThat(context).hasSingleBean(RestClient.class); + RestClient client = context.getBean(RestClient.class); + assertThat(client.getHttpClient()).extracting("connmgr.ioReactor.config.soKeepAlive") + .isEqualTo(Boolean.TRUE); + }); } @Test