Merge branch 'stable-2.16' into stable-3.0

* stable-2.16:
  Remove support for discontinued Elasticsearch version 5.6

Change-Id: I165b4d4fc9d3589ba03121bb9c25b5ff60459124
This commit is contained in:
David Pursehouse
2020-04-06 20:30:53 +09:00
21 changed files with 29 additions and 399 deletions

View File

@@ -2965,11 +2965,9 @@ WARNING: Support for Elasticsearch is still experimental and is not recommended
for production use. For compatibility information, please refer to the for production use. For compatibility information, please refer to the
link:https://www.gerritcodereview.com/elasticsearch.html[project homepage]. link:https://www.gerritcodereview.com/elasticsearch.html[project homepage].
When using Elasticsearch version 5.6, the open and closed changes are In Elasticsearch version 6.2 or later, the open and closed changes are merged
indexed in a single index, separated into types `open_changes` and `closed_changes` into the default `_doc` type. The latter is also used for the accounts and groups
respectively. When using version 6.2 or later, the open and closed changes are indices starting with Elasticsearch 6.2.
merged into the default `_doc` type. The latter is also used for the accounts and
groups indices starting with Elasticsearch 6.2.
Note that when Gerrit is configured to use Elasticsearch, the Elasticsearch Note that when Gerrit is configured to use Elasticsearch, the Elasticsearch
server(s) must be reachable during the site initialization. server(s) must be reachable during the site initialization.

View File

