diff --git a/src/test/java/org/springframework/data/elasticsearch/junit/jupiter/ClusterConnection.java b/src/test/java/org/springframework/data/elasticsearch/junit/jupiter/ClusterConnection.java index 4b6f8083b..e0d2bc430 100644 --- a/src/test/java/org/springframework/data/elasticsearch/junit/jupiter/ClusterConnection.java +++ b/src/test/java/org/springframework/data/elasticsearch/junit/jupiter/ClusterConnection.java @@ -15,6 +15,12 @@ */ package org.springframework.data.elasticsearch.junit.jupiter; +import java.io.InputStream; +import java.util.Collections; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.Properties; + import org.junit.jupiter.api.extension.ExtensionContext; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -77,10 +83,13 @@ private ClusterConnectionInfo startElasticsearchContainer() { try { String elasticsearchVersion = VersionInfo.versionProperties() .getProperty(VersionInfo.VERSION_ELASTICSEARCH_CLIENT); + Map elasticsearchProperties = elasticsearchProperties(); String dockerImageName = ELASTICSEARCH_DEFAULT_IMAGE + ':' + elasticsearchVersion; LOGGER.debug("Docker image: {}", dockerImageName); + ElasticsearchContainer elasticsearchContainer = new ElasticsearchContainer(dockerImageName); + elasticsearchContainer.withEnv(elasticsearchProperties); elasticsearchContainer.start(); return ClusterConnectionInfo.builder() // .withHostAndPort(elasticsearchContainer.getHost(), @@ -95,6 +104,24 @@ private ClusterConnectionInfo startElasticsearchContainer() { return null; } + private Map elasticsearchProperties() { + + String propertiesFile = "testcontainers-elasticsearch.properties"; + try (InputStream inputStream = getClass().getClassLoader().getResourceAsStream(propertiesFile)) { + Properties props = new Properties(); + + if (inputStream != null) { + props.load(inputStream); + } + Map elasticsearchProperties = new LinkedHashMap<>(); + props.forEach((key, value) -> elasticsearchProperties.put(key.toString(), value.toString())); + return elasticsearchProperties; + } catch (Exception e) { + LOGGER.error("Cannot load " + propertiesFile); + } + return Collections.emptyMap(); + } + @Override public void close() { diff --git a/src/test/resources/testcontainers-elasticsearch.properties b/src/test/resources/testcontainers-elasticsearch.properties new file mode 100644 index 000000000..5bef8c62b --- /dev/null +++ b/src/test/resources/testcontainers-elasticsearch.properties @@ -0,0 +1,2 @@ +# needed as we do a DELETE /* at the end of the tests, will be requited from 8.0 on, produces a warning since 7.13 +action.destructive_requires_name=false