Upgrade Testcontainers to 1.10.2 and use ElasticsearchContainer
Since version 1.10.0 [1] there is an official ElasticsearchContainer. [1] https://github.com/testcontainers/testcontainers-java/releases/tag/1.10.0 Change-Id: I155f9eb0e0bac41c24469e683417eba52f01a80a
This commit is contained in:
12
WORKSPACE
12
WORKSPACE
@@ -908,10 +908,18 @@ maven_jar(
|
||||
sha1 = "4b7f0e0dc527fab032e9800ed231080fdc3ac015",
|
||||
)
|
||||
|
||||
TESTCONTAINERS_VERSION = "1.10.2"
|
||||
|
||||
maven_jar(
|
||||
name = "testcontainers",
|
||||
artifact = "org.testcontainers:testcontainers:1.8.0",
|
||||
sha1 = "bc413912f7044f9f12aa0782853aef0a067ee52a",
|
||||
artifact = "org.testcontainers:testcontainers:" + TESTCONTAINERS_VERSION,
|
||||
sha1 = "dfe35b1887685000fecee7f102bd8ce55643665c",
|
||||
)
|
||||
|
||||
maven_jar(
|
||||
name = "testcontainers-elasticsearch",
|
||||
artifact = "org.testcontainers:elasticsearch:" + TESTCONTAINERS_VERSION,
|
||||
sha1 = "c6eb4a3a0ad114929b659fa59c2ee9fe1c1d6a58",
|
||||
)
|
||||
|
||||
maven_jar(
|
||||
|
||||
@@ -46,6 +46,7 @@ java_library(
|
||||
"//lib/httpcomponents:httpcore",
|
||||
"//lib/jgit/org.eclipse.jgit:jgit",
|
||||
"//lib/testcontainers",
|
||||
"//lib/testcontainers:testcontainers-elasticsearch",
|
||||
],
|
||||
)
|
||||
|
||||
|
||||
@@ -14,21 +14,19 @@
|
||||
|
||||
package com.google.gerrit.elasticsearch;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import java.util.Set;
|
||||
import org.apache.http.HttpHost;
|
||||
import org.junit.internal.AssumptionViolatedException;
|
||||
import org.testcontainers.containers.GenericContainer;
|
||||
import org.testcontainers.elasticsearch.ElasticsearchContainer;
|
||||
|
||||
/* Helper class for running ES integration tests in docker container */
|
||||
public class ElasticContainer<SELF extends ElasticContainer<SELF>> extends GenericContainer<SELF> {
|
||||
public class ElasticContainer extends ElasticsearchContainer {
|
||||
private static final int ELASTICSEARCH_DEFAULT_PORT = 9200;
|
||||
|
||||
public static ElasticContainer<?> createAndStart(ElasticVersion version) {
|
||||
public static ElasticContainer createAndStart(ElasticVersion version) {
|
||||
// Assumption violation is not natively supported by Testcontainers.
|
||||
// See https://github.com/testcontainers/testcontainers-java/issues/343
|
||||
try {
|
||||
ElasticContainer<?> container = new ElasticContainer<>(version);
|
||||
ElasticContainer container = new ElasticContainer(version);
|
||||
container.start();
|
||||
return container;
|
||||
} catch (Throwable t) {
|
||||
@@ -58,16 +56,6 @@ public class ElasticContainer<SELF extends ElasticContainer<SELF>> extends Gener
|
||||
super(getImageName(version));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void configure() {
|
||||
addExposedPort(ELASTICSEARCH_DEFAULT_PORT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Integer> getLivenessCheckPortNumbers() {
|
||||
return ImmutableSet.of(getMappedPort(ELASTICSEARCH_DEFAULT_PORT));
|
||||
}
|
||||
|
||||
public HttpHost getHttpHost() {
|
||||
return new HttpHost(getContainerIpAddress(), getMappedPort(ELASTICSEARCH_DEFAULT_PORT));
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ public final class ElasticTestUtils {
|
||||
|
||||
public static Config getConfig(ElasticVersion version) {
|
||||
ElasticNodeInfo elasticNodeInfo;
|
||||
ElasticContainer<?> container = ElasticContainer.createAndStart(version);
|
||||
ElasticContainer container = ElasticContainer.createAndStart(version);
|
||||
elasticNodeInfo = new ElasticNodeInfo(container.getHttpHost().getPort());
|
||||
String indicesPrefix = UUID.randomUUID().toString();
|
||||
Config cfg = new Config();
|
||||
|
||||
@@ -25,7 +25,7 @@ import org.junit.BeforeClass;
|
||||
|
||||
public class ElasticV5QueryAccountsTest extends AbstractQueryAccountsTest {
|
||||
private static ElasticNodeInfo nodeInfo;
|
||||
private static ElasticContainer<?> container;
|
||||
private static ElasticContainer container;
|
||||
|
||||
@BeforeClass
|
||||
public static void startIndexService() {
|
||||
|
||||
@@ -25,7 +25,7 @@ import org.junit.BeforeClass;
|
||||
|
||||
public class ElasticV5QueryChangesTest extends AbstractQueryChangesTest {
|
||||
private static ElasticNodeInfo nodeInfo;
|
||||
private static ElasticContainer<?> container;
|
||||
private static ElasticContainer container;
|
||||
|
||||
@BeforeClass
|
||||
public static void startIndexService() {
|
||||
|
||||
@@ -25,7 +25,7 @@ import org.junit.BeforeClass;
|
||||
|
||||
public class ElasticV5QueryGroupsTest extends AbstractQueryGroupsTest {
|
||||
private static ElasticNodeInfo nodeInfo;
|
||||
private static ElasticContainer<?> container;
|
||||
private static ElasticContainer container;
|
||||
|
||||
@BeforeClass
|
||||
public static void startIndexService() {
|
||||
|
||||
@@ -25,7 +25,7 @@ import org.junit.BeforeClass;
|
||||
|
||||
public class ElasticV6QueryAccountsTest extends AbstractQueryAccountsTest {
|
||||
private static ElasticNodeInfo nodeInfo;
|
||||
private static ElasticContainer<?> container;
|
||||
private static ElasticContainer container;
|
||||
|
||||
@BeforeClass
|
||||
public static void startIndexService() {
|
||||
|
||||
@@ -26,7 +26,7 @@ import org.junit.BeforeClass;
|
||||
public class ElasticV6QueryChangesTest extends AbstractQueryChangesTest {
|
||||
|
||||
private static ElasticNodeInfo nodeInfo;
|
||||
private static ElasticContainer<?> container;
|
||||
private static ElasticContainer container;
|
||||
|
||||
@BeforeClass
|
||||
public static void startIndexService() {
|
||||
|
||||
@@ -25,7 +25,7 @@ import org.junit.BeforeClass;
|
||||
|
||||
public class ElasticV6QueryGroupsTest extends AbstractQueryGroupsTest {
|
||||
private static ElasticNodeInfo nodeInfo;
|
||||
private static ElasticContainer<?> container;
|
||||
private static ElasticContainer container;
|
||||
|
||||
@BeforeClass
|
||||
public static void startIndexService() {
|
||||
|
||||
@@ -25,7 +25,7 @@ import org.junit.BeforeClass;
|
||||
|
||||
public class ElasticV7QueryAccountsTest extends AbstractQueryAccountsTest {
|
||||
private static ElasticNodeInfo nodeInfo;
|
||||
private static ElasticContainer<?> container;
|
||||
private static ElasticContainer container;
|
||||
|
||||
@BeforeClass
|
||||
public static void startIndexService() {
|
||||
|
||||
@@ -26,7 +26,7 @@ import org.junit.BeforeClass;
|
||||
public class ElasticV7QueryChangesTest extends AbstractQueryChangesTest {
|
||||
|
||||
private static ElasticNodeInfo nodeInfo;
|
||||
private static ElasticContainer<?> container;
|
||||
private static ElasticContainer container;
|
||||
|
||||
@BeforeClass
|
||||
public static void startIndexService() {
|
||||
|
||||
@@ -25,7 +25,7 @@ import org.junit.BeforeClass;
|
||||
|
||||
public class ElasticV7QueryGroupsTest extends AbstractQueryGroupsTest {
|
||||
private static ElasticNodeInfo nodeInfo;
|
||||
private static ElasticContainer<?> container;
|
||||
private static ElasticContainer container;
|
||||
|
||||
@BeforeClass
|
||||
public static void startIndexService() {
|
||||
|
||||
@@ -35,3 +35,12 @@ java_library(
|
||||
"//lib/log:ext",
|
||||
],
|
||||
)
|
||||
|
||||
java_library(
|
||||
name = "testcontainers-elasticsearch",
|
||||
testonly = 1,
|
||||
data = ["//lib:LICENSE-testcontainers"],
|
||||
visibility = ["//visibility:public"],
|
||||
exports = ["@testcontainers-elasticsearch//jar"],
|
||||
runtime_deps = [":testcontainers"],
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user