diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/elasticsearch/rest/RestClientAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/elasticsearch/rest/RestClientAutoConfigurationTests.java index 1bbc1ad9eb4..ef47b22b7dd 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/elasticsearch/rest/RestClientAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/elasticsearch/rest/RestClientAutoConfigurationTests.java @@ -78,29 +78,39 @@ public class RestClientAutoConfigurationTests { } @Test - public void defaultTimeoutsShouldBeConfigured() { + public void configureWithNoTimeoutsApplyDefaults() { this.contextRunner.run((context) -> { assertThat(context).hasSingleBean(RestClient.class); RestClient restClient = context.getBean(RestClient.class); assertTimeouts(restClient, - Duration.ofMillis(RestClientBuilder.DEFAULT_CONNECT_TIMEOUT_MILLIS), Duration.ofMillis(RestClientBuilder.DEFAULT_SOCKET_TIMEOUT_MILLIS) - ); + Duration.ofMillis(RestClientBuilder.DEFAULT_CONNECT_TIMEOUT_MILLIS), + Duration.ofMillis(RestClientBuilder.DEFAULT_SOCKET_TIMEOUT_MILLIS)); }); } @Test - public void timeoutsCanBeConfigured() { + public void configureWithCustomTimeouts() { this.contextRunner .withPropertyValues("spring.elasticsearch.rest.connection-timeout=15s", "spring.elasticsearch.rest.read-timeout=1m") .run((context) -> { assertThat(context).hasSingleBean(RestClient.class); RestClient restClient = context.getBean(RestClient.class); - assertTimeouts(restClient, Duration.ofSeconds(15), Duration.ofMinutes(1) - ); + assertTimeouts(restClient, Duration.ofSeconds(15), + Duration.ofMinutes(1)); }); } + private static void assertTimeouts(RestClient restClient, Duration connectTimeout, + Duration readTimeout) { + Object client = ReflectionTestUtils.getField(restClient, "client"); + Object config = ReflectionTestUtils.getField(client, "defaultConfig"); + assertThat(config).hasFieldOrPropertyWithValue("socketTimeout", + Math.toIntExact(readTimeout.toMillis())); + assertThat(config).hasFieldOrPropertyWithValue("connectTimeout", + Math.toIntExact(connectTimeout.toMillis())); + } + @Test public void restClientCanQueryElasticsearchNode() { this.contextRunner @@ -121,15 +131,6 @@ public class RestClientAutoConfigurationTests { }); } - private static void assertTimeouts(RestClient restClient, Duration connectTimeout, Duration readTimeout) { - Object client = ReflectionTestUtils.getField(restClient, "client"); - Object config = ReflectionTestUtils.getField(client, "defaultConfig"); - assertThat(config).hasFieldOrPropertyWithValue("socketTimeout", - Math.toIntExact(readTimeout.toMillis())); - assertThat(config).hasFieldOrPropertyWithValue("connectTimeout", - Math.toIntExact(connectTimeout.toMillis())); - } - @Configuration(proxyBeanMethods = false) static class CustomRestClientConfiguration { diff --git a/spring-boot-project/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc b/spring-boot-project/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc index 9e1adc7492a..c289788c68c 100644 --- a/spring-boot-project/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc +++ b/spring-boot-project/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc @@ -4805,6 +4805,7 @@ You can further tune how `RestClient` is configured, as shown in the following e [source,properties,indent=0] ---- spring.elasticsearch.rest.uris=https://search.example.com:9200 + spring.elasticsearch.rest.read-timeout=10s spring.elasticsearch.rest.username=user spring.elasticsearch.rest.password=secret ----