Skip to content

Commit d6f6bcb

Browse files
committed
Polish "Add socketKeepAlive configuration property for Elasticsearch"
See gh-32051
1 parent 122d40a commit d6f6bcb

File tree

3 files changed

+21
-22
lines changed

3 files changed

+21
-22
lines changed

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/elasticsearch/ElasticsearchProperties.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,14 @@ public class ElasticsearchProperties {
5858
private Duration socketTimeout = Duration.ofSeconds(30);
5959

6060
/**
61-
* Prefix added to the path of every request sent to Elasticsearch.
61+
* Whether to enable socket keep alive between client and Elasticsearch.
6262
*/
63-
private String pathPrefix;
63+
private boolean socketKeepAlive = false;
6464

6565
/**
66-
* Whether to enable socket keep alive between client and Elasticsearch.
66+
* Prefix added to the path of every request sent to Elasticsearch.
6767
*/
68-
private boolean socketKeepAlive = false;
68+
private String pathPrefix;
6969

7070
private final Restclient restclient = new Restclient();
7171

@@ -109,14 +109,6 @@ public void setSocketTimeout(Duration socketTimeout) {
109109
this.socketTimeout = socketTimeout;
110110
}
111111

112-
public String getPathPrefix() {
113-
return this.pathPrefix;
114-
}
115-
116-
public void setPathPrefix(String pathPrefix) {
117-
this.pathPrefix = pathPrefix;
118-
}
119-
120112
public boolean isSocketKeepAlive() {
121113
return this.socketKeepAlive;
122114
}
@@ -125,6 +117,14 @@ public void setSocketKeepAlive(boolean socketKeepAlive) {
125117
this.socketKeepAlive = socketKeepAlive;
126118
}
127119

120+
public String getPathPrefix() {
121+
return this.pathPrefix;
122+
}
123+
124+
public void setPathPrefix(String pathPrefix) {
125+
this.pathPrefix = pathPrefix;
126+
}
127+
128128
public Restclient getRestclient() {
129129
return this.restclient;
130130
}

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/elasticsearch/ElasticsearchRestClientConfigurations.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,8 @@ public void customize(RestClientBuilder builder) {
156156
@Override
157157
public void customize(HttpAsyncClientBuilder builder) {
158158
builder.setDefaultCredentialsProvider(new PropertiesCredentialsProvider(this.properties));
159-
map.from(this.properties::isSocketKeepAlive).whenTrue()
160-
.to(keepalive -> builder.setDefaultIOReactorConfig(IOReactorConfig.custom().setSoKeepAlive(keepalive).build()));
159+
map.from(this.properties::isSocketKeepAlive).to((keepAlive) -> builder
160+
.setDefaultIOReactorConfig(IOReactorConfig.custom().setSoKeepAlive(keepAlive).build()));
161161
}
162162

163163
@Override

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/elasticsearch/ElasticsearchRestClientAutoConfigurationTests.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -184,20 +184,19 @@ void configureWithCustomPathPrefix() {
184184
}
185185

186186
@Test
187-
void socketKeepAliveDefaults() {
187+
void configureWithNoSocketKeepAliveApplyDefault() {
188188
RestClient client = RestClient.builder(new HttpHost("localhost", 9201, "http")).build();
189189
assertThat(client.getHttpClient()).extracting("connmgr.ioReactor.config.soKeepAlive").isEqualTo(Boolean.FALSE);
190190
}
191191

192192
@Test
193193
void configureWithCustomSocketKeepAlive() {
194-
this.contextRunner.withPropertyValues("spring.elasticsearch.socket-keep-alive=true").run(
195-
context -> {
196-
assertThat(context).hasSingleBean(RestClient.class);
197-
RestClient client = context.getBean(RestClient.class);
198-
assertThat(client.getHttpClient()).extracting("connmgr.ioReactor.config.soKeepAlive").isEqualTo(Boolean.TRUE);
199-
}
200-
);
194+
this.contextRunner.withPropertyValues("spring.elasticsearch.socket-keep-alive=true").run((context) -> {
195+
assertThat(context).hasSingleBean(RestClient.class);
196+
RestClient client = context.getBean(RestClient.class);
197+
assertThat(client.getHttpClient()).extracting("connmgr.ioReactor.config.soKeepAlive")
198+
.isEqualTo(Boolean.TRUE);
199+
});
201200
}
202201

203202
@Test

0 commit comments

Comments
 (0)