Elasticsearch: Add tests for queries against version 6
Add separate test classes to test queries with Elasticsearch version 6.
The entire test classes are basically copied from the existing ones,
with the only difference being the version passed into the config and
into the container creation. This cannot be achieved using an abstract
class due to the container being created in the @BeforeClass annotated
method which is static and cannot be overridden by a derived class.
The docker image for V6 testing requires this limit [1] to be secured.
The test container otherwise aborts upon running V6 tests, causing an
AssumptionViolatedException, which is currently ignored by Bazel ([2]).
Amend the test execution documentation accordingly.
Replace the V6 image used for testing with the oss one, which has no
X-Pack or security defaults installed; cf. [3]. Without this change,
V6 tests fail upon api usage lacking authorization.
[1] https://www.elastic.co/guide/en/elasticsearch/reference/current/vm-max-map-count.html
[2] https://github.com/bazelbuild/bazel/issues/3476
[3] https://www.elastic.co/guide/en/elasticsearch/reference/current/docker.html
Bug: Issue 9112
Bug: Issue 9212
Change-Id: I11ced5f811cdc078d7feba187086e803326886cb
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 eacc43e..0033566 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 @@
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 0000000..f973e36
--- /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 0000000..5e0fd7e
--- /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 0000000..abb715c
--- /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));
+ }
+}