Merge branch 'stable-2.15'
* stable-2.15: ElasticContainer: Allow to specify the docker container version to create ElasticContainer: Include cause in AssumptionViolatedException ElasticContainer: Create with static method Acceptance tests: Replace embedded ES with docker testcontainer Elasticsearch: replace native API in prod w/ REST Change-Id: I6b2c4f4d6c28538073f432f8e64cc18ba9de32ef
This commit is contained in:
@@ -17,20 +17,49 @@ package com.google.gerrit.elasticsearch;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import java.util.Set;
|
||||
import org.apache.http.HttpHost;
|
||||
import org.junit.AssumptionViolatedException;
|
||||
import org.testcontainers.containers.GenericContainer;
|
||||
|
||||
/* Helper class for running ES integration tests in docker container */
|
||||
public class ElasticContainer<SELF extends ElasticContainer<SELF>> extends GenericContainer<SELF> {
|
||||
private static final String NAME = "elasticsearch";
|
||||
private static final String VERSION = "2.4.6-alpine";
|
||||
private static final int ELASTICSEARCH_DEFAULT_PORT = 9200;
|
||||
|
||||
public ElasticContainer() {
|
||||
this(NAME + ":" + VERSION);
|
||||
public enum Version {
|
||||
V2,
|
||||
V5,
|
||||
V6
|
||||
}
|
||||
|
||||
public ElasticContainer(String dockerImageName) {
|
||||
super(dockerImageName);
|
||||
public static ElasticContainer<?> createAndStart(Version version) {
|
||||
// Assumption violation is not natively supported by Testcontainers.
|
||||
// See https://github.com/testcontainers/testcontainers-java/issues/343
|
||||
try {
|
||||
ElasticContainer<?> container = new ElasticContainer<>(version);
|
||||
container.start();
|
||||
return container;
|
||||
} catch (Throwable t) {
|
||||
throw new AssumptionViolatedException("Unable to start container", t);
|
||||
}
|
||||
}
|
||||
|
||||
public static ElasticContainer<?> createAndStart() {
|
||||
return createAndStart(Version.V2);
|
||||
}
|
||||
|
||||
private static String getImageName(Version version) {
|
||||
switch (version) {
|
||||
case V2:
|
||||
return "elasticsearch:2.4.6-alpine";
|
||||
case V5:
|
||||
return "elasticsearch:5.6.9-alpine";
|
||||
case V6:
|
||||
return "docker.elastic.co/elasticsearch/elasticsearch:6.2.4";
|
||||
}
|
||||
throw new IllegalStateException("Unsupported version: " + version.name());
|
||||
}
|
||||
|
||||
private ElasticContainer(Version version) {
|
||||
super(getImageName(version));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -23,7 +23,6 @@ import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
import org.eclipse.jgit.lib.Config;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.AssumptionViolatedException;
|
||||
import org.junit.BeforeClass;
|
||||
|
||||
public class ElasticQueryAccountsTest extends AbstractQueryAccountsTest {
|
||||
@@ -42,15 +41,7 @@ public class ElasticQueryAccountsTest extends AbstractQueryAccountsTest {
|
||||
return;
|
||||
}
|
||||
|
||||
// Assumption violation is not natively supported by Testcontainers.
|
||||
// See https://github.com/testcontainers/testcontainers-java/issues/343
|
||||
try {
|
||||
container = new ElasticContainer<>();
|
||||
container.start();
|
||||
} catch (Throwable t) {
|
||||
throw new AssumptionViolatedException("Unable to start container[might be docker related]");
|
||||
}
|
||||
|
||||
container = ElasticContainer.createAndStart();
|
||||
nodeInfo = new ElasticNodeInfo(container.getHttpHost().getPort());
|
||||
}
|
||||
|
||||
|
||||
@@ -25,7 +25,6 @@ import com.google.inject.Injector;
|
||||
import org.eclipse.jgit.junit.TestRepository;
|
||||
import org.eclipse.jgit.lib.Config;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.AssumptionViolatedException;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -45,15 +44,7 @@ public class ElasticQueryChangesTest extends AbstractQueryChangesTest {
|
||||
return;
|
||||
}
|
||||
|
||||
// Assumption violation is not natively supported by Testcontainers.
|
||||
// See https://github.com/testcontainers/testcontainers-java/issues/343
|
||||
try {
|
||||
container = new ElasticContainer<>();
|
||||
container.start();
|
||||
} catch (Throwable t) {
|
||||
throw new AssumptionViolatedException("Unable to start container[might be docker related]");
|
||||
}
|
||||
|
||||
container = ElasticContainer.createAndStart();
|
||||
nodeInfo = new ElasticNodeInfo(container.getHttpHost().getPort());
|
||||
}
|
||||
|
||||
|
||||
@@ -23,7 +23,6 @@ import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
import org.eclipse.jgit.lib.Config;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.AssumptionViolatedException;
|
||||
import org.junit.BeforeClass;
|
||||
|
||||
public class ElasticQueryGroupsTest extends AbstractQueryGroupsTest {
|
||||
@@ -42,15 +41,7 @@ public class ElasticQueryGroupsTest extends AbstractQueryGroupsTest {
|
||||
return;
|
||||
}
|
||||
|
||||
// Assumption violation is not natively supported by Testcontainers.
|
||||
// See https://github.com/testcontainers/testcontainers-java/issues/343
|
||||
try {
|
||||
container = new ElasticContainer<>();
|
||||
container.start();
|
||||
} catch (Throwable t) {
|
||||
throw new AssumptionViolatedException("Unable to start container[might be docker related]");
|
||||
}
|
||||
|
||||
container = ElasticContainer.createAndStart();
|
||||
nodeInfo = new ElasticNodeInfo(container.getHttpHost().getPort());
|
||||
}
|
||||
|
||||
|
||||
@@ -23,7 +23,6 @@ import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
import org.eclipse.jgit.lib.Config;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.AssumptionViolatedException;
|
||||
import org.junit.BeforeClass;
|
||||
|
||||
public class ElasticQueryProjectsTest extends AbstractQueryProjectsTest {
|
||||
@@ -42,15 +41,7 @@ public class ElasticQueryProjectsTest extends AbstractQueryProjectsTest {
|
||||
return;
|
||||
}
|
||||
|
||||
// Assumption violation is not natively supported by Testcontainers.
|
||||
// See https://github.com/testcontainers/testcontainers-java/issues/343
|
||||
try {
|
||||
container = new ElasticContainer<>();
|
||||
container.start();
|
||||
} catch (Throwable t) {
|
||||
throw new AssumptionViolatedException("Unable to start container[might be docker related]");
|
||||
}
|
||||
|
||||
container = ElasticContainer.createAndStart();
|
||||
nodeInfo = new ElasticNodeInfo(container.getHttpHost().getPort());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user