diff --git a/Documentation/dev-bazel.txt b/Documentation/dev-bazel.txt index 341094df18..6d5c75aa37 100644 --- a/Documentation/dev-bazel.txt +++ b/Documentation/dev-bazel.txt @@ -269,6 +269,15 @@ The following values are currently supported for the group name: * server * ssh +[[elasticsearch]] +=== Elasticsearch + +Successfully running the elasticsearch tests may require setting the local +link:https://www.elastic.co/guide/en/elasticsearch/reference/current/vm-max-map-count.html[virtual memory]. + +Bazel link:https://github.com/bazelbuild/bazel/issues/3476[does not currently make container failures visible], +if any. + == Dependencies Dependency JARs are normally downloaded as needed, but you can 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 index eacc43eaa4..003356671b 100644 --- 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 @@ -48,7 +48,7 @@ public class ElasticContainer> extends Gener case V5_6: return "elasticsearch:5.6.9-alpine"; case V6_2: - return "docker.elastic.co/elasticsearch/elasticsearch:6.2.4"; + return "docker.elastic.co/elasticsearch/elasticsearch-oss:6.2.4"; } throw new IllegalStateException("No tests for version: " + version.name()); } diff --git a/gerrit-elasticsearch/src/test/java/com/google/gerrit/elasticsearch/ElasticV6QueryAccountsTest.java b/gerrit-elasticsearch/src/test/java/com/google/gerrit/elasticsearch/ElasticV6QueryAccountsTest.java new file mode 100644 index 0000000000..f973e36755 --- /dev/null +++ b/gerrit-elasticsearch/src/test/java/com/google/gerrit/elasticsearch/ElasticV6QueryAccountsTest.java @@ -0,0 +1,68 @@ +// 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.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 org.eclipse.jgit.lib.Config; +import org.junit.AfterClass; +import org.junit.BeforeClass; + +public class ElasticV6QueryAccountsTest extends AbstractQueryAccountsTest { + private static ElasticNodeInfo nodeInfo; + private static ElasticContainer container; + + @BeforeClass + public static void startIndexService() { + if (nodeInfo != null) { + // do not start Elasticsearch twice + return; + } + + container = ElasticContainer.createAndStart(ElasticVersion.V6_2); + nodeInfo = new ElasticNodeInfo(container.getHttpHost().getPort()); + } + + @AfterClass + public static void stopElasticsearchServer() { + if (container != null) { + container.stop(); + } + } + + private String testName() { + return testName.getMethodName().toLowerCase() + "_"; + } + + @Override + protected void initAfterLifecycleStart() throws Exception { + super.initAfterLifecycleStart(); + ElasticTestUtils.createAllIndexes(injector); + } + + @Override + protected Injector createInjector() { + Config elasticsearchConfig = new Config(config); + InMemoryModule.setDefaults(elasticsearchConfig); + String indicesPrefix = testName(); + ElasticTestUtils.configure(elasticsearchConfig, nodeInfo.port, indicesPrefix); + return Guice.createInjector(new InMemoryModule(elasticsearchConfig, notesMigration)); + } +} diff --git a/gerrit-elasticsearch/src/test/java/com/google/gerrit/elasticsearch/ElasticV6QueryChangesTest.java b/gerrit-elasticsearch/src/test/java/com/google/gerrit/elasticsearch/ElasticV6QueryChangesTest.java new file mode 100644 index 0000000000..5e0fd7e003 --- /dev/null +++ b/gerrit-elasticsearch/src/test/java/com/google/gerrit/elasticsearch/ElasticV6QueryChangesTest.java @@ -0,0 +1,69 @@ +// 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.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; +import com.google.gerrit.testutil.InMemoryModule; +import com.google.inject.Guice; +import com.google.inject.Injector; +import org.eclipse.jgit.lib.Config; +import org.junit.AfterClass; +import org.junit.BeforeClass; + +public class ElasticV6QueryChangesTest extends AbstractQueryChangesTest { + + private static ElasticNodeInfo nodeInfo; + private static ElasticContainer container; + + @BeforeClass + public static void startIndexService() { + if (nodeInfo != null) { + // do not start Elasticsearch twice + return; + } + + container = ElasticContainer.createAndStart(ElasticVersion.V6_2); + nodeInfo = new ElasticNodeInfo(container.getHttpHost().getPort()); + } + + @AfterClass + public static void stopElasticsearchServer() { + if (container != null) { + container.stop(); + } + } + + private String testName() { + return testName.getMethodName().toLowerCase() + "_"; + } + + @Override + protected void initAfterLifecycleStart() throws Exception { + super.initAfterLifecycleStart(); + ElasticTestUtils.createAllIndexes(injector); + } + + @Override + protected Injector createInjector() { + Config elasticsearchConfig = new Config(config); + InMemoryModule.setDefaults(elasticsearchConfig); + String indicesPrefix = testName(); + ElasticTestUtils.configure(elasticsearchConfig, nodeInfo.port, indicesPrefix); + return Guice.createInjector(new InMemoryModule(elasticsearchConfig, notesMigration)); + } +} diff --git a/gerrit-elasticsearch/src/test/java/com/google/gerrit/elasticsearch/ElasticV6QueryGroupsTest.java b/gerrit-elasticsearch/src/test/java/com/google/gerrit/elasticsearch/ElasticV6QueryGroupsTest.java new file mode 100644 index 0000000000..abb715ca7b --- /dev/null +++ b/gerrit-elasticsearch/src/test/java/com/google/gerrit/elasticsearch/ElasticV6QueryGroupsTest.java @@ -0,0 +1,68 @@ +// 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.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 org.eclipse.jgit.lib.Config; +import org.junit.AfterClass; +import org.junit.BeforeClass; + +public class ElasticV6QueryGroupsTest extends AbstractQueryGroupsTest { + private static ElasticNodeInfo nodeInfo; + private static ElasticContainer container; + + @BeforeClass + public static void startIndexService() { + if (nodeInfo != null) { + // do not start Elasticsearch twice + return; + } + + container = ElasticContainer.createAndStart(ElasticVersion.V6_2); + nodeInfo = new ElasticNodeInfo(container.getHttpHost().getPort()); + } + + @AfterClass + public static void stopElasticsearchServer() { + if (container != null) { + container.stop(); + } + } + + private String testName() { + return testName.getMethodName().toLowerCase() + "_"; + } + + @Override + protected void initAfterLifecycleStart() throws Exception { + super.initAfterLifecycleStart(); + ElasticTestUtils.createAllIndexes(injector); + } + + @Override + protected Injector createInjector() { + Config elasticsearchConfig = new Config(config); + InMemoryModule.setDefaults(elasticsearchConfig); + String indicesPrefix = testName(); + ElasticTestUtils.configure(elasticsearchConfig, nodeInfo.port, indicesPrefix); + return Guice.createInjector(new InMemoryModule(elasticsearchConfig, notesMigration)); + } +}