Bring back Elasticsearch RestClient auto-configuration
Prior to this commit, Spring Boot would only auto-configure the
`RestHighLevelClient` and `RestClientBuilder` if the
`RestHighLevelClient` was present. This was done in 1d73d4ed.
This commit brings back the exposing of the `RestClient` bean in when
exposing the `RestHighLevelClient` or when the `RestHighLevelClient`
is not present. It allows for using the auto-configuration and its
customizers of the `RestClientBuilder` in a similar way as it is done
for the `RestTemplateBuilder` and the `WebClient.Builder`.
The presence of the `elasticsearch-rest-high-level-client` module is
now optional. This opens the door for potentially adding support for
the new Elasticsearch Java Client[1] that is based on the same
`RestClient`.
The health contributor and its configuration has also been updated to
only depend on the low-level RestClient.
See gh-28496
[1] https://github.com/elastic/elasticsearch-java
This commit is contained in:
committed by
Andy Wilkinson
parent
e0ae1d3501
commit
eb3bf40bdb
@@ -22,7 +22,9 @@ import org.springframework.boot.autoconfigure.AutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.boot.autoconfigure.elasticsearch.ElasticsearchRestClientConfigurations.RestClientBuilderConfiguration;
|
||||
import org.springframework.boot.autoconfigure.elasticsearch.ElasticsearchRestClientConfigurations.RestClientConfiguration;
|
||||
import org.springframework.boot.autoconfigure.elasticsearch.ElasticsearchRestClientConfigurations.RestClientSnifferConfiguration;
|
||||
import org.springframework.boot.autoconfigure.elasticsearch.ElasticsearchRestClientConfigurations.RestClientWithRestHighLevelClientConfiguration;
|
||||
import org.springframework.boot.autoconfigure.elasticsearch.ElasticsearchRestClientConfigurations.RestHighLevelClientConfiguration;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.context.annotation.Import;
|
||||
@@ -40,6 +42,7 @@ import org.springframework.context.annotation.Import;
|
||||
@EnableConfigurationProperties({ ElasticsearchProperties.class, ElasticsearchRestClientProperties.class,
|
||||
DeprecatedElasticsearchRestClientProperties.class })
|
||||
@Import({ RestClientBuilderConfiguration.class, RestHighLevelClientConfiguration.class,
|
||||
RestClientWithRestHighLevelClientConfiguration.class, RestClientConfiguration.class,
|
||||
RestClientSnifferConfiguration.class })
|
||||
public class ElasticsearchRestClientAutoConfiguration {
|
||||
|
||||
|
||||
@@ -36,6 +36,7 @@ import org.elasticsearch.client.sniff.SnifferBuilder;
|
||||
import org.springframework.beans.factory.ObjectProvider;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingClass;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnSingleCandidate;
|
||||
import org.springframework.boot.context.properties.PropertyMapper;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
@@ -46,6 +47,7 @@ import org.springframework.util.StringUtils;
|
||||
* Elasticsearch rest client configurations.
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
* @author Filip Hrisafov
|
||||
*/
|
||||
class ElasticsearchRestClientConfigurations {
|
||||
|
||||
@@ -126,16 +128,41 @@ class ElasticsearchRestClientConfigurations {
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
@ConditionalOnClass(Sniffer.class)
|
||||
@ConditionalOnClass(org.elasticsearch.client.RestHighLevelClient.class)
|
||||
@ConditionalOnSingleCandidate(org.elasticsearch.client.RestHighLevelClient.class)
|
||||
@ConditionalOnMissingBean(RestClient.class)
|
||||
static class RestClientWithRestHighLevelClientConfiguration {
|
||||
|
||||
@Bean
|
||||
RestClient elasticsearchRestClient(org.elasticsearch.client.RestHighLevelClient restHighLevelClient) {
|
||||
return restHighLevelClient.getLowLevelClient();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
@ConditionalOnMissingClass("org.elasticsearch.client.RestHighLevelClient")
|
||||
@ConditionalOnMissingBean(RestClient.class)
|
||||
static class RestClientConfiguration {
|
||||
|
||||
@Bean
|
||||
RestClient elasticsearchRestClient(RestClientBuilder restClientBuilder) {
|
||||
return restClientBuilder.build();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
@ConditionalOnClass(Sniffer.class)
|
||||
@ConditionalOnSingleCandidate(RestClient.class)
|
||||
static class RestClientSnifferConfiguration {
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
Sniffer elasticsearchSniffer(org.elasticsearch.client.RestHighLevelClient client,
|
||||
ElasticsearchRestClientProperties properties,
|
||||
@SuppressWarnings("deprecation")
|
||||
Sniffer elasticsearchSniffer(RestClient client, ElasticsearchRestClientProperties properties,
|
||||
DeprecatedElasticsearchRestClientProperties deprecatedProperties) {
|
||||
SnifferBuilder builder = Sniffer.builder(client.getLowLevelClient());
|
||||
SnifferBuilder builder = Sniffer.builder(client);
|
||||
PropertyMapper map = PropertyMapper.get().alwaysApplyingWhenNonNull();
|
||||
Duration interval = deprecatedProperties.isCustomized() ? deprecatedProperties.getSniffer().getInterval()
|
||||
: properties.getSniffer().getInterval();
|
||||
|
||||
@@ -16,19 +16,26 @@
|
||||
|
||||
package org.springframework.boot.autoconfigure.elasticsearch;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.time.Duration;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.elasticsearch.action.get.GetRequest;
|
||||
import org.elasticsearch.action.index.IndexRequest;
|
||||
import org.elasticsearch.client.Request;
|
||||
import org.elasticsearch.client.RequestOptions;
|
||||
import org.elasticsearch.client.Response;
|
||||
import org.elasticsearch.client.RestClient;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.testcontainers.elasticsearch.ElasticsearchContainer;
|
||||
import org.testcontainers.junit.jupiter.Container;
|
||||
import org.testcontainers.junit.jupiter.Testcontainers;
|
||||
|
||||
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
||||
import org.springframework.boot.test.context.FilteredClassLoader;
|
||||
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
|
||||
import org.springframework.boot.testsupport.testcontainers.DockerImageNames;
|
||||
|
||||
@@ -40,6 +47,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
* @author Brian Clozel
|
||||
* @author Vedran Pavic
|
||||
* @author Evgeniy Cheban
|
||||
* @author Filip Hrisafov
|
||||
*/
|
||||
@Testcontainers(disabledWithoutDocker = true)
|
||||
class ElasticsearchRestClientAutoConfigurationIntegrationTests {
|
||||
@@ -53,7 +61,7 @@ class ElasticsearchRestClientAutoConfigurationIntegrationTests {
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation")
|
||||
void restClientCanQueryElasticsearchNode() {
|
||||
void restHighLevelClientCanQueryElasticsearchNode() {
|
||||
this.contextRunner
|
||||
.withPropertyValues("spring.elasticsearch.uris=" + elasticsearch.getHttpHostAddress(),
|
||||
"spring.elasticsearch.connection-timeout=120s", "spring.elasticsearch.socket-timeout=120s")
|
||||
@@ -70,4 +78,43 @@ class ElasticsearchRestClientAutoConfigurationIntegrationTests {
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void restClientCanQueryElasticsearchNode() {
|
||||
this.contextRunner
|
||||
.withPropertyValues("spring.elasticsearch.uris=" + elasticsearch.getHttpHostAddress(),
|
||||
"spring.elasticsearch.connection-timeout=120s", "spring.elasticsearch.socket-timeout=120s")
|
||||
.run((context) -> {
|
||||
RestClient client = context.getBean(RestClient.class);
|
||||
Request index = new Request("PUT", "/test/_doc/2");
|
||||
index.setJsonEntity("{" + " \"a\": \"alpha\"," + " \"b\": \"bravo\"" + "}");
|
||||
client.performRequest(index);
|
||||
Request getRequest = new Request("GET", "/test/_doc/2");
|
||||
Response response = client.performRequest(getRequest);
|
||||
try (InputStream input = response.getEntity().getContent()) {
|
||||
JsonNode result = new ObjectMapper().readTree(input);
|
||||
assertThat(result.path("found").asBoolean()).isTrue();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation")
|
||||
void restClientCanQueryElasticsearchNodeWithoutHighLevelClient() {
|
||||
this.contextRunner.withClassLoader(new FilteredClassLoader(org.elasticsearch.client.RestHighLevelClient.class))
|
||||
.withPropertyValues("spring.elasticsearch.uris=" + elasticsearch.getHttpHostAddress(),
|
||||
"spring.elasticsearch.connection-timeout=120s", "spring.elasticsearch.socket-timeout=120s")
|
||||
.run((context) -> {
|
||||
RestClient client = context.getBean(RestClient.class);
|
||||
Request index = new Request("PUT", "/test/_doc/3");
|
||||
index.setJsonEntity("{" + " \"a\": \"alpha\"," + " \"b\": \"bravo\"" + "}");
|
||||
client.performRequest(index);
|
||||
Request getRequest = new Request("GET", "/test/_doc/3");
|
||||
Response response = client.performRequest(getRequest);
|
||||
try (InputStream input = response.getEntity().getContent()) {
|
||||
JsonNode result = new ObjectMapper().readTree(input);
|
||||
assertThat(result.path("found").asBoolean()).isTrue();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -63,17 +63,20 @@ class ElasticsearchRestClientAutoConfigurationTests {
|
||||
.withConfiguration(AutoConfigurations.of(ElasticsearchRestClientAutoConfiguration.class));
|
||||
|
||||
@Test
|
||||
void configureShouldOnlyCreateHighLevelRestClient() {
|
||||
this.contextRunner.run((context) -> assertThat(context).doesNotHaveBean(RestClient.class)
|
||||
.hasSingleBean(RestClientBuilder.class)
|
||||
.hasSingleBean(org.elasticsearch.client.RestHighLevelClient.class));
|
||||
|
||||
void configureShouldCreateHighLevelAndLowLevelRestClient() {
|
||||
this.contextRunner.run((context) -> {
|
||||
assertThat(context).hasSingleBean(RestClient.class)
|
||||
.hasSingleBean(org.elasticsearch.client.RestHighLevelClient.class)
|
||||
.hasSingleBean(RestClientBuilder.class);
|
||||
assertThat(context.getBean(RestClient.class))
|
||||
.isEqualTo(context.getBean(org.elasticsearch.client.RestHighLevelClient.class).getLowLevelClient());
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void configureWithoutRestHighLevelClientShouldOnlyCreateRestClientBuilder() {
|
||||
void configureWithoutRestHighLevelClientShouldOnlyCreateRestClientBuilderAndRestClient() {
|
||||
this.contextRunner.withClassLoader(new FilteredClassLoader(org.elasticsearch.client.RestHighLevelClient.class))
|
||||
.run((context) -> assertThat(context).doesNotHaveBean(RestClient.class)
|
||||
.run((context) -> assertThat(context).hasSingleBean(RestClient.class)
|
||||
.doesNotHaveBean(org.elasticsearch.client.RestHighLevelClient.class)
|
||||
.hasSingleBean(RestClientBuilder.class));
|
||||
}
|
||||
@@ -87,25 +90,52 @@ class ElasticsearchRestClientAutoConfigurationTests {
|
||||
.hasBean("customRestClient"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void configureWhenCustomRestHighLevelClientIsNotPresent() {
|
||||
this.contextRunner.withClassLoader(new FilteredClassLoader(org.elasticsearch.client.RestHighLevelClient.class))
|
||||
.run((context) -> assertThat(context)
|
||||
.doesNotHaveBean(org.elasticsearch.client.RestHighLevelClient.class)
|
||||
.hasSingleBean(RestClient.class).hasSingleBean(RestClientBuilder.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
void configureWhenCustomRestHighLevelClientShouldBackOff() {
|
||||
this.contextRunner.withUserConfiguration(CustomRestHighLevelClientConfiguration.class).run(
|
||||
(context) -> assertThat(context).hasSingleBean(org.elasticsearch.client.RestHighLevelClient.class));
|
||||
this.contextRunner.withUserConfiguration(CustomRestHighLevelClientConfiguration.class)
|
||||
.run((context) -> assertThat(context).hasSingleBean(org.elasticsearch.client.RestHighLevelClient.class)
|
||||
.hasSingleBean(RestClient.class).hasBean("elasticsearchRestClient"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void configureWhenCustomRestHighLevelClientAndRestClientWithRestHighLevelClientShouldBackOff() {
|
||||
this.contextRunner.withUserConfiguration(CustomRestHighLevelClientWithRestClientConfiguration.class)
|
||||
.run((context) -> assertThat(context).hasSingleBean(org.elasticsearch.client.RestHighLevelClient.class)
|
||||
.hasSingleBean(RestClient.class).hasBean("customRestClient"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void configureWhenDefaultRestClientShouldCreateWhenNoUniqueRestHighLevelClient() {
|
||||
this.contextRunner.withUserConfiguration(TwoCustomRestHighLevelClientConfiguration.class).run((context) -> {
|
||||
assertThat(context).doesNotHaveBean(RestClient.class);
|
||||
Map<String, org.elasticsearch.client.RestHighLevelClient> restHighLevelClients = context
|
||||
.getBeansOfType(org.elasticsearch.client.RestHighLevelClient.class);
|
||||
assertThat(restHighLevelClients).hasSize(2);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void configureWhenDefaultRestClientShouldCreateWhenNoUniqueRestClient() {
|
||||
this.contextRunner.withClassLoader(new FilteredClassLoader(org.elasticsearch.client.RestHighLevelClient.class))
|
||||
.withUserConfiguration(TwoCustomRestClientConfiguration.class).run((context) -> {
|
||||
Map<String, RestClient> restClients = context.getBeansOfType(RestClient.class);
|
||||
assertThat(restClients).hasSize(2);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void configureWhenBuilderCustomizerShouldApply() {
|
||||
this.contextRunner.withUserConfiguration(BuilderCustomizerConfiguration.class).run((context) -> {
|
||||
assertThat(context).hasSingleBean(org.elasticsearch.client.RestHighLevelClient.class);
|
||||
assertThat(context).hasSingleBean(org.elasticsearch.client.RestHighLevelClient.class)
|
||||
.hasSingleBean(RestClient.class);
|
||||
org.elasticsearch.client.RestHighLevelClient restClient = context
|
||||
.getBean(org.elasticsearch.client.RestHighLevelClient.class);
|
||||
RestClient lowLevelClient = restClient.getLowLevelClient();
|
||||
@@ -118,9 +148,8 @@ class ElasticsearchRestClientAutoConfigurationTests {
|
||||
@Test
|
||||
void configureWithNoTimeoutsApplyDefaults() {
|
||||
this.contextRunner.run((context) -> {
|
||||
assertThat(context).hasSingleBean(org.elasticsearch.client.RestHighLevelClient.class);
|
||||
org.elasticsearch.client.RestHighLevelClient restClient = context
|
||||
.getBean(org.elasticsearch.client.RestHighLevelClient.class);
|
||||
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));
|
||||
});
|
||||
@@ -130,9 +159,8 @@ class ElasticsearchRestClientAutoConfigurationTests {
|
||||
void configureWithLegacyCustomTimeouts() {
|
||||
this.contextRunner.withPropertyValues("spring.elasticsearch.rest.connection-timeout=15s",
|
||||
"spring.elasticsearch.rest.read-timeout=1m").run((context) -> {
|
||||
assertThat(context).hasSingleBean(org.elasticsearch.client.RestHighLevelClient.class);
|
||||
org.elasticsearch.client.RestHighLevelClient restClient = context
|
||||
.getBean(org.elasticsearch.client.RestHighLevelClient.class);
|
||||
assertThat(context).hasSingleBean(RestClient.class);
|
||||
RestClient restClient = context.getBean(RestClient.class);
|
||||
assertTimeouts(restClient, Duration.ofSeconds(15), Duration.ofMinutes(1));
|
||||
});
|
||||
}
|
||||
@@ -141,25 +169,23 @@ class ElasticsearchRestClientAutoConfigurationTests {
|
||||
void configureWithCustomTimeouts() {
|
||||
this.contextRunner.withPropertyValues("spring.elasticsearch.connection-timeout=15s",
|
||||
"spring.elasticsearch.socket-timeout=1m").run((context) -> {
|
||||
assertThat(context).hasSingleBean(org.elasticsearch.client.RestHighLevelClient.class);
|
||||
org.elasticsearch.client.RestHighLevelClient restClient = context
|
||||
.getBean(org.elasticsearch.client.RestHighLevelClient.class);
|
||||
assertThat(context).hasSingleBean(RestClient.class);
|
||||
RestClient restClient = context.getBean(RestClient.class);
|
||||
assertTimeouts(restClient, Duration.ofSeconds(15), Duration.ofMinutes(1));
|
||||
});
|
||||
}
|
||||
|
||||
private static void assertTimeouts(org.elasticsearch.client.RestHighLevelClient restClient, Duration connectTimeout,
|
||||
Duration readTimeout) {
|
||||
assertThat(restClient.getLowLevelClient()).extracting("client.defaultConfig.socketTimeout")
|
||||
private static void assertTimeouts(RestClient restClient, Duration connectTimeout, Duration readTimeout) {
|
||||
assertThat(restClient).extracting("client.defaultConfig.socketTimeout")
|
||||
.isEqualTo(Math.toIntExact(readTimeout.toMillis()));
|
||||
assertThat(restClient.getLowLevelClient()).extracting("client.defaultConfig.connectTimeout")
|
||||
assertThat(restClient).extracting("client.defaultConfig.connectTimeout")
|
||||
.isEqualTo(Math.toIntExact(connectTimeout.toMillis()));
|
||||
}
|
||||
|
||||
@ParameterizedPropertyPrefixTest
|
||||
void configureUriWithNoScheme(String prefix) {
|
||||
this.contextRunner.withPropertyValues(prefix + "uris=localhost:9876").run((context) -> {
|
||||
RestClient client = context.getBean(org.elasticsearch.client.RestHighLevelClient.class).getLowLevelClient();
|
||||
RestClient client = context.getBean(RestClient.class);
|
||||
assertThat(client.getNodes().stream().map(Node::getHost).map(HttpHost::toString))
|
||||
.containsExactly("http://localhost:9876");
|
||||
});
|
||||
@@ -168,7 +194,7 @@ class ElasticsearchRestClientAutoConfigurationTests {
|
||||
@ParameterizedPropertyPrefixTest
|
||||
void configureUriWithUsernameOnly(String prefix) {
|
||||
this.contextRunner.withPropertyValues(prefix + "uris=http://user@localhost:9200").run((context) -> {
|
||||
RestClient client = context.getBean(org.elasticsearch.client.RestHighLevelClient.class).getLowLevelClient();
|
||||
RestClient client = context.getBean(RestClient.class);
|
||||
assertThat(client.getNodes().stream().map(Node::getHost).map(HttpHost::toString))
|
||||
.containsExactly("http://localhost:9200");
|
||||
assertThat(client)
|
||||
@@ -184,7 +210,7 @@ class ElasticsearchRestClientAutoConfigurationTests {
|
||||
@ParameterizedPropertyPrefixTest
|
||||
void configureUriWithUsernameAndEmptyPassword(String prefix) {
|
||||
this.contextRunner.withPropertyValues(prefix + "uris=http://user:@localhost:9200").run((context) -> {
|
||||
RestClient client = context.getBean(org.elasticsearch.client.RestHighLevelClient.class).getLowLevelClient();
|
||||
RestClient client = context.getBean(RestClient.class);
|
||||
assertThat(client.getNodes().stream().map(Node::getHost).map(HttpHost::toString))
|
||||
.containsExactly("http://localhost:9200");
|
||||
assertThat(client)
|
||||
@@ -201,8 +227,7 @@ class ElasticsearchRestClientAutoConfigurationTests {
|
||||
void configureUriWithUsernameAndPasswordWhenUsernameAndPasswordPropertiesSet(String prefix) {
|
||||
this.contextRunner.withPropertyValues(prefix + "uris=http://user:password@localhost:9200,localhost:9201",
|
||||
prefix + "username=admin", prefix + "password=admin").run((context) -> {
|
||||
RestClient client = context.getBean(org.elasticsearch.client.RestHighLevelClient.class)
|
||||
.getLowLevelClient();
|
||||
RestClient client = context.getBean(RestClient.class);
|
||||
assertThat(client.getNodes().stream().map(Node::getHost).map(HttpHost::toString))
|
||||
.containsExactly("http://localhost:9200", "http://localhost:9201");
|
||||
assertThat(client)
|
||||
@@ -224,7 +249,7 @@ class ElasticsearchRestClientAutoConfigurationTests {
|
||||
@Test
|
||||
void configureWithCustomPathPrefix() {
|
||||
this.contextRunner.withPropertyValues("spring.elasticsearch.path-prefix=/some/prefix").run((context) -> {
|
||||
RestClient client = context.getBean(org.elasticsearch.client.RestHighLevelClient.class).getLowLevelClient();
|
||||
RestClient client = context.getBean(RestClient.class);
|
||||
assertThat(client).extracting("pathPrefix").isEqualTo("/some/prefix");
|
||||
});
|
||||
}
|
||||
@@ -233,19 +258,21 @@ class ElasticsearchRestClientAutoConfigurationTests {
|
||||
void configureWithoutSnifferLibraryShouldNotCreateSniffer() {
|
||||
this.contextRunner.withClassLoader(new FilteredClassLoader("org.elasticsearch.client.sniff"))
|
||||
.run((context) -> assertThat(context).hasSingleBean(org.elasticsearch.client.RestHighLevelClient.class)
|
||||
.doesNotHaveBean(Sniffer.class));
|
||||
.hasSingleBean(RestClient.class).doesNotHaveBean(Sniffer.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
void configureShouldCreateSnifferUsingRestHighLevelClient() {
|
||||
this.contextRunner.run((context) -> {
|
||||
assertThat(context).hasSingleBean(Sniffer.class);
|
||||
assertThat(context.getBean(Sniffer.class)).hasFieldOrPropertyWithValue("restClient",
|
||||
context.getBean(org.elasticsearch.client.RestHighLevelClient.class).getLowLevelClient());
|
||||
// Validate shutdown order as the sniffer must be shutdown before the client
|
||||
assertThat(context.getBeanFactory().getDependentBeans("elasticsearchRestHighLevelClient"))
|
||||
.contains("elasticsearchSniffer");
|
||||
});
|
||||
void configureShouldCreateSnifferUsingRestClient() {
|
||||
this.contextRunner.withClassLoader(new FilteredClassLoader(org.elasticsearch.client.RestHighLevelClient.class))
|
||||
.run((context) -> {
|
||||
assertThat(context).hasSingleBean(Sniffer.class);
|
||||
assertThat(context.getBean(Sniffer.class)).hasFieldOrPropertyWithValue("restClient",
|
||||
context.getBean(RestClient.class));
|
||||
// Validate shutdown order as the sniffer must be shutdown before the
|
||||
// client
|
||||
assertThat(context.getBeanFactory().getDependentBeans("elasticsearchRestClient"))
|
||||
.contains("elasticsearchSniffer");
|
||||
});
|
||||
}
|
||||
|
||||
@ParameterizedSnifferPropertyPrefixTest
|
||||
@@ -309,6 +336,21 @@ class ElasticsearchRestClientAutoConfigurationTests {
|
||||
|
||||
}
|
||||
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
static class CustomRestHighLevelClientWithRestClientConfiguration {
|
||||
|
||||
@Bean
|
||||
org.elasticsearch.client.RestHighLevelClient customRestHighLevelClient(RestClientBuilder builder) {
|
||||
return new org.elasticsearch.client.RestHighLevelClient(builder);
|
||||
}
|
||||
|
||||
@Bean
|
||||
RestClient customRestClient(org.elasticsearch.client.RestHighLevelClient restHighLevelClient) {
|
||||
return restHighLevelClient.getLowLevelClient();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
static class TwoCustomRestHighLevelClientConfiguration {
|
||||
|
||||
@@ -334,6 +376,21 @@ class ElasticsearchRestClientAutoConfigurationTests {
|
||||
|
||||
}
|
||||
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
static class TwoCustomRestClientConfiguration {
|
||||
|
||||
@Bean
|
||||
RestClient customRestClient(RestClientBuilder builder) {
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
RestClient customRestClient1(RestClientBuilder builder) {
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@Target(ElementType.METHOD)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
|
||||
Reference in New Issue
Block a user