From 5f40a6adff9e760c9da8680982e822ecf6f6cfd7 Mon Sep 17 00:00:00 2001 From: David Ostrovsky Date: Mon, 21 May 2018 23:50:02 +0200 Subject: [PATCH] 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 --- WORKSPACE | 108 +++++------------- .../gerrit/acceptance/pgm/ReindexIT.java | 28 +++-- gerrit-elasticsearch/BUILD | 5 +- .../testing/ElasticContainer.java | 52 +++++++++ .../testing/ElasticTestUtils.java | 92 +-------------- .../ElasticQueryAccountsTest.java | 24 ++-- .../ElasticQueryChangesTest.java | 22 ++-- .../elasticsearch/ElasticQueryGroupsTest.java | 22 ++-- lib/LICENSE-testcontainers | 22 ++++ lib/elasticsearch/BUILD | 59 ---------- lib/log/BUILD | 7 ++ lib/lucene/BUILD | 36 ------ lib/testcontainers/BUILD | 37 ++++++ 13 files changed, 225 insertions(+), 289 deletions(-) create mode 100644 gerrit-elasticsearch/src/main/java/com/google/gerrit/elasticsearch/testing/ElasticContainer.java create mode 100644 lib/LICENSE-testcontainers delete mode 100644 lib/elasticsearch/BUILD create mode 100644 lib/testcontainers/BUILD diff --git a/WORKSPACE b/WORKSPACE index d08ecbd51d..75bfeea95b 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -244,6 +244,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, @@ -476,42 +482,6 @@ maven_jar( sha1 = "8ac921563e744463605284c6d9d2d95e1be5b87c", ) -maven_jar( - name = "lucene_highlighter", - artifact = "org.apache.lucene:lucene-highlighter:" + LUCENE_VERS, - sha1 = "d127ac514e9df965ab0b57d92bbe0c68d3d145b8", -) - -maven_jar( - name = "lucene_join", - artifact = "org.apache.lucene:lucene-join:" + LUCENE_VERS, - sha1 = "dac1b322508f3f2696ecc49a97311d34d8382054", -) - -maven_jar( - name = "lucene_memory", - artifact = "org.apache.lucene:lucene-memory:" + LUCENE_VERS, - sha1 = "7409db9863d8fbc265c27793c6cc7511304182c2", -) - -maven_jar( - name = "lucene_spatial", - artifact = "org.apache.lucene:lucene-spatial:" + LUCENE_VERS, - sha1 = "8ed7a9a43d78222038573dd1c295a61f3c0bb0db", -) - -maven_jar( - name = "lucene_suggest", - artifact = "org.apache.lucene:lucene-suggest:" + LUCENE_VERS, - sha1 = "e8316b37dddcf2092a54dab2ce6aad0d5ad78585", -) - -maven_jar( - name = "lucene_queries", - artifact = "org.apache.lucene:lucene-queries:" + LUCENE_VERS, - sha1 = "692f1ad887cf4e006a23f45019e6de30f3312d3f", -) - maven_jar( name = "mime_util", artifact = "eu.medsea.mimeutil:mime-util:2.1.3", @@ -913,36 +883,6 @@ maven_jar( 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.6.6" maven_jar( @@ -951,18 +891,6 @@ maven_jar( sha1 = "02eb801df67aacaf5b1deb4ac626e1964508e47b", ) -maven_jar( - name = "jackson_dataformat_cbor", - artifact = "com.fasterxml.jackson.dataformat:jackson-dataformat-cbor:" + JACKSON_VERSION, - sha1 = "34c7b7ff495fc6b049612bdc9db0900a68e112f8", -) - -maven_jar( - name = "jackson_dataformat_smile", - artifact = "com.fasterxml.jackson.dataformat:jackson-dataformat-smile:" + JACKSON_VERSION, - sha1 = "ccbfc948748ed2754a58c1af9e0a02b5cc1aed69", -) - maven_jar( name = "httpasyncclient", artifact = "org.apache.httpcomponents:httpasyncclient:4.1.2", @@ -975,6 +903,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( diff --git a/gerrit-acceptance-tests/src/test/java/com/google/gerrit/acceptance/pgm/ReindexIT.java b/gerrit-acceptance-tests/src/test/java/com/google/gerrit/acceptance/pgm/ReindexIT.java index 145a5b9259..b30ba1dc5e 100644 --- a/gerrit-acceptance-tests/src/test/java/com/google/gerrit/acceptance/pgm/ReindexIT.java +++ b/gerrit-acceptance-tests/src/test/java/com/google/gerrit/acceptance/pgm/ReindexIT.java @@ -15,11 +15,13 @@ package com.google.gerrit.acceptance.pgm; import static com.google.common.truth.Truth8.assertThat; +import static com.google.common.truth.TruthJUnit.assume; import com.google.common.io.MoreFiles; import com.google.common.io.RecursiveDeleteOption; import com.google.gerrit.acceptance.NoHttpd; import com.google.gerrit.acceptance.StandaloneSiteTest; +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.extensions.api.GerritApi; @@ -28,7 +30,6 @@ import com.google.gerrit.reviewdb.client.Project; import com.google.gerrit.testutil.ConfigSuite; import java.nio.file.Files; import java.util.UUID; -import java.util.concurrent.ExecutionException; import org.eclipse.jgit.lib.Config; import org.junit.AfterClass; import org.junit.Test; @@ -37,9 +38,17 @@ import org.junit.Test; public class ReindexIT extends StandaloneSiteTest { @ConfigSuite.Config - public static Config elasticsearch() throws InterruptedException, ExecutionException { + public static Config elasticsearch() { + elasticsearchTest = true; if (elasticNodeInfo == null) { - elasticNodeInfo = ElasticTestUtils.startElasticsearchNode(); + try { + container = new ElasticContainer<>(); + container.start(); + } catch (Throwable t) { + return null; + } + + elasticNodeInfo = new ElasticNodeInfo(container.getHttpHost().getPort()); } String indicesPrefix = UUID.randomUUID().toString(); Config cfg = new Config(); @@ -48,9 +57,15 @@ public class ReindexIT extends StandaloneSiteTest { } private static ElasticNodeInfo elasticNodeInfo; + private static ElasticContainer container; + // TODO(davido): Retrieve elasticsearch config from test description + private static boolean elasticsearchTest; @Test public void reindexFromScratch() throws Exception { + if (elasticsearchTest) { + assume().that(elasticNodeInfo != null).isTrue(); + } Project.NameKey project = new Project.NameKey("project"); String changeId; try (ServerContext ctx = startServer()) { @@ -83,10 +98,9 @@ public class ReindexIT extends StandaloneSiteTest { @AfterClass public static void stopElasticServer() { - if (elasticNodeInfo != null) { - elasticNodeInfo.node.close(); - elasticNodeInfo.elasticDir.delete(); - elasticNodeInfo = null; + if (container != null) { + container.stop(); + elasticsearchTest = false; } } } diff --git a/gerrit-elasticsearch/BUILD b/gerrit-elasticsearch/BUILD index ee55267d11..09d35fe116 100644 --- a/gerrit-elasticsearch/BUILD +++ b/gerrit-elasticsearch/BUILD @@ -40,9 +40,10 @@ java_library( "//gerrit-server:server", "//lib:gson", "//lib:truth", - "//lib/elasticsearch", "//lib/guice", + "//lib/httpcomponents:httpcore", "//lib/jgit/org.eclipse.jgit:jgit", + "//lib/testcontainers", ], ) @@ -60,7 +61,9 @@ junit_tests( "//gerrit-server:server", "//gerrit-server:testutil", "//lib/guice", + "//lib/httpcomponents:httpcore", "//lib/jgit/org.eclipse.jgit:jgit", "//lib/jgit/org.eclipse.jgit.junit:junit", + "//lib/testcontainers", ], ) diff --git a/gerrit-elasticsearch/src/main/java/com/google/gerrit/elasticsearch/testing/ElasticContainer.java b/gerrit-elasticsearch/src/main/java/com/google/gerrit/elasticsearch/testing/ElasticContainer.java new file mode 100644 index 0000000000..bae6b06958 --- /dev/null +++ b/gerrit-elasticsearch/src/main/java/com/google/gerrit/elasticsearch/testing/ElasticContainer.java @@ -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.testing; + +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> extends GenericContainer { + 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 getLivenessCheckPorts() { + return ImmutableSet.of(getMappedPort(ELASTICSEARCH_DEFAULT_PORT)); + } + + public HttpHost getHttpHost() { + return new HttpHost(getContainerIpAddress(), getMappedPort(ELASTICSEARCH_DEFAULT_PORT)); + } +} diff --git a/gerrit-elasticsearch/src/main/java/com/google/gerrit/elasticsearch/testing/ElasticTestUtils.java b/gerrit-elasticsearch/src/main/java/com/google/gerrit/elasticsearch/testing/ElasticTestUtils.java index 51abf0a225..f5d2331364 100644 --- a/gerrit-elasticsearch/src/main/java/com/google/gerrit/elasticsearch/testing/ElasticTestUtils.java +++ b/gerrit-elasticsearch/src/main/java/com/google/gerrit/elasticsearch/testing/ElasticTestUtils.java @@ -14,91 +14,31 @@ package com.google.gerrit.elasticsearch.testing; -import static com.google.common.truth.Truth.assertThat; - -import com.google.common.base.Strings; -import com.google.common.io.Files; import com.google.gerrit.server.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; } } - public 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); - } - - public 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)); - } - - public static class NodeInfo { - String httpAddress; - } - - public static class Info { - Map nodes; + config.setString("index", null, "maxLimit", "10000"); } public static void createAllIndexes(Injector injector) throws IOException { @@ -109,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 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 } diff --git a/gerrit-elasticsearch/src/test/java/com/google/gerrit/elasticsearch/ElasticQueryAccountsTest.java b/gerrit-elasticsearch/src/test/java/com/google/gerrit/elasticsearch/ElasticQueryAccountsTest.java index 17ff61cdfc..6e02549f7e 100644 --- a/gerrit-elasticsearch/src/test/java/com/google/gerrit/elasticsearch/ElasticQueryAccountsTest.java +++ b/gerrit-elasticsearch/src/test/java/com/google/gerrit/elasticsearch/ElasticQueryAccountsTest.java @@ -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(); } } diff --git a/gerrit-elasticsearch/src/test/java/com/google/gerrit/elasticsearch/ElasticQueryChangesTest.java b/gerrit-elasticsearch/src/test/java/com/google/gerrit/elasticsearch/ElasticQueryChangesTest.java index 3c7ccceaa6..d607cf79d6 100644 --- a/gerrit-elasticsearch/src/test/java/com/google/gerrit/elasticsearch/ElasticQueryChangesTest.java +++ b/gerrit-elasticsearch/src/test/java/com/google/gerrit/elasticsearch/ElasticQueryChangesTest.java @@ -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(); } } diff --git a/gerrit-elasticsearch/src/test/java/com/google/gerrit/elasticsearch/ElasticQueryGroupsTest.java b/gerrit-elasticsearch/src/test/java/com/google/gerrit/elasticsearch/ElasticQueryGroupsTest.java index ed25a9a227..c476a3795f 100644 --- a/gerrit-elasticsearch/src/test/java/com/google/gerrit/elasticsearch/ElasticQueryGroupsTest.java +++ b/gerrit-elasticsearch/src/test/java/com/google/gerrit/elasticsearch/ElasticQueryGroupsTest.java @@ -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(); } } diff --git a/lib/LICENSE-testcontainers b/lib/LICENSE-testcontainers new file mode 100644 index 0000000000..5d60e930d3 --- /dev/null +++ b/lib/LICENSE-testcontainers @@ -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. + diff --git a/lib/elasticsearch/BUILD b/lib/elasticsearch/BUILD deleted file mode 100644 index 8cef95d31d..0000000000 --- a/lib/elasticsearch/BUILD +++ /dev/null @@ -1,59 +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", - ":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 = "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"], -) diff --git a/lib/log/BUILD b/lib/log/BUILD index af83d19f53..8ca87e7538 100644 --- a/lib/log/BUILD +++ b/lib/log/BUILD @@ -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"], diff --git a/lib/lucene/BUILD b/lib/lucene/BUILD index 6590af4a46..5c8982ab39 100644 --- a/lib/lucene/BUILD +++ b/lib/lucene/BUILD @@ -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"], -) diff --git a/lib/testcontainers/BUILD b/lib/testcontainers/BUILD new file mode 100644 index 0000000000..e6ec04f5cf --- /dev/null +++ b/lib/testcontainers/BUILD @@ -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", + ], +)