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:
parent
f9758fd8bb
commit
4b1ff15c1a
128
WORKSPACE
128
WORKSPACE
@ -238,6 +238,12 @@ maven_jar(
|
||||
sha1 = "6cca9a3b999ff28b7a35ca762b3197cd7e4c2ad1",
|
||||
)
|
||||
|
||||
maven_jar(
|
||||
name = "log_ext",
|
||||
artifact = "org.slf4j:slf4j-ext:" + SLF4J_VERS,
|
||||
sha1 = "09a8f58c784c37525d2624062414358acf296717",
|
||||
)
|
||||
|
||||
maven_jar(
|
||||
name = "impl_log4j",
|
||||
artifact = "org.slf4j:slf4j-log4j12:" + SLF4J_VERS,
|
||||
@ -436,7 +442,6 @@ maven_jar(
|
||||
sha1 = "05b6f921f1810bdf90e25471968f741f87168b64",
|
||||
)
|
||||
|
||||
# When upgrading Lucene, make sure it's compatible with Elasticsearch
|
||||
LUCENE_VERS = "5.5.4"
|
||||
|
||||
maven_jar(
|
||||
@ -469,42 +474,6 @@ maven_jar(
|
||||
sha1 = "8a06fad4675473d98d93b61fea529e3f464bf69e",
|
||||
)
|
||||
|
||||
maven_jar(
|
||||
name = "lucene_highlighter",
|
||||
artifact = "org.apache.lucene:lucene-highlighter:" + LUCENE_VERS,
|
||||
sha1 = "433f53f03f1b14337c08d54e507a5410905376fa",
|
||||
)
|
||||
|
||||
maven_jar(
|
||||
name = "lucene_join",
|
||||
artifact = "org.apache.lucene:lucene-join:" + LUCENE_VERS,
|
||||
sha1 = "23f9a909a244ed3b28b37c5bb21a6e33e6c0a339",
|
||||
)
|
||||
|
||||
maven_jar(
|
||||
name = "lucene_memory",
|
||||
artifact = "org.apache.lucene:lucene-memory:" + LUCENE_VERS,
|
||||
sha1 = "4dbdc2e1a24837722294762a9edb479f79092ab9",
|
||||
)
|
||||
|
||||
maven_jar(
|
||||
name = "lucene_spatial",
|
||||
artifact = "org.apache.lucene:lucene-spatial:" + LUCENE_VERS,
|
||||
sha1 = "0217d302dc0ef4d9b8b475ffe327d83c1e0ceba5",
|
||||
)
|
||||
|
||||
maven_jar(
|
||||
name = "lucene_suggest",
|
||||
artifact = "org.apache.lucene:lucene-suggest:" + LUCENE_VERS,
|
||||
sha1 = "0f46dbb3229eed62dff10d008172c885e0e028c8",
|
||||
)
|
||||
|
||||
maven_jar(
|
||||
name = "lucene_queries",
|
||||
artifact = "org.apache.lucene:lucene-queries:" + LUCENE_VERS,
|
||||
sha1 = "f915357b8b4b43742ab48f1401dedcaa12dfa37a",
|
||||
)
|
||||
|
||||
maven_jar(
|
||||
name = "mime_util",
|
||||
artifact = "eu.medsea.mimeutil:mime-util:2.1.3",
|
||||
@ -911,61 +880,12 @@ maven_jar(
|
||||
sha1 = "8903bf42272062e87a7cbc1d98919e0729a9939f",
|
||||
)
|
||||
|
||||
# When upgrading Elasticsearch, make sure it's compatible with Lucene
|
||||
maven_jar(
|
||||
name = "elasticsearch",
|
||||
artifact = "org.elasticsearch:elasticsearch:2.4.6",
|
||||
sha1 = "d2954e1173a608a9711f132d1768a676a8b1fb81",
|
||||
)
|
||||
|
||||
maven_jar(
|
||||
name = "joda_time",
|
||||
artifact = "joda-time:joda-time:2.9.9",
|
||||
sha1 = "f7b520c458572890807d143670c9b24f4de90897",
|
||||
)
|
||||
|
||||
maven_jar(
|
||||
name = "joda_convert",
|
||||
artifact = "org.joda:joda-convert:1.8.1",
|
||||
sha1 = "675642ac208e0b741bc9118dcbcae44c271b992a",
|
||||
)
|
||||
|
||||
maven_jar(
|
||||
name = "elasticsearch-rest-client",
|
||||
artifact = "org.elasticsearch.client:elasticsearch-rest-client:5.6.9",
|
||||
sha1 = "895706412e2fba3f842fca82ec3dece1cb4ee7d1",
|
||||
)
|
||||
|
||||
maven_jar(
|
||||
name = "compress_lzf",
|
||||
artifact = "com.ning:compress-lzf:1.0.2",
|
||||
sha1 = "62896e6fca184c79cc01a14d143f3ae2b4f4b4ae",
|
||||
)
|
||||
|
||||
maven_jar(
|
||||
name = "hppc",
|
||||
artifact = "com.carrotsearch:hppc:0.7.1",
|
||||
sha1 = "8b5057f74ea378c0150a1860874a3ebdcb713767",
|
||||
)
|
||||
|
||||
maven_jar(
|
||||
name = "jsr166e",
|
||||
artifact = "com.twitter:jsr166e:1.1.0",
|
||||
sha1 = "233098147123ee5ddcd39ffc57ff648be4b7e5b2",
|
||||
)
|
||||
|
||||
maven_jar(
|
||||
name = "netty",
|
||||
artifact = "io.netty:netty:3.10.0.Final",
|
||||
sha1 = "ad61cd1bba067e6634ddd3e160edf0727391ac30",
|
||||
)
|
||||
|
||||
maven_jar(
|
||||
name = "t_digest",
|
||||
artifact = "com.tdunning:t-digest:3.0",
|
||||
sha1 = "84ccf145ac2215e6bfa63baa3101c0af41017cfc",
|
||||
)
|
||||
|
||||
JACKSON_VERSION = "2.8.9"
|
||||
|
||||
maven_jar(
|
||||
@ -974,18 +894,6 @@ maven_jar(
|
||||
sha1 = "569b1752705da98f49aabe2911cc956ff7d8ed9d",
|
||||
)
|
||||
|
||||
maven_jar(
|
||||
name = "jackson_dataformat_cbor",
|
||||
artifact = "com.fasterxml.jackson.dataformat:jackson-dataformat-cbor:" + JACKSON_VERSION,
|
||||
sha1 = "93242092324cad33d777e06c0515e40a6b862659",
|
||||
)
|
||||
|
||||
maven_jar(
|
||||
name = "jackson_dataformat_smile",
|
||||
artifact = "com.fasterxml.jackson.dataformat:jackson-dataformat-smile:" + JACKSON_VERSION,
|
||||
sha1 = "d36cbae6b06ac12fca16fda403759e479316141b",
|
||||
)
|
||||
|
||||
maven_jar(
|
||||
name = "httpasyncclient",
|
||||
artifact = "org.apache.httpcomponents:httpasyncclient:4.1.2",
|
||||
@ -998,6 +906,30 @@ maven_jar(
|
||||
sha1 = "a8c5e3c3bfea5ce23fb647c335897e415eb442e3",
|
||||
)
|
||||
|
||||
maven_jar(
|
||||
name = "testcontainers",
|
||||
artifact = "org.testcontainers:testcontainers:1.7.2",
|
||||
sha1 = "fec8b360b6b613f6c9d3b8e7a9fa32d1a2bcb978",
|
||||
)
|
||||
|
||||
maven_jar(
|
||||
name = "duct_tape",
|
||||
artifact = "org.rnorth.duct-tape:duct-tape:1.0.7",
|
||||
sha1 = "a26b5d90d88c91321dc7a3734ea72d2fc019ebb6",
|
||||
)
|
||||
|
||||
maven_jar(
|
||||
name = "visible_assertions",
|
||||
artifact = "org.rnorth.visible-assertions:visible-assertions:2.1.0",
|
||||
sha1 = "f2fcff2862860828ac38a5e1f14d941787c06b13",
|
||||
)
|
||||
|
||||
maven_jar(
|
||||
name = "jna",
|
||||
artifact = "net.java.dev.jna:jna:4.5.1",
|
||||
sha1 = "65bd0cacc9c79a21c6ed8e9f588577cd3c2f85b9",
|
||||
)
|
||||
|
||||
load("//tools/bzl:js.bzl", "npm_binary", "bower_archive")
|
||||
|
||||
npm_binary(
|
||||
|
@ -16,7 +16,6 @@ java_library(
|
||||
"//lib:protobuf",
|
||||
"//lib/commons:codec",
|
||||
"//lib/commons:lang",
|
||||
"//lib/elasticsearch:joda-time",
|
||||
"//lib/elasticsearch-rest-client",
|
||||
"//lib/guice",
|
||||
"//lib/guice:guice-assistedinject",
|
||||
|
@ -3,7 +3,11 @@ load("//tools/bzl:junit.bzl", "junit_tests")
|
||||
java_library(
|
||||
name = "elasticsearch_test_utils",
|
||||
testonly = 1,
|
||||
srcs = ["ElasticTestUtils.java"],
|
||||
srcs = [
|
||||
"ElasticContainer.java",
|
||||
"ElasticTestUtils.java",
|
||||
],
|
||||
visibility = ["//visibility:public"],
|
||||
deps = [
|
||||
"//java/com/google/gerrit/elasticsearch",
|
||||
"//java/com/google/gerrit/extensions:api",
|
||||
@ -14,10 +18,11 @@ java_library(
|
||||
"//lib:gson",
|
||||
"//lib:guava",
|
||||
"//lib:junit",
|
||||
"//lib/elasticsearch",
|
||||
"//lib/guice",
|
||||
"//lib/httpcomponents:httpcore",
|
||||
"//lib/jgit/org.eclipse.jgit:jgit",
|
||||
"//lib/jgit/org.eclipse.jgit.junit:junit",
|
||||
"//lib/testcontainers",
|
||||
"//lib/truth",
|
||||
],
|
||||
)
|
||||
@ -44,7 +49,9 @@ ELASTICSEARCH_TESTS = {i: "ElasticQuery" + i.capitalize() + "sTest.java" for i i
|
||||
"//java/com/google/gerrit/testing:gerrit-test-util",
|
||||
"//javatests/com/google/gerrit/server/query/%s:abstract_query_tests" % name,
|
||||
"//lib/guice",
|
||||
"//lib/httpcomponents:httpcore",
|
||||
"//lib/jgit/org.eclipse.jgit:jgit",
|
||||
"//lib/jgit/org.eclipse.jgit.junit:junit",
|
||||
"//lib/testcontainers",
|
||||
],
|
||||
) for name, src in ELASTICSEARCH_TESTS.items()]
|
||||
|
@ -0,0 +1,52 @@
|
||||
// Copyright (C) 2018 The Android Open Source Project
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package com.google.gerrit.elasticsearch;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import java.util.Set;
|
||||
import org.apache.http.HttpHost;
|
||||
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 ElasticContainer(String dockerImageName) {
|
||||
super(dockerImageName);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void configure() {
|
||||
addExposedPort(ELASTICSEARCH_DEFAULT_PORT);
|
||||
|
||||
// https://github.com/docker-library/elasticsearch/issues/58
|
||||
addEnv("-Ees.network.host", "0.0.0.0");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Set<Integer> getLivenessCheckPorts() {
|
||||
return ImmutableSet.of(getMappedPort(ELASTICSEARCH_DEFAULT_PORT));
|
||||
}
|
||||
|
||||
public HttpHost getHttpHost() {
|
||||
return new HttpHost(getContainerIpAddress(), getMappedPort(ELASTICSEARCH_DEFAULT_PORT));
|
||||
}
|
||||
}
|
@ -21,9 +21,9 @@ import com.google.gerrit.testing.InMemoryModule;
|
||||
import com.google.gerrit.testing.IndexConfig;
|
||||
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.AssumptionViolatedException;
|
||||
import org.junit.BeforeClass;
|
||||
|
||||
public class ElasticQueryAccountsTest extends AbstractQueryAccountsTest {
|
||||
@ -33,22 +33,31 @@ 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();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -22,10 +22,10 @@ import com.google.gerrit.testing.InMemoryRepositoryManager.Repo;
|
||||
import com.google.gerrit.testing.IndexConfig;
|
||||
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.AssumptionViolatedException;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
@ -36,22 +36,31 @@ public class ElasticQueryChangesTest extends AbstractQueryChangesTest {
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -21,9 +21,9 @@ import com.google.gerrit.testing.InMemoryModule;
|
||||
import com.google.gerrit.testing.IndexConfig;
|
||||
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.AssumptionViolatedException;
|
||||
import org.junit.BeforeClass;
|
||||
|
||||
public class ElasticQueryGroupsTest extends AbstractQueryGroupsTest {
|
||||
@ -33,22 +33,31 @@ 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();
|
||||
|
||||
// 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();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -21,9 +21,9 @@ import com.google.gerrit.testing.InMemoryModule;
|
||||
import com.google.gerrit.testing.IndexConfig;
|
||||
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.AssumptionViolatedException;
|
||||
import org.junit.BeforeClass;
|
||||
|
||||
public class ElasticQueryProjectsTest extends AbstractQueryProjectsTest {
|
||||
@ -33,22 +33,31 @@ public class ElasticQueryProjectsTest extends AbstractQueryProjectsTest {
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -14,90 +14,31 @@
|
||||
|
||||
package com.google.gerrit.elasticsearch;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import com.google.common.base.Strings;
|
||||
import com.google.common.io.Files;
|
||||
import com.google.gerrit.index.IndexDefinition;
|
||||
import com.google.gerrit.server.index.IndexModule.IndexType;
|
||||
import com.google.gson.FieldNamingPolicy;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.Key;
|
||||
import com.google.inject.TypeLiteral;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import org.eclipse.jgit.lib.Config;
|
||||
import org.elasticsearch.action.admin.cluster.node.info.NodesInfoRequest;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.node.Node;
|
||||
import org.elasticsearch.node.NodeBuilder;
|
||||
|
||||
public final class ElasticTestUtils {
|
||||
public static class ElasticNodeInfo {
|
||||
public final Node node;
|
||||
public final String port;
|
||||
public final File elasticDir;
|
||||
public final int port;
|
||||
|
||||
private ElasticNodeInfo(Node node, File rootDir, String port) {
|
||||
this.node = node;
|
||||
public ElasticNodeInfo(int port) {
|
||||
this.port = port;
|
||||
this.elasticDir = rootDir;
|
||||
}
|
||||
}
|
||||
|
||||
static void configure(Config config, String port, String prefix) {
|
||||
public static void configure(Config config, int port, String prefix) {
|
||||
config.setEnum("index", null, "type", IndexType.ELASTICSEARCH);
|
||||
config.setString("elasticsearch", "test", "protocol", "http");
|
||||
config.setString("elasticsearch", "test", "hostname", "localhost");
|
||||
config.setString("elasticsearch", "test", "port", port);
|
||||
config.setInt("elasticsearch", "test", "port", port);
|
||||
config.setString("elasticsearch", null, "prefix", prefix);
|
||||
}
|
||||
|
||||
static ElasticNodeInfo startElasticsearchNode() throws InterruptedException, ExecutionException {
|
||||
File elasticDir = Files.createTempDir();
|
||||
Path elasticDirPath = elasticDir.toPath();
|
||||
Settings settings =
|
||||
Settings.settingsBuilder()
|
||||
.put("cluster.name", "gerrit")
|
||||
.put("node.name", "Gerrit Elasticsearch Test Node")
|
||||
.put("node.local", true)
|
||||
.put("discovery.zen.ping.multicast.enabled", false)
|
||||
.put("index.store.fs.memory.enabled", true)
|
||||
.put("index.gateway.type", "none")
|
||||
.put("index.max_result_window", Integer.MAX_VALUE)
|
||||
.put("gateway.type", "default")
|
||||
.put("http.port", 0)
|
||||
.put("discovery.zen.ping.unicast.hosts", "[\"localhost\"]")
|
||||
.put("path.home", elasticDirPath.toAbsolutePath())
|
||||
.put("path.data", elasticDirPath.resolve("data").toAbsolutePath())
|
||||
.put("path.work", elasticDirPath.resolve("work").toAbsolutePath())
|
||||
.put("path.logs", elasticDirPath.resolve("logs").toAbsolutePath())
|
||||
.put("transport.tcp.connect_timeout", "60s")
|
||||
.build();
|
||||
|
||||
// Start the node
|
||||
Node node = NodeBuilder.nodeBuilder().settings(settings).node();
|
||||
|
||||
// Wait for it to be ready
|
||||
node.client().admin().cluster().prepareHealth().setWaitForYellowStatus().execute().actionGet();
|
||||
|
||||
assertThat(node.isClosed()).isFalse();
|
||||
return new ElasticNodeInfo(node, elasticDir, getHttpPort(node));
|
||||
}
|
||||
|
||||
static class NodeInfo {
|
||||
String httpAddress;
|
||||
}
|
||||
|
||||
static class Info {
|
||||
Map<String, NodeInfo> nodes;
|
||||
config.setString("index", null, "maxLimit", "10000");
|
||||
}
|
||||
|
||||
public static void createAllIndexes(Injector injector) throws IOException {
|
||||
@ -108,28 +49,6 @@ public final class ElasticTestUtils {
|
||||
}
|
||||
}
|
||||
|
||||
private static String getHttpPort(Node node) throws InterruptedException, ExecutionException {
|
||||
String nodes =
|
||||
node.client().admin().cluster().nodesInfo(new NodesInfoRequest("*")).get().toString();
|
||||
Gson gson =
|
||||
new GsonBuilder()
|
||||
.setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES)
|
||||
.create();
|
||||
Info info = gson.fromJson(nodes, Info.class);
|
||||
if (info.nodes == null || info.nodes.size() != 1) {
|
||||
throw new RuntimeException("Cannot extract local Elasticsearch http port");
|
||||
}
|
||||
Iterator<NodeInfo> values = info.nodes.values().iterator();
|
||||
String httpAddress = values.next().httpAddress;
|
||||
if (Strings.isNullOrEmpty(httpAddress)) {
|
||||
throw new RuntimeException("Cannot extract local Elasticsearch http port");
|
||||
}
|
||||
if (httpAddress.indexOf(':') < 0) {
|
||||
throw new RuntimeException("Seems that port is not included in Elasticsearch http_address");
|
||||
}
|
||||
return httpAddress.substring(httpAddress.indexOf(':') + 1, httpAddress.length());
|
||||
}
|
||||
|
||||
private ElasticTestUtils() {
|
||||
// hide default constructor
|
||||
}
|
||||
|
22
lib/LICENSE-testcontainers
Normal file
22
lib/LICENSE-testcontainers
Normal file
@ -0,0 +1,22 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2015 Richard North
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
|
@ -1,73 +0,0 @@
|
||||
package(default_visibility = ["//visibility:public"])
|
||||
|
||||
java_library(
|
||||
name = "elasticsearch",
|
||||
testonly = 1,
|
||||
data = ["//lib:LICENSE-Apache2.0"],
|
||||
exports = ["@elasticsearch//jar"],
|
||||
runtime_deps = [
|
||||
":compress-lzf",
|
||||
":hppc",
|
||||
":joda-time",
|
||||
":jsr166e",
|
||||
":netty",
|
||||
":t-digest",
|
||||
"//lib/jackson:jackson-core",
|
||||
"//lib/jackson:jackson-dataformat-cbor",
|
||||
"//lib/jackson:jackson-dataformat-smile",
|
||||
"//lib/lucene:lucene-highlighter",
|
||||
"//lib/lucene:lucene-join",
|
||||
"//lib/lucene:lucene-memory",
|
||||
"//lib/lucene:lucene-queries",
|
||||
"//lib/lucene:lucene-spatial",
|
||||
"//lib/lucene:lucene-suggest",
|
||||
],
|
||||
)
|
||||
|
||||
java_library(
|
||||
name = "joda-time",
|
||||
data = ["//lib:LICENSE-Apache2.0"],
|
||||
exports = ["@joda_time//jar"],
|
||||
runtime_deps = ["joda-convert"],
|
||||
)
|
||||
|
||||
java_library(
|
||||
name = "joda-convert",
|
||||
data = ["//lib:LICENSE-Apache2.0"],
|
||||
exports = ["@joda_convert//jar"],
|
||||
)
|
||||
|
||||
java_library(
|
||||
name = "compress-lzf",
|
||||
data = ["//lib:LICENSE-Apache2.0"],
|
||||
visibility = ["//lib/elasticsearch:__pkg__"],
|
||||
exports = ["@compress_lzf//jar"],
|
||||
)
|
||||
|
||||
java_library(
|
||||
name = "hppc",
|
||||
data = ["//lib:LICENSE-Apache2.0"],
|
||||
visibility = ["//lib/elasticsearch:__pkg__"],
|
||||
exports = ["@hppc//jar"],
|
||||
)
|
||||
|
||||
java_library(
|
||||
name = "jsr166e",
|
||||
data = ["//lib:LICENSE-Apache2.0"],
|
||||
visibility = ["//lib/elasticsearch:__pkg__"],
|
||||
exports = ["@jsr166e//jar"],
|
||||
)
|
||||
|
||||
java_library(
|
||||
name = "netty",
|
||||
data = ["//lib:LICENSE-Apache2.0"],
|
||||
visibility = ["//lib/elasticsearch:__pkg__"],
|
||||
exports = ["@netty//jar"],
|
||||
)
|
||||
|
||||
java_library(
|
||||
name = "t-digest",
|
||||
data = ["//lib:LICENSE-Apache2.0"],
|
||||
visibility = ["//lib/elasticsearch:__pkg__"],
|
||||
exports = ["@t_digest//jar"],
|
||||
)
|
@ -7,15 +7,3 @@ java_library(
|
||||
data = ["//lib:LICENSE-Apache2.0"],
|
||||
exports = ["@jackson_core//jar"],
|
||||
)
|
||||
|
||||
java_library(
|
||||
name = "jackson-dataformat-cbor",
|
||||
data = ["//lib:LICENSE-Apache2.0"],
|
||||
exports = ["@jackson_dataformat_cbor//jar"],
|
||||
)
|
||||
|
||||
java_library(
|
||||
name = "jackson-dataformat-smile",
|
||||
data = ["//lib:LICENSE-Apache2.0"],
|
||||
exports = ["@jackson_dataformat_smile//jar"],
|
||||
)
|
||||
|
@ -13,6 +13,13 @@ java_library(
|
||||
runtime_deps = [":api"],
|
||||
)
|
||||
|
||||
java_library(
|
||||
name = "ext",
|
||||
data = ["//lib:LICENSE-slf4j"],
|
||||
visibility = ["//visibility:public"],
|
||||
exports = ["@log_ext//jar"],
|
||||
)
|
||||
|
||||
java_library(
|
||||
name = "impl_log4j",
|
||||
data = ["//lib:LICENSE-slf4j"],
|
||||
|
@ -44,39 +44,3 @@ java_library(
|
||||
exports = ["@lucene_queryparser//jar"],
|
||||
runtime_deps = [":lucene-core-and-backward-codecs"],
|
||||
)
|
||||
|
||||
java_library(
|
||||
name = "lucene-highlighter",
|
||||
data = ["//lib:LICENSE-Apache2.0"],
|
||||
exports = ["@lucene_highlighter//jar"],
|
||||
)
|
||||
|
||||
java_library(
|
||||
name = "lucene-join",
|
||||
data = ["//lib:LICENSE-Apache2.0"],
|
||||
exports = ["@lucene_join//jar"],
|
||||
)
|
||||
|
||||
java_library(
|
||||
name = "lucene-memory",
|
||||
data = ["//lib:LICENSE-Apache2.0"],
|
||||
exports = ["@lucene_memory//jar"],
|
||||
)
|
||||
|
||||
java_library(
|
||||
name = "lucene-spatial",
|
||||
data = ["//lib:LICENSE-Apache2.0"],
|
||||
exports = ["@lucene_spatial//jar"],
|
||||
)
|
||||
|
||||
java_library(
|
||||
name = "lucene-suggest",
|
||||
data = ["//lib:LICENSE-Apache2.0"],
|
||||
exports = ["@lucene_suggest//jar"],
|
||||
)
|
||||
|
||||
java_library(
|
||||
name = "lucene-queries",
|
||||
data = ["//lib:LICENSE-Apache2.0"],
|
||||
exports = ["@lucene_queries//jar"],
|
||||
)
|
||||
|
37
lib/testcontainers/BUILD
Normal file
37
lib/testcontainers/BUILD
Normal file
@ -0,0 +1,37 @@
|
||||
java_library(
|
||||
name = "duct-tape",
|
||||
testonly = True,
|
||||
data = ["//lib:LICENSE-testcontainers"],
|
||||
visibility = ["//visibility:public"],
|
||||
exports = ["@duct_tape//jar"],
|
||||
)
|
||||
|
||||
java_library(
|
||||
name = "visible-assertions",
|
||||
testonly = True,
|
||||
data = ["//lib:LICENSE-testcontainers"],
|
||||
visibility = ["//visibility:public"],
|
||||
exports = ["@visible_assertions//jar"],
|
||||
)
|
||||
|
||||
java_library(
|
||||
name = "jna",
|
||||
testonly = True,
|
||||
data = ["//lib:LICENSE-Apache2.0"],
|
||||
visibility = ["//visibility:public"],
|
||||
exports = ["@jna//jar"],
|
||||
)
|
||||
|
||||
java_library(
|
||||
name = "testcontainers",
|
||||
testonly = True,
|
||||
data = ["//lib:LICENSE-testcontainers"],
|
||||
visibility = ["//visibility:public"],
|
||||
exports = ["@testcontainers//jar"],
|
||||
runtime_deps = [
|
||||
":duct-tape",
|
||||
":jna",
|
||||
":visible-assertions",
|
||||
"//lib/log:ext",
|
||||
],
|
||||
)
|
@ -9,8 +9,8 @@ load(
|
||||
|
||||
TEST_DEPS = [
|
||||
"//gerrit-gwtui:ui_tests",
|
||||
"//javatests/com/google/gerrit/elasticsearch:elasticsearch_test_utils",
|
||||
"//javatests/com/google/gerrit/server:server_tests",
|
||||
"//lib/elasticsearch",
|
||||
]
|
||||
|
||||
DEPS = [
|
||||
|
Loading…
Reference in New Issue
Block a user