Acceptance tests: Replace embedded ES with docker testcontainer

Testcontainers is a Java 8 library that supports JUnit tests, providing
lightweight, throwaway instances of common databases, Selenium web
browsers, or anything else that can run in a Docker container.

This change replaces ES integration test that currently uses embedded
ES mode with ES docker image using Testcontainers library. All this is
done from within acceptance tests.

This change removes dependency on ES server stack for the test code. As
the consequence, this stack can be removed.

Prerequisite for this change is installed docker service on the SUT. If
docker service is not installed, assumption violation is raised so that
the tests don't fail. Unfortunately, due to this missing Bazel feature,
JUnit assumption violations are not reflected on the Bazel UI: [1] yet.

[1] https://github.com/bazelbuild/bazel/issues/3476

Change-Id: Iccf44310292cc44bff9173f2a4ea757b43f77183
This commit is contained in:
David Ostrovsky
2018-05-21 23:50:02 +02:00
committed by David Pursehouse
parent 9b4b09ee61
commit 5f40a6adff
13 changed files with 225 additions and 289 deletions

View File

@@ -14,35 +14,45 @@
package com.google.gerrit.elasticsearch;
import com.google.gerrit.elasticsearch.testing.ElasticContainer;
import com.google.gerrit.elasticsearch.testing.ElasticTestUtils;
import com.google.gerrit.elasticsearch.testing.ElasticTestUtils.ElasticNodeInfo;
import com.google.gerrit.server.query.account.AbstractQueryAccountsTest;
import com.google.gerrit.testutil.InMemoryModule;
import com.google.inject.Guice;
import com.google.inject.Injector;
import java.util.concurrent.ExecutionException;
import org.eclipse.jgit.lib.Config;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.internal.AssumptionViolatedException;
public class ElasticQueryAccountsTest extends AbstractQueryAccountsTest {
private static ElasticNodeInfo nodeInfo;
private static ElasticContainer<?> container;
@BeforeClass
public static void startIndexService() throws InterruptedException, ExecutionException {
public static void startIndexService() {
if (nodeInfo != null) {
// do not start Elasticsearch twice
return;
}
nodeInfo = ElasticTestUtils.startElasticsearchNode();
// 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]");
}
nodeInfo = new ElasticNodeInfo(container.getHttpHost().getPort());
}
@AfterClass
public static void stopElasticsearchServer() {
if (nodeInfo != null) {
nodeInfo.node.close();
nodeInfo.elasticDir.delete();
nodeInfo = null;
if (container != null) {
container.stop();
}
}

View File

@@ -14,6 +14,7 @@
package com.google.gerrit.elasticsearch;
import com.google.gerrit.elasticsearch.testing.ElasticContainer;
import com.google.gerrit.elasticsearch.testing.ElasticTestUtils;
import com.google.gerrit.elasticsearch.testing.ElasticTestUtils.ElasticNodeInfo;
import com.google.gerrit.server.query.change.AbstractQueryChangesTest;
@@ -21,35 +22,42 @@ import com.google.gerrit.testutil.InMemoryModule;
import com.google.gerrit.testutil.InMemoryRepositoryManager.Repo;
import com.google.inject.Guice;
import com.google.inject.Injector;
import java.util.concurrent.ExecutionException;
import org.eclipse.jgit.junit.TestRepository;
import org.eclipse.jgit.lib.Config;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;
import org.junit.internal.AssumptionViolatedException;
import org.junit.rules.TestName;
public class ElasticQueryChangesTest extends AbstractQueryChangesTest {
@Rule public final TestName testName = new TestName();
private static ElasticNodeInfo nodeInfo;
private static ElasticContainer<?> container;
@BeforeClass
public static void startIndexService() throws InterruptedException, ExecutionException {
public static void startIndexService() {
if (nodeInfo != null) {
// do not start Elasticsearch twice
return;
}
nodeInfo = ElasticTestUtils.startElasticsearchNode();
try {
container = new ElasticContainer<>();
container.start();
} catch (Throwable t) {
throw new AssumptionViolatedException("Unable to start container[might be docker related]");
}
nodeInfo = new ElasticNodeInfo(container.getHttpHost().getPort());
}
@AfterClass
public static void stopElasticsearchServer() {
if (nodeInfo != null) {
nodeInfo.node.close();
nodeInfo.elasticDir.delete();
nodeInfo = null;
if (container != null) {
container.stop();
}
}

View File

@@ -14,35 +14,43 @@
package com.google.gerrit.elasticsearch;
import com.google.gerrit.elasticsearch.testing.ElasticContainer;
import com.google.gerrit.elasticsearch.testing.ElasticTestUtils;
import com.google.gerrit.elasticsearch.testing.ElasticTestUtils.ElasticNodeInfo;
import com.google.gerrit.server.query.group.AbstractQueryGroupsTest;
import com.google.gerrit.testutil.InMemoryModule;
import com.google.inject.Guice;
import com.google.inject.Injector;
import java.util.concurrent.ExecutionException;
import org.eclipse.jgit.lib.Config;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.internal.AssumptionViolatedException;
public class ElasticQueryGroupsTest extends AbstractQueryGroupsTest {
private static ElasticNodeInfo nodeInfo;
private static ElasticContainer<?> container;
@BeforeClass
public static void startIndexService() throws InterruptedException, ExecutionException {
public static void startIndexService() {
if (nodeInfo != null) {
// do not start Elasticsearch twice
return;
}
nodeInfo = ElasticTestUtils.startElasticsearchNode();
try {
container = new ElasticContainer<>();
container.start();
} catch (Throwable t) {
throw new AssumptionViolatedException("Unable to start container[might be docker related]");
}
nodeInfo = new ElasticNodeInfo(container.getHttpHost().getPort());
}
@AfterClass
public static void stopElasticsearchServer() {
if (nodeInfo != null) {
nodeInfo.node.close();
nodeInfo.elasticDir.delete();
nodeInfo = null;
if (container != null) {
container.stop();
}
}