|
|
|
@ -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 {
|
|
|
|
|
|
|
|
|
|