@@ -138,8 +138,7 @@ abstract class AbstractElasticIndex<K, V> implements Index<K, V> {
SitePaths sitePaths, SitePaths sitePaths,
Schema<V> schema, Schema<V> schema,
ElasticRestClientProvider client, ElasticRestClientProvider client,
String indexName, String indexName) {
String indexType) {
this.config = config; this.config = config;
this.sitePaths = sitePaths; this.sitePaths = sitePaths;
this.schema = schema; this.schema = schema;
@@ -148,16 +147,7 @@ abstract class AbstractElasticIndex<K, V> implements Index<K, V> {
this.indexName = config.getIndexName(indexName, schema.getVersion()); this.indexName = config.getIndexName(indexName, schema.getVersion());
this.indexNameRaw = indexName; this.indexNameRaw = indexName;
this.client = client; this.client = client;
this.type = client.adapter().getType(indexType); this.type = client.adapter().getType();
}
AbstractElasticIndex(
ElasticConfiguration cfg,
SitePaths sitePaths,
Schema<V> schema,
ElasticRestClientProvider client,
String indexName) {
this(cfg, sitePaths, schema, client, indexName, indexName);
} }
@Override @Override
@@ -223,8 +213,8 @@ abstract class AbstractElasticIndex<K, V> implements Index<K, V> {
protected abstract String getId(V v); protected abstract String getId(V v);
protected String getMappingsForSingleType(String candidateType, MappingProperties properties) { protected String getMappingsForSingleType(MappingProperties properties) {
return getMappingsFor(client.adapter().getType(candidateType), properties); return getMappingsFor(client.adapter().getType(), properties);
} }
protected String getMappingsFor(String type, MappingProperties properties) { protected String getMappingsFor(String type, MappingProperties properties) {
@@ -240,8 +230,8 @@ abstract class AbstractElasticIndex<K, V> implements Index<K, V> {
return gson.toJson(mappings); return gson.toJson(mappings);
} }
protected String delete(String type, K id) { protected String getDeleteRequest(K id) {
return new DeleteRequest(id.toString(), indexName, type, client.adapter()).toString(); return new DeleteRequest(id.toString(), indexName).toString();
} }
protected abstract V fromDocument(JsonObject doc, Set<String> fields); protected abstract V fromDocument(JsonObject doc, Set<String> fields);

View File

@@ -74,9 +74,7 @@ public class ElasticAccountIndex extends AbstractElasticIndex<Account.Id, Accoun
@Override @Override
public void replace(AccountState as) { public void replace(AccountState as) {
BulkRequest bulk = BulkRequest bulk = new IndexRequest(getId(as), indexName).add(new UpdateRequest<>(schema, as));
new IndexRequest(getId(as), indexName, type, client.adapter())
.add(new UpdateRequest<>(schema, as));
String uri = getURI(type, BULK); String uri = getURI(type, BULK);
Response response = postRequest(uri, bulk, getRefreshParam()); Response response = postRequest(uri, bulk, getRefreshParam());
@@ -98,12 +96,12 @@ public class ElasticAccountIndex extends AbstractElasticIndex<Account.Id, Accoun
@Override @Override
protected String getDeleteActions(Account.Id a) { protected String getDeleteActions(Account.Id a) {
return delete(type, a); return getDeleteRequest(a);
} }
@Override @Override
protected String getMappings() { protected String getMappings() {
return getMappingsForSingleType(ACCOUNTS, mapping.accounts); return getMappingsForSingleType(mapping.accounts);
} }
@Override @Override

View File

@@ -21,7 +21,6 @@ import static java.util.Objects.requireNonNull;
import com.google.common.collect.FluentIterable; import com.google.common.collect.FluentIterable;
import com.google.common.collect.ImmutableListMultimap; import com.google.common.collect.ImmutableListMultimap;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;
import com.google.common.collect.ListMultimap; import com.google.common.collect.ListMultimap;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
@@ -29,7 +28,6 @@ import com.google.common.collect.MultimapBuilder;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
import com.google.gerrit.elasticsearch.ElasticMapping.MappingProperties; import com.google.gerrit.elasticsearch.ElasticMapping.MappingProperties;
import com.google.gerrit.elasticsearch.bulk.BulkRequest; import com.google.gerrit.elasticsearch.bulk.BulkRequest;
import com.google.gerrit.elasticsearch.bulk.DeleteRequest;
import com.google.gerrit.elasticsearch.bulk.IndexRequest; import com.google.gerrit.elasticsearch.bulk.IndexRequest;
import com.google.gerrit.elasticsearch.bulk.UpdateRequest; import com.google.gerrit.elasticsearch.bulk.UpdateRequest;
import com.google.gerrit.exceptions.StorageException; import com.google.gerrit.exceptions.StorageException;
@@ -105,24 +103,7 @@ class ElasticChangeIndex extends AbstractElasticIndex<Change.Id, ChangeData>
@Override @Override
public void replace(ChangeData cd) { public void replace(ChangeData cd) {
String deleteIndex; BulkRequest bulk = new IndexRequest(getId(cd), indexName).add(new UpdateRequest<>(schema, cd));
String insertIndex;
if (cd.change().isNew()) {
insertIndex = OPEN_CHANGES;
deleteIndex = CLOSED_CHANGES;
} else {
insertIndex = CLOSED_CHANGES;
deleteIndex = OPEN_CHANGES;
}
ElasticQueryAdapter adapter = client.adapter();
BulkRequest bulk =
new IndexRequest(getId(cd), indexName, adapter.getType(insertIndex), adapter)
.add(new UpdateRequest<>(schema, cd));
if (adapter.deleteToReplace()) {
bulk.add(new DeleteRequest(cd.getId().toString(), indexName, deleteIndex, adapter));
}
String uri = getURI(type, BULK); String uri = getURI(type, BULK);
Response response = postRequest(uri, bulk, getRefreshParam()); Response response = postRequest(uri, bulk, getRefreshParam());
@@ -175,18 +156,12 @@ class ElasticChangeIndex extends AbstractElasticIndex<Change.Id, ChangeData>
@Override @Override
protected String getDeleteActions(Change.Id c) { protected String getDeleteActions(Change.Id c) {
if (!client.adapter().useV5Type()) { return getDeleteRequest(c);
return delete(client.adapter().getType(), c);
}
return delete(OPEN_CHANGES, c) + delete(CLOSED_CHANGES, c);
} }
@Override @Override
protected String getMappings() { protected String getMappings() {
if (!client.adapter().useV5Type()) { return getMappingsFor(client.adapter().getType(), mapping.changes);
return getMappingsFor(client.adapter().getType(), mapping.changes);
}
return gson.toJson(ImmutableMap.of(MAPPINGS, mapping));
} }
@Override @Override

View File

@@ -73,8 +73,7 @@ public class ElasticGroupIndex extends AbstractElasticIndex<AccountGroup.UUID, I
@Override @Override
public void replace(InternalGroup group) { public void replace(InternalGroup group) {
BulkRequest bulk = BulkRequest bulk =
new IndexRequest(getId(group), indexName, type, client.adapter()) new IndexRequest(getId(group), indexName).add(new UpdateRequest<>(schema, group));
.add(new UpdateRequest<>(schema, group));
String uri = getURI(type, BULK); String uri = getURI(type, BULK);
Response response = postRequest(uri, bulk, getRefreshParam()); Response response = postRequest(uri, bulk, getRefreshParam());
@@ -96,12 +95,12 @@ public class ElasticGroupIndex extends AbstractElasticIndex<AccountGroup.UUID, I
@Override @Override
protected String getDeleteActions(AccountGroup.UUID g) { protected String getDeleteActions(AccountGroup.UUID g) {
return delete(type, g); return getDeleteRequest(g);
} }
@Override @Override
protected String getMappings() { protected String getMappings() {
return getMappingsForSingleType(GROUPS, mapping.groups); return getMappingsForSingleType(mapping.groups);
} }
@Override @Override

View File

@@ -73,7 +73,7 @@ public class ElasticProjectIndex extends AbstractElasticIndex<Project.NameKey, P
@Override @Override
public void replace(ProjectData projectState) { public void replace(ProjectData projectState) {
BulkRequest bulk = BulkRequest bulk =
new IndexRequest(projectState.getProject().getName(), indexName, type, client.adapter()) new IndexRequest(projectState.getProject().getName(), indexName)
.add(new UpdateRequest<>(schema, projectState)); .add(new UpdateRequest<>(schema, projectState));
String uri = getURI(type, BULK); String uri = getURI(type, BULK);
@@ -96,12 +96,12 @@ public class ElasticProjectIndex extends AbstractElasticIndex<Project.NameKey, P
@Override @Override
protected String getDeleteActions(Project.NameKey nameKey) { protected String getDeleteActions(Project.NameKey nameKey) {
return delete(type, nameKey); return getDeleteRequest(nameKey);
} }
@Override @Override
protected String getMappings() { protected String getMappings() {
return getMappingsForSingleType(PROJECTS, mapping.projects); return getMappingsForSingleType(mapping.projects);
} }
@Override @Override

View File

@@ -16,15 +16,12 @@ package com.google.gerrit.elasticsearch;
import static com.google.gerrit.elasticsearch.ElasticVersion.V6_7; import static com.google.gerrit.elasticsearch.ElasticVersion.V6_7;
import com.google.gson.JsonObject;
public class ElasticQueryAdapter { public class ElasticQueryAdapter {
static final String V6_TYPE = "_doc"; static final String V6_TYPE = "_doc";
private static final String INCLUDE_TYPE = "include_type_name=true"; private static final String INCLUDE_TYPE = "include_type_name=true";
private static final String INDICES = "?allow_no_indices=false"; private static final String INDICES = "?allow_no_indices=false";
private final boolean useV5Type;
private final boolean useV6Type; private final boolean useV6Type;
private final boolean omitType; private final boolean omitType;
private final int defaultNumberOfShards; private final int defaultNumberOfShards;
@@ -39,7 +36,6 @@ public class ElasticQueryAdapter {
private final String includeTypeNameParam; private final String includeTypeNameParam;
ElasticQueryAdapter(ElasticVersion version) { ElasticQueryAdapter(ElasticVersion version) {
this.useV5Type = !version.isV6OrLater();
this.useV6Type = version.isV6(); this.useV6Type = version.isV6();
this.omitType = version.isV7OrLater(); this.omitType = version.isV7OrLater();
this.defaultNumberOfShards = version.isV7OrLater() ? 1 : 5; this.defaultNumberOfShards = version.isV7OrLater() ? 1 : 5;
@@ -54,12 +50,6 @@ public class ElasticQueryAdapter {
this.includeTypeNameParam = version.isAtLeastMinorVersion(V6_7) ? "?" + INCLUDE_TYPE : ""; this.includeTypeNameParam = version.isAtLeastMinorVersion(V6_7) ? "?" + INCLUDE_TYPE : "";
} }
public void setType(JsonObject properties, String type) {
if (useV5Type) {
properties.addProperty("_type", type);
}
}
public String searchFilteringName() { public String searchFilteringName() {
return searchFilteringName; return searchFilteringName;
} }
@@ -84,14 +74,6 @@ public class ElasticQueryAdapter {
return rawFieldsKey; return rawFieldsKey;
} }
boolean deleteToReplace() {
return useV5Type;
}
boolean useV5Type() {
return useV5Type;
}
boolean useV6Type() { boolean useV6Type() {
return useV6Type; return useV6Type;
} }
@@ -105,14 +87,7 @@ public class ElasticQueryAdapter {
} }
String getType() { String getType() {
return getType(""); return useV6Type() ? V6_TYPE : "";
}
String getType(String type) {
if (useV6Type()) {
return V6_TYPE;
}
return useV5Type() ? type : "";
} }
String getVersionDiscoveryUrl(String name) { String getVersionDiscoveryUrl(String name) {

View File

@@ -18,7 +18,6 @@ import com.google.common.base.Joiner;
import java.util.regex.Pattern; import java.util.regex.Pattern;
public enum ElasticVersion { public enum ElasticVersion {
V5_6("5.6.*"),
V6_2("6.2.*"), V6_2("6.2.*"),
V6_3("6.3.*"), V6_3("6.3.*"),
V6_4("6.4.*"), V6_4("6.4.*"),

View File

@@ -14,7 +14,6 @@
package com.google.gerrit.elasticsearch.bulk; package com.google.gerrit.elasticsearch.bulk;
import com.google.gerrit.elasticsearch.ElasticQueryAdapter;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
abstract class ActionRequest extends BulkRequest { abstract class ActionRequest extends BulkRequest {
@@ -22,16 +21,11 @@ abstract class ActionRequest extends BulkRequest {
private final String action; private final String action;
private final String id; private final String id;
private final String index; private final String index;
private final String type;
private final ElasticQueryAdapter adapter;
protected ActionRequest( protected ActionRequest(String action, String id, String index) {
String action, String id, String index, String type, ElasticQueryAdapter adapter) {
this.action = action; this.action = action;
this.id = id; this.id = id;
this.index = index; this.index = index;
this.type = type;
this.adapter = adapter;
} }
@Override @Override
@@ -39,7 +33,6 @@ abstract class ActionRequest extends BulkRequest {
JsonObject properties = new JsonObject(); JsonObject properties = new JsonObject();
properties.addProperty("_id", id); properties.addProperty("_id", id);
properties.addProperty("_index", index); properties.addProperty("_index", index);
adapter.setType(properties, type);
JsonObject jsonAction = new JsonObject(); JsonObject jsonAction = new JsonObject();
jsonAction.add(action, properties); jsonAction.add(action, properties);

View File

@@ -14,11 +14,9 @@
package com.google.gerrit.elasticsearch.bulk; package com.google.gerrit.elasticsearch.bulk;
import com.google.gerrit.elasticsearch.ElasticQueryAdapter;
public class DeleteRequest extends ActionRequest { public class DeleteRequest extends ActionRequest {
public DeleteRequest(String id, String index, String type, ElasticQueryAdapter adapter) { public DeleteRequest(String id, String index) {
super("delete", id, index, type, adapter); super("delete", id, index);
} }
} }

View File

@@ -14,11 +14,9 @@
package com.google.gerrit.elasticsearch.bulk; package com.google.gerrit.elasticsearch.bulk;
import com.google.gerrit.elasticsearch.ElasticQueryAdapter;
public class IndexRequest extends ActionRequest { public class IndexRequest extends ActionRequest {
public IndexRequest(String id, String index, String type, ElasticQueryAdapter adapter) { public IndexRequest(String id, String index) {
super("index", id, index, type, adapter); super("index", id, index);
} }
} }

View File

@@ -26,11 +26,6 @@ import org.junit.Before;
public class ElasticReindexIT extends AbstractReindexTests { public class ElasticReindexIT extends AbstractReindexTests {
@ConfigSuite.Default @ConfigSuite.Default
public static Config elasticsearchV5() {
return getConfig(ElasticVersion.V5_6);
}
@ConfigSuite.Config
public static Config elasticsearchV6() { public static Config elasticsearchV6() {
return getConfig(ElasticVersion.V6_8); return getConfig(ElasticVersion.V6_8);
} }

View File

@@ -25,11 +25,6 @@ import org.eclipse.jgit.lib.Config;
public class ElasticIndexIT extends AbstractIndexTests { public class ElasticIndexIT extends AbstractIndexTests {
@ConfigSuite.Default @ConfigSuite.Default
public static Config elasticsearchV5() {
return getConfig(ElasticVersion.V5_6);
}
@ConfigSuite.Config
public static Config elasticsearchV6() { public static Config elasticsearchV6() {
return getConfig(ElasticVersion.V6_8); return getConfig(ElasticVersion.V6_8);
} }

View File

@@ -48,8 +48,6 @@ TYPES = [
SUFFIX = "sTest.java" SUFFIX = "sTest.java"
ELASTICSEARCH_TESTS_V5 = {i: "ElasticV5Query" + i.capitalize() + SUFFIX for i in TYPES}
ELASTICSEARCH_TESTS_V6 = {i: "ElasticV6Query" + i.capitalize() + SUFFIX for i in TYPES} ELASTICSEARCH_TESTS_V6 = {i: "ElasticV6Query" + i.capitalize() + SUFFIX for i in TYPES}
ELASTICSEARCH_TESTS_V7 = {i: "ElasticV7Query" + i.capitalize() + SUFFIX for i in TYPES} ELASTICSEARCH_TESTS_V7 = {i: "ElasticV7Query" + i.capitalize() + SUFFIX for i in TYPES}
@@ -60,14 +58,6 @@ ELASTICSEARCH_TAGS = [
"exclusive", "exclusive",
] ]
[junit_tests(
name = "elasticsearch_query_%ss_test_V5" % name,
size = "large",
srcs = [src],
tags = ELASTICSEARCH_TAGS,
deps = ELASTICSEARCH_DEPS + [QUERY_TESTS_DEP % name],
) for name, src in ELASTICSEARCH_TESTS_V5.items()]
[junit_tests( [junit_tests(
name = "elasticsearch_query_%ss_test_V6" % name, name = "elasticsearch_query_%ss_test_V6" % name,
size = "large", size = "large",

View File

@@ -38,8 +38,6 @@ public class ElasticContainer extends ElasticsearchContainer {
private static String getImageName(ElasticVersion version) { private static String getImageName(ElasticVersion version) {
switch (version) { switch (version) {
case V5_6:
return "blacktop/elasticsearch:5.6.16";
case V6_2: case V6_2:
return "blacktop/elasticsearch:6.2.4"; return "blacktop/elasticsearch:6.2.4";
case V6_3: case V6_3:

View File

@@ -24,22 +24,13 @@ import java.util.UUID;
import org.eclipse.jgit.lib.Config; import org.eclipse.jgit.lib.Config;
public final class ElasticTestUtils { public final class ElasticTestUtils {
public static void configure( public static void configure(Config config, ElasticContainer container, String prefix) {
Config config, ElasticContainer container, String prefix, ElasticVersion version) {
String hostname = container.getHttpHost().getHostName(); String hostname = container.getHttpHost().getHostName();
int port = container.getHttpHost().getPort(); int port = container.getHttpHost().getPort();
config.setEnum("index", null, "type", IndexType.ELASTICSEARCH); config.setEnum("index", null, "type", IndexType.ELASTICSEARCH);
config.setString("elasticsearch", null, "server", "http://" + hostname + ":" + port); config.setString("elasticsearch", null, "server", "http://" + hostname + ":" + port);
config.setString("elasticsearch", null, "prefix", prefix); config.setString("elasticsearch", null, "prefix", prefix);
config.setInt("index", null, "maxLimit", 10000); config.setInt("index", null, "maxLimit", 10000);
String password = version == ElasticVersion.V5_6 ? "changeme" : null;
if (password != null) {
config.setString("elasticsearch", null, "password", password);
}
}
public static void configure(Config config, ElasticContainer container, String prefix) {
configure(config, container, prefix, null);
} }
public static void createAllIndexes(Injector injector) { public static void createAllIndexes(Injector injector) {
@@ -54,7 +45,7 @@ public final class ElasticTestUtils {
ElasticContainer container = ElasticContainer.createAndStart(version); ElasticContainer container = ElasticContainer.createAndStart(version);
String indicesPrefix = UUID.randomUUID().toString(); String indicesPrefix = UUID.randomUUID().toString();
Config cfg = new Config(); Config cfg = new Config();
configure(cfg, container, indicesPrefix, version); configure(cfg, container, indicesPrefix);
return cfg; return cfg;
} }

View File

@@ -1,64 +0,0 @@
// 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.server.query.account.AbstractQueryAccountsTest;
import com.google.gerrit.testing.ConfigSuite;
import com.google.gerrit.testing.InMemoryModule;
import com.google.gerrit.testing.IndexConfig;
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 ElasticV5QueryAccountsTest extends AbstractQueryAccountsTest {
@ConfigSuite.Default
public static Config defaultConfig() {
return IndexConfig.createForElasticsearch();
}
private static ElasticContainer container;
@BeforeClass
public static void startIndexService() {
if (container == null) {
// Only start Elasticsearch once
container = ElasticContainer.createAndStart(ElasticVersion.V5_6);
}
}
@AfterClass
public static void stopElasticsearchServer() {
if (container != null) {
container.stop();
}
}
@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 = getSanitizedMethodName();
ElasticTestUtils.configure(elasticsearchConfig, container, indicesPrefix, ElasticVersion.V5_6);
return Guice.createInjector(new InMemoryModule(elasticsearchConfig));
}
}

View File

@@ -1,64 +0,0 @@
// 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.server.query.change.AbstractQueryChangesTest;
import com.google.gerrit.testing.ConfigSuite;
import com.google.gerrit.testing.InMemoryModule;
import com.google.gerrit.testing.IndexConfig;
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 ElasticV5QueryChangesTest extends AbstractQueryChangesTest {
@ConfigSuite.Default
public static Config defaultConfig() {
return IndexConfig.createForElasticsearch();
}
private static ElasticContainer container;
@BeforeClass
public static void startIndexService() {
if (container == null) {
// Only start Elasticsearch once
container = ElasticContainer.createAndStart(ElasticVersion.V5_6);
}
}
@AfterClass
public static void stopElasticsearchServer() {
if (container != null) {
container.stop();
}
}
@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 = getSanitizedMethodName();
ElasticTestUtils.configure(elasticsearchConfig, container, indicesPrefix, ElasticVersion.V5_6);
return Guice.createInjector(new InMemoryModule(elasticsearchConfig));
}
}

View File

@@ -1,64 +0,0 @@
// 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.server.query.group.AbstractQueryGroupsTest;
import com.google.gerrit.testing.ConfigSuite;
import com.google.gerrit.testing.InMemoryModule;
import com.google.gerrit.testing.IndexConfig;
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 ElasticV5QueryGroupsTest extends AbstractQueryGroupsTest {
@ConfigSuite.Default
public static Config defaultConfig() {
return IndexConfig.createForElasticsearch();
}
private static ElasticContainer container;
@BeforeClass
public static void startIndexService() {
if (container == null) {
// Only start Elasticsearch once
container = ElasticContainer.createAndStart(ElasticVersion.V5_6);
}
}
@AfterClass
public static void stopElasticsearchServer() {
if (container != null) {
container.stop();
}
}
@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 = getSanitizedMethodName();
ElasticTestUtils.configure(elasticsearchConfig, container, indicesPrefix, ElasticVersion.V5_6);
return Guice.createInjector(new InMemoryModule(elasticsearchConfig));
}
}

View File

@@ -1,64 +0,0 @@
// 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.server.query.project.AbstractQueryProjectsTest;
import com.google.gerrit.testing.ConfigSuite;
import com.google.gerrit.testing.InMemoryModule;
import com.google.gerrit.testing.IndexConfig;
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 ElasticV5QueryProjectsTest extends AbstractQueryProjectsTest {
@ConfigSuite.Default
public static Config defaultConfig() {
return IndexConfig.createForElasticsearch();
}
private static ElasticContainer container;
@BeforeClass
public static void startIndexService() {
if (container == null) {
// Only start Elasticsearch once
container = ElasticContainer.createAndStart(ElasticVersion.V5_6);
}
}
@AfterClass
public static void stopElasticsearchServer() {
if (container != null) {
container.stop();
}
}
@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 = getSanitizedMethodName();
ElasticTestUtils.configure(elasticsearchConfig, container, indicesPrefix, ElasticVersion.V5_6);
return Guice.createInjector(new InMemoryModule(elasticsearchConfig));
}
}

View File

@@ -22,9 +22,6 @@ import org.junit.Test;
public class ElasticVersionTest extends GerritBaseTests { public class ElasticVersionTest extends GerritBaseTests {
@Test @Test
public void supportedVersion() throws Exception { public void supportedVersion() throws Exception {
assertThat(ElasticVersion.forVersion("5.6.0")).isEqualTo(ElasticVersion.V5_6);
assertThat(ElasticVersion.forVersion("5.6.11")).isEqualTo(ElasticVersion.V5_6);
assertThat(ElasticVersion.forVersion("6.2.0")).isEqualTo(ElasticVersion.V6_2); assertThat(ElasticVersion.forVersion("6.2.0")).isEqualTo(ElasticVersion.V6_2);
assertThat(ElasticVersion.forVersion("6.2.4")).isEqualTo(ElasticVersion.V6_2); assertThat(ElasticVersion.forVersion("6.2.4")).isEqualTo(ElasticVersion.V6_2);
@@ -78,7 +75,6 @@ public class ElasticVersionTest extends GerritBaseTests {
@Test @Test
public void atLeastMinorVersion() throws Exception { public void atLeastMinorVersion() throws Exception {
assertThat(ElasticVersion.V5_6.isAtLeastMinorVersion(ElasticVersion.V6_7)).isFalse();
assertThat(ElasticVersion.V6_2.isAtLeastMinorVersion(ElasticVersion.V6_7)).isFalse(); assertThat(ElasticVersion.V6_2.isAtLeastMinorVersion(ElasticVersion.V6_7)).isFalse();
assertThat(ElasticVersion.V6_3.isAtLeastMinorVersion(ElasticVersion.V6_7)).isFalse(); assertThat(ElasticVersion.V6_3.isAtLeastMinorVersion(ElasticVersion.V6_7)).isFalse();
assertThat(ElasticVersion.V6_4.isAtLeastMinorVersion(ElasticVersion.V6_7)).isFalse(); assertThat(ElasticVersion.V6_4.isAtLeastMinorVersion(ElasticVersion.V6_7)).isFalse();
@@ -97,7 +93,6 @@ public class ElasticVersionTest extends GerritBaseTests {
@Test @Test
public void version6OrLater() throws Exception { public void version6OrLater() throws Exception {
assertThat(ElasticVersion.V5_6.isV6OrLater()).isFalse();
assertThat(ElasticVersion.V6_2.isV6OrLater()).isTrue(); assertThat(ElasticVersion.V6_2.isV6OrLater()).isTrue();
assertThat(ElasticVersion.V6_3.isV6OrLater()).isTrue(); assertThat(ElasticVersion.V6_3.isV6OrLater()).isTrue();
assertThat(ElasticVersion.V6_4.isV6OrLater()).isTrue(); assertThat(ElasticVersion.V6_4.isV6OrLater()).isTrue();
@@ -116,7 +111,6 @@ public class ElasticVersionTest extends GerritBaseTests {
@Test @Test
public void version7OrLater() throws Exception { public void version7OrLater() throws Exception {
assertThat(ElasticVersion.V5_6.isV7OrLater()).isFalse();
assertThat(ElasticVersion.V6_2.isV7OrLater()).isFalse(); assertThat(ElasticVersion.V6_2.isV7OrLater()).isFalse();
assertThat(ElasticVersion.V6_3.isV7OrLater()).isFalse(); assertThat(ElasticVersion.V6_3.isV7OrLater()).isFalse();
assertThat(ElasticVersion.V6_4.isV7OrLater()).isFalse(); assertThat(ElasticVersion.V6_4.isV7OrLater()).isFalse();