Commit d282eb61 authored by Stephane Nicoll's avatar Stephane Nicoll

Upgrade to Elasticsearch 7.5.1

See gh-19588
parent f268ede3
/* /*
* 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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 ...@@ -27,15 +27,11 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.data.elasticsearch.client.reactive.ReactiveElasticsearchClient; 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.ElasticsearchOperations;
import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate; import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate;
import org.springframework.data.elasticsearch.core.ElasticsearchTemplate; 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.ReactiveElasticsearchOperations;
import org.springframework.data.elasticsearch.core.ReactiveElasticsearchTemplate; 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.ElasticsearchConverter;
import org.springframework.data.elasticsearch.core.convert.MappingElasticsearchConverter; import org.springframework.data.elasticsearch.core.convert.MappingElasticsearchConverter;
import org.springframework.data.elasticsearch.core.mapping.SimpleElasticsearchMappingContext; import org.springframework.data.elasticsearch.core.mapping.SimpleElasticsearchMappingContext;
...@@ -48,6 +44,7 @@ import org.springframework.web.reactive.function.client.WebClient; ...@@ -48,6 +44,7 @@ import org.springframework.web.reactive.function.client.WebClient;
* their order of execution. * their order of execution.
* *
* @author Brian Clozel * @author Brian Clozel
* @author Scott Frederick
*/ */
abstract class ElasticsearchDataConfiguration { abstract class ElasticsearchDataConfiguration {
...@@ -66,18 +63,6 @@ abstract class ElasticsearchDataConfiguration { ...@@ -66,18 +63,6 @@ abstract class ElasticsearchDataConfiguration {
return new SimpleElasticsearchMappingContext(); 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) @Configuration(proxyBeanMethods = false)
...@@ -87,9 +72,8 @@ abstract class ElasticsearchDataConfiguration { ...@@ -87,9 +72,8 @@ abstract class ElasticsearchDataConfiguration {
@Bean @Bean
@ConditionalOnMissingBean(value = ElasticsearchOperations.class, name = "elasticsearchTemplate") @ConditionalOnMissingBean(value = ElasticsearchOperations.class, name = "elasticsearchTemplate")
@ConditionalOnBean(RestHighLevelClient.class) @ConditionalOnBean(RestHighLevelClient.class)
ElasticsearchRestTemplate elasticsearchTemplate(RestHighLevelClient client, ElasticsearchConverter converter, ElasticsearchRestTemplate elasticsearchTemplate(RestHighLevelClient client, ElasticsearchConverter converter) {
ResultsMapper resultsMapper) { return new ElasticsearchRestTemplate(client, converter);
return new ElasticsearchRestTemplate(client, converter, resultsMapper);
} }
} }
...@@ -101,10 +85,10 @@ abstract class ElasticsearchDataConfiguration { ...@@ -101,10 +85,10 @@ abstract class ElasticsearchDataConfiguration {
@Bean @Bean
@ConditionalOnMissingBean(value = ElasticsearchOperations.class, name = "elasticsearchTemplate") @ConditionalOnMissingBean(value = ElasticsearchOperations.class, name = "elasticsearchTemplate")
@ConditionalOnBean(Client.class) @ConditionalOnBean(Client.class)
ElasticsearchTemplate elasticsearchTemplate(Client client, ElasticsearchConverter converter, @Deprecated
ResultsMapper resultsMapper) { ElasticsearchTemplate elasticsearchTemplate(Client client, ElasticsearchConverter converter) {
try { try {
return new ElasticsearchTemplate(client, converter, resultsMapper); return new ElasticsearchTemplate(client, converter);
} }
catch (Exception ex) { catch (Exception ex) {
throw new IllegalStateException(ex); throw new IllegalStateException(ex);
...@@ -121,9 +105,8 @@ abstract class ElasticsearchDataConfiguration { ...@@ -121,9 +105,8 @@ abstract class ElasticsearchDataConfiguration {
@ConditionalOnMissingBean(value = ReactiveElasticsearchOperations.class, name = "reactiveElasticsearchTemplate") @ConditionalOnMissingBean(value = ReactiveElasticsearchOperations.class, name = "reactiveElasticsearchTemplate")
@ConditionalOnBean(ReactiveElasticsearchClient.class) @ConditionalOnBean(ReactiveElasticsearchClient.class)
ReactiveElasticsearchTemplate reactiveElasticsearchTemplate(ReactiveElasticsearchClient client, ReactiveElasticsearchTemplate reactiveElasticsearchTemplate(ReactiveElasticsearchClient client,
ElasticsearchConverter converter, ResultsMapper resultsMapper) { ElasticsearchConverter converter) {
ReactiveElasticsearchTemplate template = new ReactiveElasticsearchTemplate(client, converter, ReactiveElasticsearchTemplate template = new ReactiveElasticsearchTemplate(client, converter);
resultsMapper);
template.setIndicesOptions(IndicesOptions.strictExpandOpenAndForbidClosed()); template.setIndicesOptions(IndicesOptions.strictExpandOpenAndForbidClosed());
template.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE); template.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE);
return template; return template;
......
/* /*
* 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -47,8 +47,8 @@ import static org.mockito.Mockito.mock; ...@@ -47,8 +47,8 @@ import static org.mockito.Mockito.mock;
class ElasticsearchAutoConfigurationTests { class ElasticsearchAutoConfigurationTests {
@Container @Container
public static ElasticsearchContainer elasticsearch = new ElasticsearchContainer().withStartupAttempts(5) public static ElasticsearchContainer elasticsearch = new VersionOverridingElasticsearchContainer()
.withStartupTimeout(Duration.ofMinutes(10)); .withStartupAttempts(5).withStartupTimeout(Duration.ofMinutes(10));
private AnnotationConfigApplicationContext context; private AnnotationConfigApplicationContext context;
...@@ -76,6 +76,7 @@ class ElasticsearchAutoConfigurationTests { ...@@ -76,6 +76,7 @@ class ElasticsearchAutoConfigurationTests {
} }
@Test @Test
@SuppressWarnings("deprecation")
void createTransportClient() { void createTransportClient() {
this.context = new AnnotationConfigApplicationContext(); this.context = new AnnotationConfigApplicationContext();
TestPropertyValues TestPropertyValues
......
/* /*
* 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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 ...@@ -30,10 +30,8 @@ import org.springframework.boot.autoconfigure.elasticsearch.rest.RestClientAutoC
import org.springframework.boot.test.context.runner.ApplicationContextRunner; import org.springframework.boot.test.context.runner.ApplicationContextRunner;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; 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.ElasticsearchRestTemplate;
import org.springframework.data.elasticsearch.core.ElasticsearchTemplate; 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.ReactiveElasticsearchTemplate;
import org.springframework.data.elasticsearch.core.convert.ElasticsearchConverter; import org.springframework.data.elasticsearch.core.convert.ElasticsearchConverter;
import org.springframework.data.elasticsearch.core.mapping.SimpleElasticsearchMappingContext; import org.springframework.data.elasticsearch.core.mapping.SimpleElasticsearchMappingContext;
...@@ -48,12 +46,13 @@ import static org.mockito.Mockito.mock; ...@@ -48,12 +46,13 @@ import static org.mockito.Mockito.mock;
* @author Artur Konczak * @author Artur Konczak
* @author Brian Clozel * @author Brian Clozel
* @author Peter-Josef Meisch * @author Peter-Josef Meisch
* @author Scott Frederick
*/ */
@Testcontainers(disabledWithoutDocker = true) @Testcontainers(disabledWithoutDocker = true)
class ElasticsearchDataAutoConfigurationTests { class ElasticsearchDataAutoConfigurationTests {
@Container @Container
static ElasticsearchContainer elasticsearch = new ElasticsearchContainer().withStartupAttempts(5) static ElasticsearchContainer elasticsearch = new VersionOverridingElasticsearchContainer().withStartupAttempts(5)
.withStartupTimeout(Duration.ofMinutes(10)); .withStartupTimeout(Duration.ofMinutes(10));
private ApplicationContextRunner contextRunner = new ApplicationContextRunner().withConfiguration( private ApplicationContextRunner contextRunner = new ApplicationContextRunner().withConfiguration(
...@@ -71,6 +70,7 @@ class ElasticsearchDataAutoConfigurationTests { ...@@ -71,6 +70,7 @@ class ElasticsearchDataAutoConfigurationTests {
} }
@Test @Test
@SuppressWarnings("deprecation")
void defaultTransportBeansAreRegistered() { void defaultTransportBeansAreRegistered() {
this.contextRunner this.contextRunner
.withPropertyValues( .withPropertyValues(
...@@ -83,6 +83,7 @@ class ElasticsearchDataAutoConfigurationTests { ...@@ -83,6 +83,7 @@ class ElasticsearchDataAutoConfigurationTests {
} }
@Test @Test
@SuppressWarnings("deprecation")
void defaultTransportBeansNotRegisteredIfNoTransportClient() { void defaultTransportBeansNotRegisteredIfNoTransportClient() {
this.contextRunner.run((context) -> assertThat(context).doesNotHaveBean(ElasticsearchTemplate.class)); this.contextRunner.run((context) -> assertThat(context).doesNotHaveBean(ElasticsearchTemplate.class));
} }
...@@ -91,16 +92,11 @@ class ElasticsearchDataAutoConfigurationTests { ...@@ -91,16 +92,11 @@ class ElasticsearchDataAutoConfigurationTests {
void defaultRestBeansRegistered() { void defaultRestBeansRegistered() {
this.contextRunner.run((context) -> assertThat(context).hasSingleBean(ElasticsearchRestTemplate.class) this.contextRunner.run((context) -> assertThat(context).hasSingleBean(ElasticsearchRestTemplate.class)
.hasSingleBean(ReactiveElasticsearchTemplate.class).hasSingleBean(ElasticsearchConverter.class) .hasSingleBean(ReactiveElasticsearchTemplate.class).hasSingleBean(ElasticsearchConverter.class)
.hasSingleBean(SimpleElasticsearchMappingContext.class).hasSingleBean(EntityMapper.class)
.hasSingleBean(ElasticsearchConverter.class)); .hasSingleBean(ElasticsearchConverter.class));
} }
@Test @Test
void defaultEntityMapperRegistered() { @SuppressWarnings("deprecation")
this.contextRunner.run((context) -> assertThat(context).hasSingleBean(EntityMapper.class));
}
@Test
void customTransportTemplateShouldBeUsed() { void customTransportTemplateShouldBeUsed() {
this.contextRunner.withUserConfiguration(CustomTransportTemplate.class).run((context) -> assertThat(context) this.contextRunner.withUserConfiguration(CustomTransportTemplate.class).run((context) -> assertThat(context)
.getBeanNames(ElasticsearchTemplate.class).hasSize(1).contains("elasticsearchTemplate")); .getBeanNames(ElasticsearchTemplate.class).hasSize(1).contains("elasticsearchTemplate"));
...@@ -119,16 +115,11 @@ class ElasticsearchDataAutoConfigurationTests { ...@@ -119,16 +115,11 @@ class ElasticsearchDataAutoConfigurationTests {
.contains("reactiveElasticsearchTemplate")); .contains("reactiveElasticsearchTemplate"));
} }
@Test
void customEntityMapperShouldeBeUsed() {
this.contextRunner.withUserConfiguration(CustomEntityMapper.class).run((context) -> assertThat(context)
.getBeanNames(EntityMapper.class).containsExactly("elasticsearchEntityMapper"));
}
@Configuration(proxyBeanMethods = false) @Configuration(proxyBeanMethods = false)
static class CustomTransportTemplate { static class CustomTransportTemplate {
@Bean @Bean
@SuppressWarnings("deprecation")
ElasticsearchTemplate elasticsearchTemplate() { ElasticsearchTemplate elasticsearchTemplate() {
return mock(ElasticsearchTemplate.class); return mock(ElasticsearchTemplate.class);
} }
...@@ -155,14 +146,4 @@ class ElasticsearchDataAutoConfigurationTests { ...@@ -155,14 +146,4 @@ class ElasticsearchDataAutoConfigurationTests {
} }
@Configuration(proxyBeanMethods = false)
static class CustomEntityMapper {
@Bean
EntityMapper elasticsearchEntityMapper() {
return mock(ElasticsearchEntityMapper.class);
}
}
} }
/* /*
* 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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; ...@@ -48,8 +48,8 @@ import static org.assertj.core.api.Assertions.assertThat;
class ElasticsearchRepositoriesAutoConfigurationTests { class ElasticsearchRepositoriesAutoConfigurationTests {
@Container @Container
static final ElasticsearchContainer elasticsearch = new ElasticsearchContainer().withStartupAttempts(5) static final ElasticsearchContainer elasticsearch = new VersionOverridingElasticsearchContainer()
.withStartupTimeout(Duration.ofMinutes(10)); .withStartupAttempts(5).withStartupTimeout(Duration.ofMinutes(10));
private ApplicationContextRunner contextRunner = new ApplicationContextRunner() private ApplicationContextRunner contextRunner = new ApplicationContextRunner()
.withConfiguration( .withConfiguration(
......
/* /*
* 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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; ...@@ -47,7 +47,7 @@ import static org.assertj.core.api.Assertions.assertThat;
public class ReactiveElasticsearchRepositoriesAutoConfigurationTests { public class ReactiveElasticsearchRepositoriesAutoConfigurationTests {
@Container @Container
static ElasticsearchContainer elasticsearch = new ElasticsearchContainer().withStartupAttempts(5) static ElasticsearchContainer elasticsearch = new VersionOverridingElasticsearchContainer().withStartupAttempts(5)
.withStartupTimeout(Duration.ofMinutes(10)); .withStartupTimeout(Duration.ofMinutes(10));
private ApplicationContextRunner contextRunner = new ApplicationContextRunner() private ApplicationContextRunner contextRunner = new ApplicationContextRunner()
......
/* /*
* 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -47,7 +47,7 @@ import static org.mockito.Mockito.mock; ...@@ -47,7 +47,7 @@ import static org.mockito.Mockito.mock;
public class ReactiveRestClientAutoConfigurationTests { public class ReactiveRestClientAutoConfigurationTests {
@Container @Container
static ElasticsearchContainer elasticsearch = new ElasticsearchContainer().withStartupAttempts(5) static ElasticsearchContainer elasticsearch = new VersionOverridingElasticsearchContainer().withStartupAttempts(5)
.withStartupTimeout(Duration.ofMinutes(10)); .withStartupTimeout(Duration.ofMinutes(10));
private ApplicationContextRunner contextRunner = new ApplicationContextRunner() private ApplicationContextRunner contextRunner = new ApplicationContextRunner()
...@@ -83,9 +83,10 @@ public class ReactiveRestClientAutoConfigurationTests { ...@@ -83,9 +83,10 @@ public class ReactiveRestClientAutoConfigurationTests {
Map<String, String> source = new HashMap<>(); Map<String, String> source = new HashMap<>();
source.put("a", "alpha"); source.put("a", "alpha");
source.put("b", "bravo"); source.put("b", "bravo");
IndexRequest index = new IndexRequest("foo", "bar", "1").source(source); IndexRequest indexRequest = new IndexRequest("foo").id("1").source(source);
GetRequest getRequest = new GetRequest("foo", "bar", "1"); GetRequest getRequest = new GetRequest("foo").id("1");
GetResult getResult = client.index(index).then(client.get(getRequest)).block(); GetResult getResult = client.index(indexRequest).then(client.get(getRequest)).block();
assertThat(getResult).isNotNull();
assertThat(getResult.isExists()).isTrue(); assertThat(getResult.isExists()).isTrue();
}); });
} }
......
/*
* 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);
}
}
...@@ -288,7 +288,7 @@ bom { ...@@ -288,7 +288,7 @@ bom {
] ]
} }
} }
library('Elasticsearch', '6.8.5') { library('Elasticsearch', '7.5.1') {
group('org.elasticsearch') { group('org.elasticsearch') {
modules = [ modules = [
'elasticsearch' 'elasticsearch'
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment