mirror of
https://github.com/spring-projects/spring-boot.git
synced 2026-09-22 09:09:01 +00:00
Restore behavior of TestImage with Elasticsearch
See gh-46052
This commit is contained in:
+1
-1
@@ -34,7 +34,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*/
|
||||
class ElasticsearchDockerComposeConnectionDetailsFactoryIntegrationTests {
|
||||
|
||||
@DockerComposeTest(composeFile = "elasticsearch-compose.yaml", image = TestImage.ELASTICSEARCH)
|
||||
@DockerComposeTest(composeFile = "elasticsearch-compose.yaml", image = TestImage.ELASTICSEARCH_9)
|
||||
void runCreatesConnectionDetails(ElasticsearchConnectionDetails connectionDetails) {
|
||||
assertConnectionDetails(connectionDetails);
|
||||
}
|
||||
|
||||
+2
-2
@@ -19,14 +19,14 @@ package org.springframework.boot.testsupport.container;
|
||||
import org.testcontainers.elasticsearch.ElasticsearchContainer;
|
||||
|
||||
/**
|
||||
* A container suitable for testing Elasticsearch 8.
|
||||
* A container suitable for testing Elasticsearch 9.
|
||||
*
|
||||
* @author Dmytro Nosan
|
||||
*/
|
||||
public class ElasticsearchContainer9 extends ElasticsearchContainer {
|
||||
|
||||
public ElasticsearchContainer9() {
|
||||
super(TestImage.ELASTICSEARCH.toString());
|
||||
super(TestImage.ELASTICSEARCH_9.toString());
|
||||
addEnv("ES_JAVA_OPTS", "-Xms32m -Xmx512m");
|
||||
addEnv("xpack.security.enabled", "false");
|
||||
}
|
||||
|
||||
+16
-2
@@ -36,6 +36,7 @@ import org.testcontainers.containers.PostgreSQLContainer;
|
||||
import org.testcontainers.containers.PulsarContainer;
|
||||
import org.testcontainers.containers.RabbitMQContainer;
|
||||
import org.testcontainers.couchbase.CouchbaseContainer;
|
||||
import org.testcontainers.elasticsearch.ElasticsearchContainer;
|
||||
import org.testcontainers.grafana.LgtmStackContainer;
|
||||
import org.testcontainers.kafka.ConfluentKafkaContainer;
|
||||
import org.testcontainers.ldap.LLdapContainer;
|
||||
@@ -107,9 +108,22 @@ public enum TestImage {
|
||||
.withStartupTimeout(Duration.ofMinutes(10))),
|
||||
|
||||
/**
|
||||
* A container image suitable for testing Elasticsearch.
|
||||
* A container image suitable for testing Elasticsearch 7.
|
||||
*/
|
||||
ELASTICSEARCH("elasticsearch", "9.0.2"),
|
||||
ELASTICSEARCH("docker.elastic.co/elasticsearch/elasticsearch", "7.17.28", () -> ElasticsearchContainer.class,
|
||||
(container) -> ((ElasticsearchContainer) container).withEnv("ES_JAVA_OPTS", "-Xms32m -Xmx512m")
|
||||
.withStartupAttempts(5)
|
||||
.withStartupTimeout(Duration.ofMinutes(10))),
|
||||
|
||||
/**
|
||||
* A container image suitable for testing Elasticsearch 8.
|
||||
*/
|
||||
ELASTICSEARCH_8("elasticsearch", "8.17.1"),
|
||||
|
||||
/**
|
||||
* A container image suitable for testing Elasticsearch 9.
|
||||
*/
|
||||
ELASTICSEARCH_9("elasticsearch", "9.0.2"),
|
||||
|
||||
/**
|
||||
* A container image suitable for testing Grafana OTel LGTM.
|
||||
|
||||
+3
-1
@@ -18,6 +18,7 @@ package smoketest.data.elasticsearch;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.testcontainers.elasticsearch.ElasticsearchContainer;
|
||||
import org.testcontainers.junit.jupiter.Container;
|
||||
@@ -39,12 +40,13 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*/
|
||||
@Testcontainers(disabledWithoutDocker = true)
|
||||
@DataElasticsearchTest
|
||||
@Disabled("Elasticsearch client v9 needs extra config with v8")
|
||||
class SampleElasticsearch8ApplicationTests {
|
||||
|
||||
@Container
|
||||
@ServiceConnection
|
||||
@Ssl
|
||||
static final ElasticsearchContainer elasticSearch = new ElasticsearchContainer(TestImage.ELASTICSEARCH.toString())
|
||||
static final ElasticsearchContainer elasticSearch = new ElasticsearchContainer(TestImage.ELASTICSEARCH_8.toString())
|
||||
.withPassword("my-custom-password");
|
||||
|
||||
@Autowired
|
||||
|
||||
+71
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* Copyright 2012-2025 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 smoketest.data.elasticsearch;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
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.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.data.elasticsearch.DataElasticsearchTest;
|
||||
import org.springframework.boot.testcontainers.service.connection.ServiceConnection;
|
||||
import org.springframework.boot.testcontainers.service.connection.Ssl;
|
||||
import org.springframework.boot.testsupport.container.TestImage;
|
||||
import org.springframework.data.elasticsearch.client.elc.ElasticsearchTemplate;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Smoke tests for Elasticsearch 9.
|
||||
*
|
||||
* @author Moritz Halbritter
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
@Testcontainers(disabledWithoutDocker = true)
|
||||
@DataElasticsearchTest
|
||||
class SampleElasticsearch9ApplicationTests {
|
||||
|
||||
@Container
|
||||
@ServiceConnection
|
||||
@Ssl
|
||||
static final ElasticsearchContainer elasticSearch = new ElasticsearchContainer(TestImage.ELASTICSEARCH_9.toString())
|
||||
.withPassword("my-custom-password");
|
||||
|
||||
@Autowired
|
||||
private ElasticsearchTemplate elasticsearchTemplate;
|
||||
|
||||
@Autowired
|
||||
private SampleRepository exampleRepository;
|
||||
|
||||
@Test
|
||||
void testRepository() {
|
||||
SampleDocument document = new SampleDocument();
|
||||
document.setText("Look, new @DataElasticsearchTest!");
|
||||
String id = UUID.randomUUID().toString();
|
||||
document.setId(id);
|
||||
SampleDocument savedDocument = this.exampleRepository.save(document);
|
||||
SampleDocument getDocument = this.elasticsearchTemplate.get(id, SampleDocument.class);
|
||||
assertThat(getDocument).isNotNull();
|
||||
assertThat(getDocument.getId()).isNotNull();
|
||||
assertThat(getDocument.getId()).isEqualTo(savedDocument.getId());
|
||||
this.exampleRepository.deleteAll();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user