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",
|
sha1 = "4b7f0e0dc527fab032e9800ed231080fdc3ac015",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
TESTCONTAINERS_VERSION = "1.10.2"
|
||||||
|
|
||||||
maven_jar(
|
maven_jar(
|
||||||
name = "testcontainers",
|
name = "testcontainers",
|
||||||
artifact = "org.testcontainers:testcontainers:1.8.0",
|
artifact = "org.testcontainers:testcontainers:" + TESTCONTAINERS_VERSION,
|
||||||
sha1 = "bc413912f7044f9f12aa0782853aef0a067ee52a",
|
sha1 = "dfe35b1887685000fecee7f102bd8ce55643665c",
|
||||||
|
)
|
||||||
|
|
||||||
|
maven_jar(
|
||||||
|
name = "testcontainers-elasticsearch",
|
||||||
|
artifact = "org.testcontainers:elasticsearch:" + TESTCONTAINERS_VERSION,
|
||||||
|
sha1 = "c6eb4a3a0ad114929b659fa59c2ee9fe1c1d6a58",
|
||||||
)
|
)
|
||||||
|
|
||||||
maven_jar(
|
maven_jar(
|
||||||
|
|||||||
@@ -46,6 +46,7 @@ java_library(
|
|||||||
"//lib/httpcomponents:httpcore",
|
"//lib/httpcomponents:httpcore",
|
||||||
"//lib/jgit/org.eclipse.jgit:jgit",
|
"//lib/jgit/org.eclipse.jgit:jgit",
|
||||||
"//lib/testcontainers",
|
"//lib/testcontainers",
|
||||||
|
"//lib/testcontainers:testcontainers-elasticsearch",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -14,21 +14,19 @@
|
|||||||
|
|
||||||
package com.google.gerrit.elasticsearch;
|
package com.google.gerrit.elasticsearch;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableSet;
|
|
||||||
import java.util.Set;
|
|
||||||
import org.apache.http.HttpHost;
|
import org.apache.http.HttpHost;
|
||||||
import org.junit.internal.AssumptionViolatedException;
|
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 */
|
/* 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;
|
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.
|
// Assumption violation is not natively supported by Testcontainers.
|
||||||
// See https://github.com/testcontainers/testcontainers-java/issues/343
|
// See https://github.com/testcontainers/testcontainers-java/issues/343
|
||||||
try {
|
try {
|
||||||
ElasticContainer<?> container = new ElasticContainer<>(version);
|
ElasticContainer container = new ElasticContainer(version);
|
||||||
container.start();
|
container.start();
|
||||||
return container;
|
return container;
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
@@ -58,16 +56,6 @@ public class ElasticContainer<SELF extends ElasticContainer<SELF>> extends Gener
|
|||||||
super(getImageName(version));
|
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() {
|
public HttpHost getHttpHost() {
|
||||||
return new HttpHost(getContainerIpAddress(), getMappedPort(ELASTICSEARCH_DEFAULT_PORT));
|
return new HttpHost(getContainerIpAddress(), getMappedPort(ELASTICSEARCH_DEFAULT_PORT));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ public final class ElasticTestUtils {
|
|||||||
|
|
||||||
public static Config getConfig(ElasticVersion version) {
|
public static Config getConfig(ElasticVersion version) {
|
||||||
ElasticNodeInfo elasticNodeInfo;
|
ElasticNodeInfo elasticNodeInfo;
|
||||||
ElasticContainer<?> container = ElasticContainer.createAndStart(version);
|
ElasticContainer container = ElasticContainer.createAndStart(version);
|
||||||
elasticNodeInfo = new ElasticNodeInfo(container.getHttpHost().getPort());
|
elasticNodeInfo = new ElasticNodeInfo(container.getHttpHost().getPort());
|
||||||
String indicesPrefix = UUID.randomUUID().toString();
|
String indicesPrefix = UUID.randomUUID().toString();
|
||||||
Config cfg = new Config();
|
Config cfg = new Config();
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ import org.junit.BeforeClass;
|
|||||||
|
|
||||||
public class ElasticV5QueryAccountsTest extends AbstractQueryAccountsTest {
|
public class ElasticV5QueryAccountsTest extends AbstractQueryAccountsTest {
|
||||||
private static ElasticNodeInfo nodeInfo;
|
private static ElasticNodeInfo nodeInfo;
|
||||||
private static ElasticContainer<?> container;
|
private static ElasticContainer container;
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void startIndexService() {
|
public static void startIndexService() {
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ import org.junit.BeforeClass;
|
|||||||
|
|
||||||
public class ElasticV5QueryChangesTest extends AbstractQueryChangesTest {
|
public class ElasticV5QueryChangesTest extends AbstractQueryChangesTest {
|
||||||
private static ElasticNodeInfo nodeInfo;
|
private static ElasticNodeInfo nodeInfo;
|
||||||
private static ElasticContainer<?> container;
|
private static ElasticContainer container;
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void startIndexService() {
|
public static void startIndexService() {
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ import org.junit.BeforeClass;
|
|||||||
|
|
||||||
public class ElasticV5QueryGroupsTest extends AbstractQueryGroupsTest {
|
public class ElasticV5QueryGroupsTest extends AbstractQueryGroupsTest {
|
||||||
private static ElasticNodeInfo nodeInfo;
|
private static ElasticNodeInfo nodeInfo;
|
||||||
private static ElasticContainer<?> container;
|
private static ElasticContainer container;
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void startIndexService() {
|
public static void startIndexService() {
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ import org.junit.BeforeClass;
|
|||||||
|
|
||||||
public class ElasticV6QueryAccountsTest extends AbstractQueryAccountsTest {
|
public class ElasticV6QueryAccountsTest extends AbstractQueryAccountsTest {
|
||||||
private static ElasticNodeInfo nodeInfo;
|
private static ElasticNodeInfo nodeInfo;
|
||||||
private static ElasticContainer<?> container;
|
private static ElasticContainer container;
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void startIndexService() {
|
public static void startIndexService() {
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ import org.junit.BeforeClass;
|
|||||||
public class ElasticV6QueryChangesTest extends AbstractQueryChangesTest {
|
public class ElasticV6QueryChangesTest extends AbstractQueryChangesTest {
|
||||||
|
|
||||||
private static ElasticNodeInfo nodeInfo;
|
private static ElasticNodeInfo nodeInfo;
|
||||||
private static ElasticContainer<?> container;
|
private static ElasticContainer container;
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void startIndexService() {
|
public static void startIndexService() {
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ import org.junit.BeforeClass;
|
|||||||
|
|
||||||
public class ElasticV6QueryGroupsTest extends AbstractQueryGroupsTest {
|
public class ElasticV6QueryGroupsTest extends AbstractQueryGroupsTest {
|
||||||
private static ElasticNodeInfo nodeInfo;
|
private static ElasticNodeInfo nodeInfo;
|
||||||
private static ElasticContainer<?> container;
|
private static ElasticContainer container;
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void startIndexService() {
|
public static void startIndexService() {
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ import org.junit.BeforeClass;
|
|||||||
|
|
||||||
public class ElasticV7QueryAccountsTest extends AbstractQueryAccountsTest {
|
public class ElasticV7QueryAccountsTest extends AbstractQueryAccountsTest {
|
||||||
private static ElasticNodeInfo nodeInfo;
|
private static ElasticNodeInfo nodeInfo;
|
||||||
private static ElasticContainer<?> container;
|
private static ElasticContainer container;
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void startIndexService() {
|
public static void startIndexService() {
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ import org.junit.BeforeClass;
|
|||||||
public class ElasticV7QueryChangesTest extends AbstractQueryChangesTest {
|
public class ElasticV7QueryChangesTest extends AbstractQueryChangesTest {
|
||||||
|
|
||||||
private static ElasticNodeInfo nodeInfo;
|
private static ElasticNodeInfo nodeInfo;
|
||||||
private static ElasticContainer<?> container;
|
private static ElasticContainer container;
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void startIndexService() {
|
public static void startIndexService() {
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ import org.junit.BeforeClass;
|
|||||||
|
|
||||||
public class ElasticV7QueryGroupsTest extends AbstractQueryGroupsTest {
|
public class ElasticV7QueryGroupsTest extends AbstractQueryGroupsTest {
|
||||||
private static ElasticNodeInfo nodeInfo;
|
private static ElasticNodeInfo nodeInfo;
|
||||||
private static ElasticContainer<?> container;
|
private static ElasticContainer container;
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void startIndexService() {
|
public static void startIndexService() {
|
||||||
|
|||||||
@@ -35,3 +35,12 @@ java_library(
|
|||||||
"//lib/log:ext",
|
"//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