mirror of
https://github.com/spring-projects/spring-data-elasticsearch.git
synced 2025-05-30 08:42:10 +00:00
Add TestContainers configuration.
Original Pull Request #1861 Closes #1860
This commit is contained in:
parent
6f84a1c589
commit
66d13444aa
@ -15,6 +15,12 @@
|
|||||||
*/
|
*/
|
||||||
package org.springframework.data.elasticsearch.junit.jupiter;
|
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.junit.jupiter.api.extension.ExtensionContext;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
@ -77,10 +83,13 @@ public class ClusterConnection implements ExtensionContext.Store.CloseableResour
|
|||||||
try {
|
try {
|
||||||
String elasticsearchVersion = VersionInfo.versionProperties()
|
String elasticsearchVersion = VersionInfo.versionProperties()
|
||||||
.getProperty(VersionInfo.VERSION_ELASTICSEARCH_CLIENT);
|
.getProperty(VersionInfo.VERSION_ELASTICSEARCH_CLIENT);
|
||||||
|
Map<String, String> elasticsearchProperties = elasticsearchProperties();
|
||||||
|
|
||||||
String dockerImageName = ELASTICSEARCH_DEFAULT_IMAGE + ':' + elasticsearchVersion;
|
String dockerImageName = ELASTICSEARCH_DEFAULT_IMAGE + ':' + elasticsearchVersion;
|
||||||
LOGGER.debug("Docker image: {}", dockerImageName);
|
LOGGER.debug("Docker image: {}", dockerImageName);
|
||||||
|
|
||||||
ElasticsearchContainer elasticsearchContainer = new ElasticsearchContainer(dockerImageName);
|
ElasticsearchContainer elasticsearchContainer = new ElasticsearchContainer(dockerImageName);
|
||||||
|
elasticsearchContainer.withEnv(elasticsearchProperties);
|
||||||
elasticsearchContainer.start();
|
elasticsearchContainer.start();
|
||||||
return ClusterConnectionInfo.builder() //
|
return ClusterConnectionInfo.builder() //
|
||||||
.withHostAndPort(elasticsearchContainer.getHost(),
|
.withHostAndPort(elasticsearchContainer.getHost(),
|
||||||
@ -95,6 +104,24 @@ public class ClusterConnection implements ExtensionContext.Store.CloseableResour
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Map<String, String> elasticsearchProperties() {
|
||||||
|
|
||||||
|
String propertiesFile = "testcontainers-elasticsearch.properties";
|
||||||
|
try (InputStream inputStream = getClass().getClassLoader().getResourceAsStream(propertiesFile)) {
|
||||||
|
Properties props = new Properties();
|
||||||
|
|
||||||
|
if (inputStream != null) {
|
||||||
|
props.load(inputStream);
|
||||||
|
}
|
||||||
|
Map<String, String> 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
|
@Override
|
||||||
public void close() {
|
public void close() {
|
||||||
|
|
||||||
|
@ -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
|
Loading…
x
Reference in New Issue
Block a user