Upgrade to Elasticsearch 7.5.1

See gh-19588
This commit is contained in:
Stephane Nicoll 2020-01-13 14:47:12 +01:00
parent f268ede3c0
commit d282eb619f
8 changed files with 73 additions and 66 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2020 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.
@ -27,15 +27,11 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
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.core.DefaultEntityMapper;
import org.springframework.data.elasticsearch.core.DefaultResultMapper;
import org.springframework.data.elasticsearch.core.ElasticsearchOperations;
import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate;
import org.springframework.data.elasticsearch.core.ElasticsearchTemplate;
import org.springframework.data.elasticsearch.core.EntityMapper;
import org.springframework.data.elasticsearch.core.ReactiveElasticsearchOperations;
import org.springframework.data.elasticsearch.core.ReactiveElasticsearchTemplate;
import org.springframework.data.elasticsearch.core.ResultsMapper;
import org.springframework.data.elasticsearch.core.convert.ElasticsearchConverter;
import org.springframework.data.elasticsearch.core.convert.MappingElasticsearchConverter;
import org.springframework.data.elasticsearch.core.mapping.SimpleElasticsearchMappingContext;
@ -48,6 +44,7 @@ import org.springframework.web.reactive.function.client.WebClient;
* their order of execution.
*
* @author Brian Clozel
* @author Scott Frederick
*/
abstract class ElasticsearchDataConfiguration {
@ -66,18 +63,6 @@ abstract class ElasticsearchDataConfiguration {
return new SimpleElasticsearchMappingContext();
}
@Bean
@ConditionalOnMissingBean
EntityMapper entityMapper(SimpleElasticsearchMappingContext mappingContext) {
return new DefaultEntityMapper(mappingContext);
}
@Bean
@ConditionalOnMissingBean
ResultsMapper resultsMapper(SimpleElasticsearchMappingContext mappingContext, EntityMapper entityMapper) {
return new DefaultResultMapper(mappingContext, entityMapper);
}
}
@Configuration(proxyBeanMethods = false)
@ -87,9 +72,8 @@ abstract class ElasticsearchDataConfiguration {
@Bean
@ConditionalOnMissingBean(value = ElasticsearchOperations.class, name = "elasticsearchTemplate")
@ConditionalOnBean(RestHighLevelClient.class)
ElasticsearchRestTemplate elasticsearchTemplate(RestHighLevelClient client, ElasticsearchConverter converter,
ResultsMapper resultsMapper) {
return new ElasticsearchRestTemplate(client, converter, resultsMapper);
ElasticsearchRestTemplate elasticsearchTemplate(RestHighLevelClient client, ElasticsearchConverter converter) {
return new ElasticsearchRestTemplate(client, converter);
}
}
@ -101,10 +85,10 @@ abstract class ElasticsearchDataConfiguration {
@Bean
@ConditionalOnMissingBean(value = ElasticsearchOperations.class, name = "elasticsearchTemplate")
@ConditionalOnBean(Client.class)
ElasticsearchTemplate elasticsearchTemplate(Client client, ElasticsearchConverter converter,
ResultsMapper resultsMapper) {
@Deprecated
ElasticsearchTemplate elasticsearchTemplate(Client client, ElasticsearchConverter converter) {
try {
return new ElasticsearchTemplate(client, converter, resultsMapper);
return new ElasticsearchTemplate(client, converter);
}
catch (Exception ex) {
throw new IllegalStateException(ex);
@ -121,9 +105,8 @@ abstract class ElasticsearchDataConfiguration {
@ConditionalOnMissingBean(value = ReactiveElasticsearchOperations.class, name = "reactiveElasticsearchTemplate")
@ConditionalOnBean(ReactiveElasticsearchClient.class)
ReactiveElasticsearchTemplate reactiveElasticsearchTemplate(ReactiveElasticsearchClient client,
ElasticsearchConverter converter, ResultsMapper resultsMapper) {
ReactiveElasticsearchTemplate template = new ReactiveElasticsearchTemplate(client, converter,
resultsMapper);
ElasticsearchConverter converter) {
ReactiveElasticsearchTemplate template = new ReactiveElasticsearchTemplate(client, converter);
template.setIndicesOptions(IndicesOptions.strictExpandOpenAndForbidClosed());
template.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE);
return template;

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2020 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.
@ -47,8 +47,8 @@ import static org.mockito.Mockito.mock;
class ElasticsearchAutoConfigurationTests {
@Container
public static ElasticsearchContainer elasticsearch = new ElasticsearchContainer().withStartupAttempts(5)
.withStartupTimeout(Duration.ofMinutes(10));
public static ElasticsearchContainer elasticsearch = new VersionOverridingElasticsearchContainer()
.withStartupAttempts(5).withStartupTimeout(Duration.ofMinutes(10));
private AnnotationConfigApplicationContext context;
@ -76,6 +76,7 @@ class ElasticsearchAutoConfigurationTests {
}
@Test
@SuppressWarnings("deprecation")
void createTransportClient() {
this.context = new AnnotationConfigApplicationContext();
TestPropertyValues

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2020 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,10 +30,8 @@ import org.springframework.boot.autoconfigure.elasticsearch.rest.RestClientAutoC
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.core.ElasticsearchEntityMapper;
import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate;
import org.springframework.data.elasticsearch.core.ElasticsearchTemplate;
import org.springframework.data.elasticsearch.core.EntityMapper;
import org.springframework.data.elasticsearch.core.ReactiveElasticsearchTemplate;
import org.springframework.data.elasticsearch.core.convert.ElasticsearchConverter;
import org.springframework.data.elasticsearch.core.mapping.SimpleElasticsearchMappingContext;
@ -48,12 +46,13 @@ import static org.mockito.Mockito.mock;
* @author Artur Konczak
* @author Brian Clozel
* @author Peter-Josef Meisch
* @author Scott Frederick
*/
@Testcontainers(disabledWithoutDocker = true)
class ElasticsearchDataAutoConfigurationTests {
@Container
static ElasticsearchContainer elasticsearch = new ElasticsearchContainer().withStartupAttempts(5)
static ElasticsearchContainer elasticsearch = new VersionOverridingElasticsearchContainer().withStartupAttempts(5)
.withStartupTimeout(Duration.ofMinutes(10));
private ApplicationContextRunner contextRunner = new ApplicationContextRunner().withConfiguration(
@ -71,6 +70,7 @@ class ElasticsearchDataAutoConfigurationTests {
}
@Test
@SuppressWarnings("deprecation")
void defaultTransportBeansAreRegistered() {
this.contextRunner
.withPropertyValues(
@ -83,6 +83,7 @@ class ElasticsearchDataAutoConfigurationTests {
}
@Test
@SuppressWarnings("deprecation")
void defaultTransportBeansNotRegisteredIfNoTransportClient() {
this.contextRunner.run((context) -> assertThat(context).doesNotHaveBean(ElasticsearchTemplate.class));
}
@ -91,16 +92,11 @@ class ElasticsearchDataAutoConfigurationTests {
void defaultRestBeansRegistered() {
this.contextRunner.run((context) -> assertThat(context).hasSingleBean(ElasticsearchRestTemplate.class)
.hasSingleBean(ReactiveElasticsearchTemplate.class).hasSingleBean(ElasticsearchConverter.class)
.hasSingleBean(SimpleElasticsearchMappingContext.class).hasSingleBean(EntityMapper.class)
.hasSingleBean(ElasticsearchConverter.class));
}
@Test
void defaultEntityMapperRegistered() {
this.contextRunner.run((context) -> assertThat(context).hasSingleBean(EntityMapper.class));
}
@Test
@SuppressWarnings("deprecation")
void customTransportTemplateShouldBeUsed() {
this.contextRunner.withUserConfiguration(CustomTransportTemplate.class).run((context) -> assertThat(context)
.getBeanNames(ElasticsearchTemplate.class).hasSize(1).contains("elasticsearchTemplate"));
@ -119,16 +115,11 @@ class ElasticsearchDataAutoConfigurationTests {
.contains("reactiveElasticsearchTemplate"));
}
@Test
void customEntityMapperShouldeBeUsed() {
this.contextRunner.withUserConfiguration(CustomEntityMapper.class).run((context) -> assertThat(context)
.getBeanNames(EntityMapper.class).containsExactly("elasticsearchEntityMapper"));
}
@Configuration(proxyBeanMethods = false)
static class CustomTransportTemplate {
@Bean
@SuppressWarnings("deprecation")
ElasticsearchTemplate elasticsearchTemplate() {
return mock(ElasticsearchTemplate.class);
}
@ -155,14 +146,4 @@ class ElasticsearchDataAutoConfigurationTests {
}
@Configuration(proxyBeanMethods = false)
static class CustomEntityMapper {
@Bean
EntityMapper elasticsearchEntityMapper() {
return mock(ElasticsearchEntityMapper.class);
}
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2020 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.
@ -48,8 +48,8 @@ import static org.assertj.core.api.Assertions.assertThat;
class ElasticsearchRepositoriesAutoConfigurationTests {
@Container
static final ElasticsearchContainer elasticsearch = new ElasticsearchContainer().withStartupAttempts(5)
.withStartupTimeout(Duration.ofMinutes(10));
static final ElasticsearchContainer elasticsearch = new VersionOverridingElasticsearchContainer()
.withStartupAttempts(5).withStartupTimeout(Duration.ofMinutes(10));
private ApplicationContextRunner contextRunner = new ApplicationContextRunner()
.withConfiguration(

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2020 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.
@ -47,7 +47,7 @@ import static org.assertj.core.api.Assertions.assertThat;
public class ReactiveElasticsearchRepositoriesAutoConfigurationTests {
@Container
static ElasticsearchContainer elasticsearch = new ElasticsearchContainer().withStartupAttempts(5)
static ElasticsearchContainer elasticsearch = new VersionOverridingElasticsearchContainer().withStartupAttempts(5)
.withStartupTimeout(Duration.ofMinutes(10));
private ApplicationContextRunner contextRunner = new ApplicationContextRunner()

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2020 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.
@ -47,7 +47,7 @@ import static org.mockito.Mockito.mock;
public class ReactiveRestClientAutoConfigurationTests {
@Container
static ElasticsearchContainer elasticsearch = new ElasticsearchContainer().withStartupAttempts(5)
static ElasticsearchContainer elasticsearch = new VersionOverridingElasticsearchContainer().withStartupAttempts(5)
.withStartupTimeout(Duration.ofMinutes(10));
private ApplicationContextRunner contextRunner = new ApplicationContextRunner()
@ -83,9 +83,10 @@ public class ReactiveRestClientAutoConfigurationTests {
Map<String, String> source = new HashMap<>();
source.put("a", "alpha");
source.put("b", "bravo");
IndexRequest index = new IndexRequest("foo", "bar", "1").source(source);
GetRequest getRequest = new GetRequest("foo", "bar", "1");
GetResult getResult = client.index(index).then(client.get(getRequest)).block();
IndexRequest indexRequest = new IndexRequest("foo").id("1").source(source);
GetRequest getRequest = new GetRequest("foo").id("1");
GetResult getResult = client.index(indexRequest).then(client.get(getRequest)).block();
assertThat(getResult).isNotNull();
assertThat(getResult.isExists()).isTrue();
});
}

View File

@ -0,0 +1,41 @@
/*
* Copyright 2012-2020 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.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.autoconfigure.data.elasticsearch;
import org.testcontainers.elasticsearch.ElasticsearchContainer;
/**
* Extension of {@link ElasticsearchContainer} to override default version.
*
* @author Scott Frederick
*/
public class VersionOverridingElasticsearchContainer extends ElasticsearchContainer {
/**
* Elasticsearch Docker base URL
*/
private static final String ELASTICSEARCH_IMAGE = "docker.elastic.co/elasticsearch/elasticsearch";
/**
* Elasticsearch version
*/
protected static final String ELASTICSEARCH_VERSION = "7.5.1";
public VersionOverridingElasticsearchContainer() {
super(ELASTICSEARCH_IMAGE + ":" + ELASTICSEARCH_VERSION);
}
}

View File

@ -288,7 +288,7 @@ bom {
]
}
}
library('Elasticsearch', '6.8.5') {
library('Elasticsearch', '7.5.1') {
group('org.elasticsearch') {
modules = [
'elasticsearch'