Start building against Spring Data 2021.2.0-M1 snapshots
This commit also upgrades to Elasticsearch 7.16.2 See gh-29223 See gh-29292
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2020 the original author or authors.
|
||||
* Copyright 2012-2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -32,7 +32,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
|
||||
import org.springframework.boot.autoconfigure.data.elasticsearch.ReactiveElasticsearchRestClientAutoConfiguration;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.data.elasticsearch.client.reactive.ReactiveElasticsearchClient;
|
||||
import org.springframework.data.elasticsearch.backend.elasticsearch7.client.reactive.ReactiveElasticsearchClient;
|
||||
|
||||
/**
|
||||
* {@link EnableAutoConfiguration Auto-configuration} for
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2020 the original author or authors.
|
||||
* Copyright 2012-2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -19,7 +19,6 @@ package org.springframework.boot.actuate.autoconfigure.elasticsearch;
|
||||
import java.util.Map;
|
||||
|
||||
import org.elasticsearch.client.RestClient;
|
||||
import org.elasticsearch.client.RestHighLevelClient;
|
||||
|
||||
import org.springframework.boot.actuate.autoconfigure.health.CompositeHealthContributorConfiguration;
|
||||
import org.springframework.boot.actuate.autoconfigure.health.ConditionalOnEnabledHealthIndicator;
|
||||
@@ -41,17 +40,19 @@ import org.springframework.context.annotation.Configuration;
|
||||
* @author Artsiom Yudovin
|
||||
* @since 2.1.1
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
@ConditionalOnClass(RestHighLevelClient.class)
|
||||
@ConditionalOnBean(RestHighLevelClient.class)
|
||||
@ConditionalOnClass(org.elasticsearch.client.RestHighLevelClient.class)
|
||||
@ConditionalOnBean(org.elasticsearch.client.RestHighLevelClient.class)
|
||||
@ConditionalOnEnabledHealthIndicator("elasticsearch")
|
||||
@AutoConfigureAfter(ElasticsearchRestClientAutoConfiguration.class)
|
||||
public class ElasticSearchRestHealthContributorAutoConfiguration
|
||||
extends CompositeHealthContributorConfiguration<ElasticsearchRestHealthIndicator, RestHighLevelClient> {
|
||||
public class ElasticSearchRestHealthContributorAutoConfiguration extends
|
||||
CompositeHealthContributorConfiguration<ElasticsearchRestHealthIndicator, org.elasticsearch.client.RestHighLevelClient> {
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean(name = { "elasticsearchHealthIndicator", "elasticsearchHealthContributor" })
|
||||
public HealthContributor elasticsearchHealthContributor(Map<String, RestHighLevelClient> clients) {
|
||||
public HealthContributor elasticsearchHealthContributor(
|
||||
Map<String, org.elasticsearch.client.RestHighLevelClient> clients) {
|
||||
return createContributor(clients);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2020 the original author or authors.
|
||||
* Copyright 2012-2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -25,7 +25,7 @@ import org.springframework.boot.actuate.health.Health;
|
||||
import org.springframework.boot.actuate.health.HealthIndicator;
|
||||
import org.springframework.boot.actuate.health.Status;
|
||||
import org.springframework.core.ParameterizedTypeReference;
|
||||
import org.springframework.data.elasticsearch.client.reactive.ReactiveElasticsearchClient;
|
||||
import org.springframework.data.elasticsearch.backend.elasticsearch7.client.reactive.ReactiveElasticsearchClient;
|
||||
import org.springframework.web.reactive.function.client.ClientResponse;
|
||||
import org.springframework.web.reactive.function.client.WebClient;
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2020 the original author or authors.
|
||||
* Copyright 2012-2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -25,7 +25,6 @@ import org.apache.http.StatusLine;
|
||||
import org.elasticsearch.client.Request;
|
||||
import org.elasticsearch.client.Response;
|
||||
import org.elasticsearch.client.RestClient;
|
||||
import org.elasticsearch.client.RestHighLevelClient;
|
||||
|
||||
import org.springframework.boot.actuate.health.AbstractHealthIndicator;
|
||||
import org.springframework.boot.actuate.health.Health;
|
||||
@@ -50,7 +49,8 @@ public class ElasticsearchRestHealthIndicator extends AbstractHealthIndicator {
|
||||
|
||||
private final JsonParser jsonParser;
|
||||
|
||||
public ElasticsearchRestHealthIndicator(RestHighLevelClient client) {
|
||||
@SuppressWarnings("deprecation")
|
||||
public ElasticsearchRestHealthIndicator(org.elasticsearch.client.RestHighLevelClient client) {
|
||||
this(client.getLowLevelClient());
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2020 the original author or authors.
|
||||
* Copyright 2012-2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -26,9 +26,9 @@ import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.boot.actuate.health.Health;
|
||||
import org.springframework.boot.actuate.health.Status;
|
||||
import org.springframework.data.elasticsearch.backend.elasticsearch7.client.reactive.DefaultReactiveElasticsearchClient;
|
||||
import org.springframework.data.elasticsearch.backend.elasticsearch7.client.reactive.ReactiveElasticsearchClient;
|
||||
import org.springframework.data.elasticsearch.client.ClientConfiguration;
|
||||
import org.springframework.data.elasticsearch.client.reactive.DefaultReactiveElasticsearchClient;
|
||||
import org.springframework.data.elasticsearch.client.reactive.ReactiveElasticsearchClient;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.MediaType;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2021 the original author or authors.
|
||||
* Copyright 2012-2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -22,7 +22,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.boot.autoconfigure.elasticsearch.ElasticsearchRestClientAutoConfiguration;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate;
|
||||
import org.springframework.data.elasticsearch.backend.elasticsearch7.ElasticsearchRestTemplate;
|
||||
import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories;
|
||||
import org.springframework.data.elasticsearch.repository.config.EnableReactiveElasticsearchRepositories;
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2021 the original author or authors.
|
||||
* Copyright 2012-2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -19,7 +19,6 @@ package org.springframework.boot.autoconfigure.data.elasticsearch;
|
||||
import java.util.Collections;
|
||||
|
||||
import org.elasticsearch.action.support.IndicesOptions;
|
||||
import org.elasticsearch.client.RestHighLevelClient;
|
||||
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
@@ -29,11 +28,11 @@ import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.data.elasticsearch.annotations.Document;
|
||||
import org.springframework.data.elasticsearch.client.reactive.ReactiveElasticsearchClient;
|
||||
import org.springframework.data.elasticsearch.backend.elasticsearch7.ElasticsearchRestTemplate;
|
||||
import org.springframework.data.elasticsearch.backend.elasticsearch7.ReactiveElasticsearchTemplate;
|
||||
import org.springframework.data.elasticsearch.backend.elasticsearch7.client.reactive.ReactiveElasticsearchClient;
|
||||
import org.springframework.data.elasticsearch.core.ElasticsearchOperations;
|
||||
import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate;
|
||||
import org.springframework.data.elasticsearch.core.ReactiveElasticsearchOperations;
|
||||
import org.springframework.data.elasticsearch.core.ReactiveElasticsearchTemplate;
|
||||
import org.springframework.data.elasticsearch.core.RefreshPolicy;
|
||||
import org.springframework.data.elasticsearch.core.convert.ElasticsearchConverter;
|
||||
import org.springframework.data.elasticsearch.core.convert.ElasticsearchCustomConversions;
|
||||
@@ -83,14 +82,16 @@ abstract class ElasticsearchDataConfiguration {
|
||||
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
@ConditionalOnClass(RestHighLevelClient.class)
|
||||
@ConditionalOnClass(org.elasticsearch.client.RestHighLevelClient.class)
|
||||
static class RestClientConfiguration {
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean(value = ElasticsearchOperations.class, name = "elasticsearchTemplate")
|
||||
@ConditionalOnBean(RestHighLevelClient.class)
|
||||
ElasticsearchRestTemplate elasticsearchTemplate(RestHighLevelClient client, ElasticsearchConverter converter) {
|
||||
@ConditionalOnBean(org.elasticsearch.client.RestHighLevelClient.class)
|
||||
ElasticsearchRestTemplate elasticsearchTemplate(org.elasticsearch.client.RestHighLevelClient client,
|
||||
ElasticsearchConverter converter) {
|
||||
return new ElasticsearchRestTemplate(client, converter);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2021 the original author or authors.
|
||||
* Copyright 2012-2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -22,7 +22,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.data.elasticsearch.client.reactive.ReactiveElasticsearchClient;
|
||||
import org.springframework.data.elasticsearch.backend.elasticsearch7.client.reactive.ReactiveElasticsearchClient;
|
||||
import org.springframework.data.elasticsearch.repository.ReactiveElasticsearchRepository;
|
||||
import org.springframework.data.elasticsearch.repository.config.EnableReactiveElasticsearchRepositories;
|
||||
import org.springframework.data.elasticsearch.repository.support.ReactiveElasticsearchRepositoryFactoryBean;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2021 the original author or authors.
|
||||
* Copyright 2012-2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -32,8 +32,8 @@ import org.springframework.boot.context.properties.EnableConfigurationProperties
|
||||
import org.springframework.boot.context.properties.PropertyMapper;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.data.elasticsearch.backend.elasticsearch7.client.reactive.ReactiveElasticsearchClient;
|
||||
import org.springframework.data.elasticsearch.client.ClientConfiguration;
|
||||
import org.springframework.data.elasticsearch.client.reactive.ReactiveElasticsearchClient;
|
||||
import org.springframework.data.elasticsearch.client.reactive.ReactiveRestClients;
|
||||
import org.springframework.data.elasticsearch.client.reactive.ReactiveRestClients.WebClientConfigurationCallback;
|
||||
import org.springframework.util.Assert;
|
||||
@@ -133,7 +133,7 @@ public class ReactiveElasticsearchRestClientAutoConfiguration {
|
||||
return Credentials.from(this.deprecatedProperties);
|
||||
}
|
||||
Credentials propertyCredentials = Credentials.from(this.properties);
|
||||
Credentials uriCredentials = Credentials.from(this.properties.getUris());
|
||||
Credentials uriCredentials = Credentials.from(this.uris);
|
||||
if (uriCredentials == null) {
|
||||
return propertyCredentials;
|
||||
}
|
||||
@@ -190,9 +190,8 @@ public class ReactiveElasticsearchRestClientAutoConfiguration {
|
||||
return this.password;
|
||||
}
|
||||
|
||||
private static Credentials from(List<String> uris) {
|
||||
Set<String> userInfos = uris.stream().map(URI::create).map(URI::getUserInfo)
|
||||
.collect(Collectors.toSet());
|
||||
private static Credentials from(List<URI> uris) {
|
||||
Set<String> userInfos = uris.stream().map(URI::getUserInfo).collect(Collectors.toSet());
|
||||
Assert.isTrue(userInfos.size() == 1, "Configured Elasticsearch URIs have varying user infos");
|
||||
String userInfo = userInfos.iterator().next();
|
||||
if (userInfo == null) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2021 the original author or authors.
|
||||
* Copyright 2012-2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -30,7 +30,6 @@ import org.apache.http.impl.client.BasicCredentialsProvider;
|
||||
import org.apache.http.impl.nio.client.HttpAsyncClientBuilder;
|
||||
import org.elasticsearch.client.RestClient;
|
||||
import org.elasticsearch.client.RestClientBuilder;
|
||||
import org.elasticsearch.client.RestHighLevelClient;
|
||||
import org.elasticsearch.client.sniff.Sniffer;
|
||||
import org.elasticsearch.client.sniff.SnifferBuilder;
|
||||
|
||||
@@ -111,27 +110,30 @@ class ElasticsearchRestClientConfigurations {
|
||||
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
@ConditionalOnClass(RestHighLevelClient.class)
|
||||
@ConditionalOnMissingBean({ RestHighLevelClient.class, RestClient.class })
|
||||
@ConditionalOnClass(org.elasticsearch.client.RestHighLevelClient.class)
|
||||
@ConditionalOnMissingBean({ org.elasticsearch.client.RestHighLevelClient.class, RestClient.class })
|
||||
static class RestHighLevelClientConfiguration {
|
||||
|
||||
@Bean
|
||||
RestHighLevelClient elasticsearchRestHighLevelClient(RestClientBuilder restClientBuilder) {
|
||||
return new RestHighLevelClient(restClientBuilder);
|
||||
org.elasticsearch.client.RestHighLevelClient elasticsearchRestHighLevelClient(
|
||||
RestClientBuilder restClientBuilder) {
|
||||
return new org.elasticsearch.client.RestHighLevelClient(restClientBuilder);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
@ConditionalOnClass(Sniffer.class)
|
||||
@ConditionalOnSingleCandidate(RestHighLevelClient.class)
|
||||
@ConditionalOnSingleCandidate(org.elasticsearch.client.RestHighLevelClient.class)
|
||||
static class RestClientSnifferConfiguration {
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
@SuppressWarnings("deprecation")
|
||||
Sniffer elasticsearchSniffer(RestHighLevelClient client, ElasticsearchRestClientProperties properties,
|
||||
Sniffer elasticsearchSniffer(org.elasticsearch.client.RestHighLevelClient client,
|
||||
ElasticsearchRestClientProperties properties,
|
||||
DeprecatedElasticsearchRestClientProperties deprecatedProperties) {
|
||||
SnifferBuilder builder = Sniffer.builder(client.getLowLevelClient());
|
||||
PropertyMapper map = PropertyMapper.get().alwaysApplyingWhenNonNull();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2021 the original author or authors.
|
||||
* Copyright 2012-2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -19,13 +19,12 @@ package org.springframework.boot.autoconfigure.elasticsearch;
|
||||
import java.time.Duration;
|
||||
|
||||
import org.elasticsearch.client.RestClient;
|
||||
import org.elasticsearch.client.RestHighLevelClient;
|
||||
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
|
||||
/**
|
||||
* Configuration properties specific to Elasticsearch's {@link RestClient} and
|
||||
* {@link RestHighLevelClient}.
|
||||
* {@link org.elasticsearch.client.RestHighLevelClient}.
|
||||
*
|
||||
* @author Brian Clozel
|
||||
* @since 2.1.0
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2021 the original author or authors.
|
||||
* Copyright 2012-2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -32,8 +32,8 @@ import org.springframework.boot.test.context.runner.ApplicationContextRunner;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.convert.converter.Converter;
|
||||
import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate;
|
||||
import org.springframework.data.elasticsearch.core.ReactiveElasticsearchTemplate;
|
||||
import org.springframework.data.elasticsearch.backend.elasticsearch7.ElasticsearchRestTemplate;
|
||||
import org.springframework.data.elasticsearch.backend.elasticsearch7.ReactiveElasticsearchTemplate;
|
||||
import org.springframework.data.elasticsearch.core.convert.ElasticsearchConverter;
|
||||
import org.springframework.data.elasticsearch.core.convert.ElasticsearchCustomConversions;
|
||||
import org.springframework.data.elasticsearch.core.mapping.SimpleElasticsearchMappingContext;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2020 the original author or authors.
|
||||
* Copyright 2012-2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -33,7 +33,7 @@ import org.springframework.boot.autoconfigure.elasticsearch.ElasticsearchRestCli
|
||||
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
|
||||
import org.springframework.boot.testsupport.testcontainers.DockerImageNames;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate;
|
||||
import org.springframework.data.elasticsearch.backend.elasticsearch7.ElasticsearchRestTemplate;
|
||||
import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2021 the original author or authors.
|
||||
* Copyright 2012-2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -32,7 +32,7 @@ import org.springframework.boot.autoconfigure.data.empty.EmptyDataPackage;
|
||||
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
|
||||
import org.springframework.boot.testsupport.testcontainers.DockerImageNames;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.data.elasticsearch.core.ReactiveElasticsearchTemplate;
|
||||
import org.springframework.data.elasticsearch.backend.elasticsearch7.ReactiveElasticsearchTemplate;
|
||||
import org.springframework.data.elasticsearch.repository.config.EnableReactiveElasticsearchRepositories;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2021 the original author or authors.
|
||||
* Copyright 2012-2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -31,7 +31,7 @@ import org.testcontainers.junit.jupiter.Testcontainers;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
||||
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
|
||||
import org.springframework.boot.testsupport.testcontainers.DockerImageNames;
|
||||
import org.springframework.data.elasticsearch.client.reactive.ReactiveElasticsearchClient;
|
||||
import org.springframework.data.elasticsearch.backend.elasticsearch7.client.reactive.ReactiveElasticsearchClient;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2021 the original author or authors.
|
||||
* Copyright 2012-2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -35,9 +35,9 @@ import org.springframework.boot.autoconfigure.AutoConfigurations;
|
||||
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.data.elasticsearch.backend.elasticsearch7.client.reactive.ReactiveElasticsearchClient;
|
||||
import org.springframework.data.elasticsearch.client.ClientConfiguration;
|
||||
import org.springframework.data.elasticsearch.client.ClientConfiguration.ClientConfigurationCallback;
|
||||
import org.springframework.data.elasticsearch.client.reactive.ReactiveElasticsearchClient;
|
||||
import org.springframework.data.elasticsearch.client.reactive.ReactiveRestClients;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.codec.CodecConfigurer.DefaultCodecConfig;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2021 the original author or authors.
|
||||
* Copyright 2012-2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -23,7 +23,6 @@ import java.util.Map;
|
||||
import org.elasticsearch.action.get.GetRequest;
|
||||
import org.elasticsearch.action.index.IndexRequest;
|
||||
import org.elasticsearch.client.RequestOptions;
|
||||
import org.elasticsearch.client.RestHighLevelClient;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.testcontainers.elasticsearch.ElasticsearchContainer;
|
||||
import org.testcontainers.junit.jupiter.Container;
|
||||
@@ -53,12 +52,14 @@ class ElasticsearchRestClientAutoConfigurationIntegrationTests {
|
||||
.withConfiguration(AutoConfigurations.of(ElasticsearchRestClientAutoConfiguration.class));
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation")
|
||||
void restClientCanQueryElasticsearchNode() {
|
||||
this.contextRunner
|
||||
.withPropertyValues("spring.elasticsearch.uris=" + elasticsearch.getHttpHostAddress(),
|
||||
"spring.elasticsearch.connection-timeout=120s", "spring.elasticsearch.socket-timeout=120s")
|
||||
.run((context) -> {
|
||||
RestHighLevelClient client = context.getBean(RestHighLevelClient.class);
|
||||
org.elasticsearch.client.RestHighLevelClient client = context
|
||||
.getBean(org.elasticsearch.client.RestHighLevelClient.class);
|
||||
Map<String, String> source = new HashMap<>();
|
||||
source.put("a", "alpha");
|
||||
source.put("b", "bravo");
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2021 the original author or authors.
|
||||
* Copyright 2012-2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -33,7 +33,6 @@ import org.assertj.core.api.InstanceOfAssertFactories;
|
||||
import org.elasticsearch.client.Node;
|
||||
import org.elasticsearch.client.RestClient;
|
||||
import org.elasticsearch.client.RestClientBuilder;
|
||||
import org.elasticsearch.client.RestHighLevelClient;
|
||||
import org.elasticsearch.client.sniff.Sniffer;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
@@ -57,6 +56,7 @@ import static org.mockito.Mockito.verifyNoInteractions;
|
||||
* @author Evgeniy Cheban
|
||||
* @author Filip Hrisafov
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
class ElasticsearchRestClientAutoConfigurationTests {
|
||||
|
||||
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
|
||||
@@ -65,34 +65,39 @@ class ElasticsearchRestClientAutoConfigurationTests {
|
||||
@Test
|
||||
void configureShouldOnlyCreateHighLevelRestClient() {
|
||||
this.contextRunner.run((context) -> assertThat(context).doesNotHaveBean(RestClient.class)
|
||||
.hasSingleBean(RestClientBuilder.class).hasSingleBean(RestHighLevelClient.class));
|
||||
.hasSingleBean(RestClientBuilder.class)
|
||||
.hasSingleBean(org.elasticsearch.client.RestHighLevelClient.class));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
void configureWithoutRestHighLevelClientShouldOnlyCreateRestClientBuilder() {
|
||||
this.contextRunner.withClassLoader(new FilteredClassLoader(RestHighLevelClient.class))
|
||||
this.contextRunner.withClassLoader(new FilteredClassLoader(org.elasticsearch.client.RestHighLevelClient.class))
|
||||
.run((context) -> assertThat(context).doesNotHaveBean(RestClient.class)
|
||||
.doesNotHaveBean(RestHighLevelClient.class).hasSingleBean(RestClientBuilder.class));
|
||||
.doesNotHaveBean(org.elasticsearch.client.RestHighLevelClient.class)
|
||||
.hasSingleBean(RestClientBuilder.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
void configureWhenCustomRestClientShouldBackOff() {
|
||||
this.contextRunner.withUserConfiguration(CustomRestClientConfiguration.class)
|
||||
.run((context) -> assertThat(context).doesNotHaveBean(RestHighLevelClient.class)
|
||||
.run((context) -> assertThat(context)
|
||||
.doesNotHaveBean(org.elasticsearch.client.RestHighLevelClient.class)
|
||||
.hasSingleBean(RestClientBuilder.class).hasSingleBean(RestClient.class)
|
||||
.hasBean("customRestClient"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void configureWhenCustomRestHighLevelClientShouldBackOff() {
|
||||
this.contextRunner.withUserConfiguration(CustomRestHighLevelClientConfiguration.class)
|
||||
.run((context) -> assertThat(context).hasSingleBean(RestHighLevelClient.class));
|
||||
this.contextRunner.withUserConfiguration(CustomRestHighLevelClientConfiguration.class).run(
|
||||
(context) -> assertThat(context).hasSingleBean(org.elasticsearch.client.RestHighLevelClient.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
void configureWhenDefaultRestClientShouldCreateWhenNoUniqueRestHighLevelClient() {
|
||||
this.contextRunner.withUserConfiguration(TwoCustomRestHighLevelClientConfiguration.class).run((context) -> {
|
||||
Map<String, RestHighLevelClient> restHighLevelClients = context.getBeansOfType(RestHighLevelClient.class);
|
||||
Map<String, org.elasticsearch.client.RestHighLevelClient> restHighLevelClients = context
|
||||
.getBeansOfType(org.elasticsearch.client.RestHighLevelClient.class);
|
||||
assertThat(restHighLevelClients).hasSize(2);
|
||||
});
|
||||
}
|
||||
@@ -100,8 +105,9 @@ class ElasticsearchRestClientAutoConfigurationTests {
|
||||
@Test
|
||||
void configureWhenBuilderCustomizerShouldApply() {
|
||||
this.contextRunner.withUserConfiguration(BuilderCustomizerConfiguration.class).run((context) -> {
|
||||
assertThat(context).hasSingleBean(RestHighLevelClient.class);
|
||||
RestHighLevelClient restClient = context.getBean(RestHighLevelClient.class);
|
||||
assertThat(context).hasSingleBean(org.elasticsearch.client.RestHighLevelClient.class);
|
||||
org.elasticsearch.client.RestHighLevelClient restClient = context
|
||||
.getBean(org.elasticsearch.client.RestHighLevelClient.class);
|
||||
RestClient lowLevelClient = restClient.getLowLevelClient();
|
||||
assertThat(lowLevelClient).hasFieldOrPropertyWithValue("pathPrefix", "/test");
|
||||
assertThat(lowLevelClient).extracting("client.connmgr.pool.maxTotal").isEqualTo(100);
|
||||
@@ -112,8 +118,9 @@ class ElasticsearchRestClientAutoConfigurationTests {
|
||||
@Test
|
||||
void configureWithNoTimeoutsApplyDefaults() {
|
||||
this.contextRunner.run((context) -> {
|
||||
assertThat(context).hasSingleBean(RestHighLevelClient.class);
|
||||
RestHighLevelClient restClient = context.getBean(RestHighLevelClient.class);
|
||||
assertThat(context).hasSingleBean(org.elasticsearch.client.RestHighLevelClient.class);
|
||||
org.elasticsearch.client.RestHighLevelClient restClient = context
|
||||
.getBean(org.elasticsearch.client.RestHighLevelClient.class);
|
||||
assertTimeouts(restClient, Duration.ofMillis(RestClientBuilder.DEFAULT_CONNECT_TIMEOUT_MILLIS),
|
||||
Duration.ofMillis(RestClientBuilder.DEFAULT_SOCKET_TIMEOUT_MILLIS));
|
||||
});
|
||||
@@ -123,8 +130,9 @@ class ElasticsearchRestClientAutoConfigurationTests {
|
||||
void configureWithLegacyCustomTimeouts() {
|
||||
this.contextRunner.withPropertyValues("spring.elasticsearch.rest.connection-timeout=15s",
|
||||
"spring.elasticsearch.rest.read-timeout=1m").run((context) -> {
|
||||
assertThat(context).hasSingleBean(RestHighLevelClient.class);
|
||||
RestHighLevelClient restClient = context.getBean(RestHighLevelClient.class);
|
||||
assertThat(context).hasSingleBean(org.elasticsearch.client.RestHighLevelClient.class);
|
||||
org.elasticsearch.client.RestHighLevelClient restClient = context
|
||||
.getBean(org.elasticsearch.client.RestHighLevelClient.class);
|
||||
assertTimeouts(restClient, Duration.ofSeconds(15), Duration.ofMinutes(1));
|
||||
});
|
||||
}
|
||||
@@ -133,13 +141,15 @@ class ElasticsearchRestClientAutoConfigurationTests {
|
||||
void configureWithCustomTimeouts() {
|
||||
this.contextRunner.withPropertyValues("spring.elasticsearch.connection-timeout=15s",
|
||||
"spring.elasticsearch.socket-timeout=1m").run((context) -> {
|
||||
assertThat(context).hasSingleBean(RestHighLevelClient.class);
|
||||
RestHighLevelClient restClient = context.getBean(RestHighLevelClient.class);
|
||||
assertThat(context).hasSingleBean(org.elasticsearch.client.RestHighLevelClient.class);
|
||||
org.elasticsearch.client.RestHighLevelClient restClient = context
|
||||
.getBean(org.elasticsearch.client.RestHighLevelClient.class);
|
||||
assertTimeouts(restClient, Duration.ofSeconds(15), Duration.ofMinutes(1));
|
||||
});
|
||||
}
|
||||
|
||||
private static void assertTimeouts(RestHighLevelClient restClient, Duration connectTimeout, Duration readTimeout) {
|
||||
private static void assertTimeouts(org.elasticsearch.client.RestHighLevelClient restClient, Duration connectTimeout,
|
||||
Duration readTimeout) {
|
||||
assertThat(restClient.getLowLevelClient()).extracting("client.defaultConfig.socketTimeout")
|
||||
.isEqualTo(Math.toIntExact(readTimeout.toMillis()));
|
||||
assertThat(restClient.getLowLevelClient()).extracting("client.defaultConfig.connectTimeout")
|
||||
@@ -149,7 +159,7 @@ class ElasticsearchRestClientAutoConfigurationTests {
|
||||
@ParameterizedPropertyPrefixTest
|
||||
void configureUriWithNoScheme(String prefix) {
|
||||
this.contextRunner.withPropertyValues(prefix + "uris=localhost:9876").run((context) -> {
|
||||
RestClient client = context.getBean(RestHighLevelClient.class).getLowLevelClient();
|
||||
RestClient client = context.getBean(org.elasticsearch.client.RestHighLevelClient.class).getLowLevelClient();
|
||||
assertThat(client.getNodes().stream().map(Node::getHost).map(HttpHost::toString))
|
||||
.containsExactly("http://localhost:9876");
|
||||
});
|
||||
@@ -158,7 +168,7 @@ class ElasticsearchRestClientAutoConfigurationTests {
|
||||
@ParameterizedPropertyPrefixTest
|
||||
void configureUriWithUsernameOnly(String prefix) {
|
||||
this.contextRunner.withPropertyValues(prefix + "uris=http://user@localhost:9200").run((context) -> {
|
||||
RestClient client = context.getBean(RestHighLevelClient.class).getLowLevelClient();
|
||||
RestClient client = context.getBean(org.elasticsearch.client.RestHighLevelClient.class).getLowLevelClient();
|
||||
assertThat(client.getNodes().stream().map(Node::getHost).map(HttpHost::toString))
|
||||
.containsExactly("http://localhost:9200");
|
||||
assertThat(client)
|
||||
@@ -174,7 +184,7 @@ class ElasticsearchRestClientAutoConfigurationTests {
|
||||
@ParameterizedPropertyPrefixTest
|
||||
void configureUriWithUsernameAndEmptyPassword(String prefix) {
|
||||
this.contextRunner.withPropertyValues(prefix + "uris=http://user:@localhost:9200").run((context) -> {
|
||||
RestClient client = context.getBean(RestHighLevelClient.class).getLowLevelClient();
|
||||
RestClient client = context.getBean(org.elasticsearch.client.RestHighLevelClient.class).getLowLevelClient();
|
||||
assertThat(client.getNodes().stream().map(Node::getHost).map(HttpHost::toString))
|
||||
.containsExactly("http://localhost:9200");
|
||||
assertThat(client)
|
||||
@@ -191,7 +201,8 @@ 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(RestHighLevelClient.class).getLowLevelClient();
|
||||
RestClient client = context.getBean(org.elasticsearch.client.RestHighLevelClient.class)
|
||||
.getLowLevelClient();
|
||||
assertThat(client.getNodes().stream().map(Node::getHost).map(HttpHost::toString))
|
||||
.containsExactly("http://localhost:9200", "http://localhost:9201");
|
||||
assertThat(client)
|
||||
@@ -213,7 +224,7 @@ class ElasticsearchRestClientAutoConfigurationTests {
|
||||
@Test
|
||||
void configureWithCustomPathPrefix() {
|
||||
this.contextRunner.withPropertyValues("spring.elasticsearch.path-prefix=/some/prefix").run((context) -> {
|
||||
RestClient client = context.getBean(RestHighLevelClient.class).getLowLevelClient();
|
||||
RestClient client = context.getBean(org.elasticsearch.client.RestHighLevelClient.class).getLowLevelClient();
|
||||
assertThat(client).extracting("pathPrefix").isEqualTo("/some/prefix");
|
||||
});
|
||||
}
|
||||
@@ -221,7 +232,7 @@ class ElasticsearchRestClientAutoConfigurationTests {
|
||||
@Test
|
||||
void configureWithoutSnifferLibraryShouldNotCreateSniffer() {
|
||||
this.contextRunner.withClassLoader(new FilteredClassLoader("org.elasticsearch.client.sniff"))
|
||||
.run((context) -> assertThat(context).hasSingleBean(RestHighLevelClient.class)
|
||||
.run((context) -> assertThat(context).hasSingleBean(org.elasticsearch.client.RestHighLevelClient.class)
|
||||
.doesNotHaveBean(Sniffer.class));
|
||||
}
|
||||
|
||||
@@ -230,7 +241,7 @@ class ElasticsearchRestClientAutoConfigurationTests {
|
||||
this.contextRunner.run((context) -> {
|
||||
assertThat(context).hasSingleBean(Sniffer.class);
|
||||
assertThat(context.getBean(Sniffer.class)).hasFieldOrPropertyWithValue("restClient",
|
||||
context.getBean(RestHighLevelClient.class).getLowLevelClient());
|
||||
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");
|
||||
@@ -292,8 +303,8 @@ class ElasticsearchRestClientAutoConfigurationTests {
|
||||
static class CustomRestHighLevelClientConfiguration {
|
||||
|
||||
@Bean
|
||||
RestHighLevelClient customRestHighLevelClient(RestClientBuilder builder) {
|
||||
return new RestHighLevelClient(builder);
|
||||
org.elasticsearch.client.RestHighLevelClient customRestHighLevelClient(RestClientBuilder builder) {
|
||||
return new org.elasticsearch.client.RestHighLevelClient(builder);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -302,13 +313,13 @@ class ElasticsearchRestClientAutoConfigurationTests {
|
||||
static class TwoCustomRestHighLevelClientConfiguration {
|
||||
|
||||
@Bean
|
||||
RestHighLevelClient customRestHighLevelClient(RestClientBuilder builder) {
|
||||
return new RestHighLevelClient(builder);
|
||||
org.elasticsearch.client.RestHighLevelClient customRestHighLevelClient(RestClientBuilder builder) {
|
||||
return new org.elasticsearch.client.RestHighLevelClient(builder);
|
||||
}
|
||||
|
||||
@Bean
|
||||
RestHighLevelClient customRestHighLevelClient1(RestClientBuilder builder) {
|
||||
return new RestHighLevelClient(builder);
|
||||
org.elasticsearch.client.RestHighLevelClient customoRestHighLevelClient1(RestClientBuilder builder) {
|
||||
return new org.elasticsearch.client.RestHighLevelClient(builder);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -276,7 +276,7 @@ bom {
|
||||
]
|
||||
}
|
||||
}
|
||||
library("Elasticsearch", "7.15.2") {
|
||||
library("Elasticsearch", "7.16.2") {
|
||||
group("org.elasticsearch") {
|
||||
modules = [
|
||||
"elasticsearch"
|
||||
@@ -1653,7 +1653,7 @@ bom {
|
||||
]
|
||||
}
|
||||
}
|
||||
library("Spring Data Bom", "2021.1.0") {
|
||||
library("Spring Data Bom", "2021.2.0-SNAPSHOT") {
|
||||
group("org.springframework.data") {
|
||||
imports = [
|
||||
"spring-data-bom"
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2021 the original author or authors.
|
||||
* Copyright 2012-2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
package org.springframework.boot.docs.data.nosql.elasticsearch.connectingusingspringdata;
|
||||
|
||||
import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate;
|
||||
import org.springframework.data.elasticsearch.backend.elasticsearch7.ElasticsearchRestTemplate;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
|
||||
Reference in New Issue
Block a user