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:
		@@ -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
 | 
			
		||||
link:https://www.gerritcodereview.com/elasticsearch.html[project homepage].
 | 
			
		||||
 | 
			
		||||
When using Elasticsearch version 5.6, the open and closed changes are
 | 
			
		||||
indexed in a single index, separated into types `open_changes` and `closed_changes`
 | 
			
		||||
respectively. When using version 6.2 or later, the open and closed changes are
 | 
			
		||||
merged into the default `_doc` type. The latter is also used for the accounts and
 | 
			
		||||
groups indices starting with Elasticsearch 6.2.
 | 
			
		||||
In Elasticsearch version 6.2 or later, the open and closed changes are 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
 | 
			
		||||
server(s) must be reachable during the site initialization.
 | 
			
		||||
 
 | 
			
		||||
@@ -138,8 +138,7 @@ abstract class AbstractElasticIndex<K, V> implements Index<K, V> {
 | 
			
		||||
      SitePaths sitePaths,
 | 
			
		||||
      Schema<V> schema,
 | 
			
		||||
      ElasticRestClientProvider client,
 | 
			
		||||
      String indexName,
 | 
			
		||||
      String indexType) {
 | 
			
		||||
      String indexName) {
 | 
			
		||||
    this.config = config;
 | 
			
		||||
    this.sitePaths = sitePaths;
 | 
			
		||||
    this.schema = schema;
 | 
			
		||||
@@ -148,16 +147,7 @@ abstract class AbstractElasticIndex<K, V> implements Index<K, V> {
 | 
			
		||||
    this.indexName = config.getIndexName(indexName, schema.getVersion());
 | 
			
		||||
    this.indexNameRaw = indexName;
 | 
			
		||||
    this.client = client;
 | 
			
		||||
    this.type = client.adapter().getType(indexType);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  AbstractElasticIndex(
 | 
			
		||||
      ElasticConfiguration cfg,
 | 
			
		||||
      SitePaths sitePaths,
 | 
			
		||||
      Schema<V> schema,
 | 
			
		||||
      ElasticRestClientProvider client,
 | 
			
		||||
      String indexName) {
 | 
			
		||||
    this(cfg, sitePaths, schema, client, indexName, indexName);
 | 
			
		||||
    this.type = client.adapter().getType();
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @Override
 | 
			
		||||
@@ -223,8 +213,8 @@ abstract class AbstractElasticIndex<K, V> implements Index<K, V> {
 | 
			
		||||
 | 
			
		||||
  protected abstract String getId(V v);
 | 
			
		||||
 | 
			
		||||
  protected String getMappingsForSingleType(String candidateType, MappingProperties properties) {
 | 
			
		||||
    return getMappingsFor(client.adapter().getType(candidateType), properties);
 | 
			
		||||
  protected String getMappingsForSingleType(MappingProperties properties) {
 | 
			
		||||
    return getMappingsFor(client.adapter().getType(), 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);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  protected String delete(String type, K id) {
 | 
			
		||||
    return new DeleteRequest(id.toString(), indexName, type, client.adapter()).toString();
 | 
			
		||||
  protected String getDeleteRequest(K id) {
 | 
			
		||||
    return new DeleteRequest(id.toString(), indexName).toString();
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  protected abstract V fromDocument(JsonObject doc, Set<String> fields);
 | 
			
		||||
 
 | 
			
		||||
@@ -74,9 +74,7 @@ public class ElasticAccountIndex extends AbstractElasticIndex<Account.Id, Accoun
 | 
			
		||||
 | 
			
		||||
  @Override
 | 
			
		||||
  public void replace(AccountState as) {
 | 
			
		||||
    BulkRequest bulk =
 | 
			
		||||
        new IndexRequest(getId(as), indexName, type, client.adapter())
 | 
			
		||||
            .add(new UpdateRequest<>(schema, as));
 | 
			
		||||
    BulkRequest bulk = new IndexRequest(getId(as), indexName).add(new UpdateRequest<>(schema, as));
 | 
			
		||||
 | 
			
		||||
    String uri = getURI(type, BULK);
 | 
			
		||||
    Response response = postRequest(uri, bulk, getRefreshParam());
 | 
			
		||||
@@ -98,12 +96,12 @@ public class ElasticAccountIndex extends AbstractElasticIndex<Account.Id, Accoun
 | 
			
		||||
 | 
			
		||||
  @Override
 | 
			
		||||
  protected String getDeleteActions(Account.Id a) {
 | 
			
		||||
    return delete(type, a);
 | 
			
		||||
    return getDeleteRequest(a);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @Override
 | 
			
		||||
  protected String getMappings() {
 | 
			
		||||
    return getMappingsForSingleType(ACCOUNTS, mapping.accounts);
 | 
			
		||||
    return getMappingsForSingleType(mapping.accounts);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @Override
 | 
			
		||||
 
 | 
			
		||||
@@ -21,7 +21,6 @@ import static java.util.Objects.requireNonNull;
 | 
			
		||||
 | 
			
		||||
import com.google.common.collect.FluentIterable;
 | 
			
		||||
import com.google.common.collect.ImmutableListMultimap;
 | 
			
		||||
import com.google.common.collect.ImmutableMap;
 | 
			
		||||
import com.google.common.collect.Iterables;
 | 
			
		||||
import com.google.common.collect.ListMultimap;
 | 
			
		||||
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.gerrit.elasticsearch.ElasticMapping.MappingProperties;
 | 
			
		||||
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.UpdateRequest;
 | 
			
		||||
import com.google.gerrit.exceptions.StorageException;
 | 
			
		||||
@@ -105,24 +103,7 @@ class ElasticChangeIndex extends AbstractElasticIndex<Change.Id, ChangeData>
 | 
			
		||||
 | 
			
		||||
  @Override
 | 
			
		||||
  public void replace(ChangeData cd) {
 | 
			
		||||
    String deleteIndex;
 | 
			
		||||
    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));
 | 
			
		||||
    }
 | 
			
		||||
    BulkRequest bulk = new IndexRequest(getId(cd), indexName).add(new UpdateRequest<>(schema, cd));
 | 
			
		||||
 | 
			
		||||
    String uri = getURI(type, BULK);
 | 
			
		||||
    Response response = postRequest(uri, bulk, getRefreshParam());
 | 
			
		||||
@@ -175,18 +156,12 @@ class ElasticChangeIndex extends AbstractElasticIndex<Change.Id, ChangeData>
 | 
			
		||||
 | 
			
		||||
  @Override
 | 
			
		||||
  protected String getDeleteActions(Change.Id c) {
 | 
			
		||||
    if (!client.adapter().useV5Type()) {
 | 
			
		||||
      return delete(client.adapter().getType(), c);
 | 
			
		||||
    }
 | 
			
		||||
    return delete(OPEN_CHANGES, c) + delete(CLOSED_CHANGES, c);
 | 
			
		||||
    return getDeleteRequest(c);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @Override
 | 
			
		||||
  protected String getMappings() {
 | 
			
		||||
    if (!client.adapter().useV5Type()) {
 | 
			
		||||
      return getMappingsFor(client.adapter().getType(), mapping.changes);
 | 
			
		||||
    }
 | 
			
		||||
    return gson.toJson(ImmutableMap.of(MAPPINGS, mapping));
 | 
			
		||||
    return getMappingsFor(client.adapter().getType(), mapping.changes);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @Override
 | 
			
		||||
 
 | 
			
		||||
@@ -73,8 +73,7 @@ public class ElasticGroupIndex extends AbstractElasticIndex<AccountGroup.UUID, I
 | 
			
		||||
  @Override
 | 
			
		||||
  public void replace(InternalGroup group) {
 | 
			
		||||
    BulkRequest bulk =
 | 
			
		||||
        new IndexRequest(getId(group), indexName, type, client.adapter())
 | 
			
		||||
            .add(new UpdateRequest<>(schema, group));
 | 
			
		||||
        new IndexRequest(getId(group), indexName).add(new UpdateRequest<>(schema, group));
 | 
			
		||||
 | 
			
		||||
    String uri = getURI(type, BULK);
 | 
			
		||||
    Response response = postRequest(uri, bulk, getRefreshParam());
 | 
			
		||||
@@ -96,12 +95,12 @@ public class ElasticGroupIndex extends AbstractElasticIndex<AccountGroup.UUID, I
 | 
			
		||||
 | 
			
		||||
  @Override
 | 
			
		||||
  protected String getDeleteActions(AccountGroup.UUID g) {
 | 
			
		||||
    return delete(type, g);
 | 
			
		||||
    return getDeleteRequest(g);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @Override
 | 
			
		||||
  protected String getMappings() {
 | 
			
		||||
    return getMappingsForSingleType(GROUPS, mapping.groups);
 | 
			
		||||
    return getMappingsForSingleType(mapping.groups);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @Override
 | 
			
		||||
 
 | 
			
		||||
@@ -73,7 +73,7 @@ public class ElasticProjectIndex extends AbstractElasticIndex<Project.NameKey, P
 | 
			
		||||
  @Override
 | 
			
		||||
  public void replace(ProjectData projectState) {
 | 
			
		||||
    BulkRequest bulk =
 | 
			
		||||
        new IndexRequest(projectState.getProject().getName(), indexName, type, client.adapter())
 | 
			
		||||
        new IndexRequest(projectState.getProject().getName(), indexName)
 | 
			
		||||
            .add(new UpdateRequest<>(schema, projectState));
 | 
			
		||||
 | 
			
		||||
    String uri = getURI(type, BULK);
 | 
			
		||||
@@ -96,12 +96,12 @@ public class ElasticProjectIndex extends AbstractElasticIndex<Project.NameKey, P
 | 
			
		||||
 | 
			
		||||
  @Override
 | 
			
		||||
  protected String getDeleteActions(Project.NameKey nameKey) {
 | 
			
		||||
    return delete(type, nameKey);
 | 
			
		||||
    return getDeleteRequest(nameKey);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @Override
 | 
			
		||||
  protected String getMappings() {
 | 
			
		||||
    return getMappingsForSingleType(PROJECTS, mapping.projects);
 | 
			
		||||
    return getMappingsForSingleType(mapping.projects);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @Override
 | 
			
		||||
 
 | 
			
		||||
@@ -16,15 +16,12 @@ package com.google.gerrit.elasticsearch;
 | 
			
		||||
 | 
			
		||||
import static com.google.gerrit.elasticsearch.ElasticVersion.V6_7;
 | 
			
		||||
 | 
			
		||||
import com.google.gson.JsonObject;
 | 
			
		||||
 | 
			
		||||
public class ElasticQueryAdapter {
 | 
			
		||||
  static final String V6_TYPE = "_doc";
 | 
			
		||||
 | 
			
		||||
  private static final String INCLUDE_TYPE = "include_type_name=true";
 | 
			
		||||
  private static final String INDICES = "?allow_no_indices=false";
 | 
			
		||||
 | 
			
		||||
  private final boolean useV5Type;
 | 
			
		||||
  private final boolean useV6Type;
 | 
			
		||||
  private final boolean omitType;
 | 
			
		||||
  private final int defaultNumberOfShards;
 | 
			
		||||
@@ -39,7 +36,6 @@ public class ElasticQueryAdapter {
 | 
			
		||||
  private final String includeTypeNameParam;
 | 
			
		||||
 | 
			
		||||
  ElasticQueryAdapter(ElasticVersion version) {
 | 
			
		||||
    this.useV5Type = !version.isV6OrLater();
 | 
			
		||||
    this.useV6Type = version.isV6();
 | 
			
		||||
    this.omitType = version.isV7OrLater();
 | 
			
		||||
    this.defaultNumberOfShards = version.isV7OrLater() ? 1 : 5;
 | 
			
		||||
@@ -54,12 +50,6 @@ public class ElasticQueryAdapter {
 | 
			
		||||
    this.includeTypeNameParam = version.isAtLeastMinorVersion(V6_7) ? "?" + INCLUDE_TYPE : "";
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  public void setType(JsonObject properties, String type) {
 | 
			
		||||
    if (useV5Type) {
 | 
			
		||||
      properties.addProperty("_type", type);
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  public String searchFilteringName() {
 | 
			
		||||
    return searchFilteringName;
 | 
			
		||||
  }
 | 
			
		||||
@@ -84,14 +74,6 @@ public class ElasticQueryAdapter {
 | 
			
		||||
    return rawFieldsKey;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  boolean deleteToReplace() {
 | 
			
		||||
    return useV5Type;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  boolean useV5Type() {
 | 
			
		||||
    return useV5Type;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  boolean useV6Type() {
 | 
			
		||||
    return useV6Type;
 | 
			
		||||
  }
 | 
			
		||||
@@ -105,14 +87,7 @@ public class ElasticQueryAdapter {
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  String getType() {
 | 
			
		||||
    return getType("");
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  String getType(String type) {
 | 
			
		||||
    if (useV6Type()) {
 | 
			
		||||
      return V6_TYPE;
 | 
			
		||||
    }
 | 
			
		||||
    return useV5Type() ? type : "";
 | 
			
		||||
    return useV6Type() ? V6_TYPE : "";
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  String getVersionDiscoveryUrl(String name) {
 | 
			
		||||
 
 | 
			
		||||
@@ -18,7 +18,6 @@ import com.google.common.base.Joiner;
 | 
			
		||||
import java.util.regex.Pattern;
 | 
			
		||||
 | 
			
		||||
public enum ElasticVersion {
 | 
			
		||||
  V5_6("5.6.*"),
 | 
			
		||||
  V6_2("6.2.*"),
 | 
			
		||||
  V6_3("6.3.*"),
 | 
			
		||||
  V6_4("6.4.*"),
 | 
			
		||||
 
 | 
			
		||||
@@ -14,7 +14,6 @@
 | 
			
		||||
 | 
			
		||||
package com.google.gerrit.elasticsearch.bulk;
 | 
			
		||||
 | 
			
		||||
import com.google.gerrit.elasticsearch.ElasticQueryAdapter;
 | 
			
		||||
import com.google.gson.JsonObject;
 | 
			
		||||
 | 
			
		||||
abstract class ActionRequest extends BulkRequest {
 | 
			
		||||
@@ -22,16 +21,11 @@ abstract class ActionRequest extends BulkRequest {
 | 
			
		||||
  private final String action;
 | 
			
		||||
  private final String id;
 | 
			
		||||
  private final String index;
 | 
			
		||||
  private final String type;
 | 
			
		||||
  private final ElasticQueryAdapter adapter;
 | 
			
		||||
 | 
			
		||||
  protected ActionRequest(
 | 
			
		||||
      String action, String id, String index, String type, ElasticQueryAdapter adapter) {
 | 
			
		||||
  protected ActionRequest(String action, String id, String index) {
 | 
			
		||||
    this.action = action;
 | 
			
		||||
    this.id = id;
 | 
			
		||||
    this.index = index;
 | 
			
		||||
    this.type = type;
 | 
			
		||||
    this.adapter = adapter;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @Override
 | 
			
		||||
@@ -39,7 +33,6 @@ abstract class ActionRequest extends BulkRequest {
 | 
			
		||||
    JsonObject properties = new JsonObject();
 | 
			
		||||
    properties.addProperty("_id", id);
 | 
			
		||||
    properties.addProperty("_index", index);
 | 
			
		||||
    adapter.setType(properties, type);
 | 
			
		||||
 | 
			
		||||
    JsonObject jsonAction = new JsonObject();
 | 
			
		||||
    jsonAction.add(action, properties);
 | 
			
		||||
 
 | 
			
		||||
@@ -14,11 +14,9 @@
 | 
			
		||||
 | 
			
		||||
package com.google.gerrit.elasticsearch.bulk;
 | 
			
		||||
 | 
			
		||||
import com.google.gerrit.elasticsearch.ElasticQueryAdapter;
 | 
			
		||||
 | 
			
		||||
public class DeleteRequest extends ActionRequest {
 | 
			
		||||
 | 
			
		||||
  public DeleteRequest(String id, String index, String type, ElasticQueryAdapter adapter) {
 | 
			
		||||
    super("delete", id, index, type, adapter);
 | 
			
		||||
  public DeleteRequest(String id, String index) {
 | 
			
		||||
    super("delete", id, index);
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -14,11 +14,9 @@
 | 
			
		||||
 | 
			
		||||
package com.google.gerrit.elasticsearch.bulk;
 | 
			
		||||
 | 
			
		||||
import com.google.gerrit.elasticsearch.ElasticQueryAdapter;
 | 
			
		||||
 | 
			
		||||
public class IndexRequest extends ActionRequest {
 | 
			
		||||
 | 
			
		||||
  public IndexRequest(String id, String index, String type, ElasticQueryAdapter adapter) {
 | 
			
		||||
    super("index", id, index, type, adapter);
 | 
			
		||||
  public IndexRequest(String id, String index) {
 | 
			
		||||
    super("index", id, index);
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -26,11 +26,6 @@ import org.junit.Before;
 | 
			
		||||
public class ElasticReindexIT extends AbstractReindexTests {
 | 
			
		||||
 | 
			
		||||
  @ConfigSuite.Default
 | 
			
		||||
  public static Config elasticsearchV5() {
 | 
			
		||||
    return getConfig(ElasticVersion.V5_6);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @ConfigSuite.Config
 | 
			
		||||
  public static Config elasticsearchV6() {
 | 
			
		||||
    return getConfig(ElasticVersion.V6_8);
 | 
			
		||||
  }
 | 
			
		||||
 
 | 
			
		||||
@@ -25,11 +25,6 @@ import org.eclipse.jgit.lib.Config;
 | 
			
		||||
public class ElasticIndexIT extends AbstractIndexTests {
 | 
			
		||||
 | 
			
		||||
  @ConfigSuite.Default
 | 
			
		||||
  public static Config elasticsearchV5() {
 | 
			
		||||
    return getConfig(ElasticVersion.V5_6);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @ConfigSuite.Config
 | 
			
		||||
  public static Config elasticsearchV6() {
 | 
			
		||||
    return getConfig(ElasticVersion.V6_8);
 | 
			
		||||
  }
 | 
			
		||||
 
 | 
			
		||||
@@ -48,8 +48,6 @@ TYPES = [
 | 
			
		||||
 | 
			
		||||
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_V7 = {i: "ElasticV7Query" + i.capitalize() + SUFFIX for i in TYPES}
 | 
			
		||||
@@ -60,14 +58,6 @@ ELASTICSEARCH_TAGS = [
 | 
			
		||||
    "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(
 | 
			
		||||
    name = "elasticsearch_query_%ss_test_V6" % name,
 | 
			
		||||
    size = "large",
 | 
			
		||||
 
 | 
			
		||||
@@ -38,8 +38,6 @@ public class ElasticContainer extends ElasticsearchContainer {
 | 
			
		||||
 | 
			
		||||
  private static String getImageName(ElasticVersion version) {
 | 
			
		||||
    switch (version) {
 | 
			
		||||
      case V5_6:
 | 
			
		||||
        return "blacktop/elasticsearch:5.6.16";
 | 
			
		||||
      case V6_2:
 | 
			
		||||
        return "blacktop/elasticsearch:6.2.4";
 | 
			
		||||
      case V6_3:
 | 
			
		||||
 
 | 
			
		||||
@@ -24,22 +24,13 @@ import java.util.UUID;
 | 
			
		||||
import org.eclipse.jgit.lib.Config;
 | 
			
		||||
 | 
			
		||||
public final class ElasticTestUtils {
 | 
			
		||||
  public static void configure(
 | 
			
		||||
      Config config, ElasticContainer container, String prefix, ElasticVersion version) {
 | 
			
		||||
  public static void configure(Config config, ElasticContainer container, String prefix) {
 | 
			
		||||
    String hostname = container.getHttpHost().getHostName();
 | 
			
		||||
    int port = container.getHttpHost().getPort();
 | 
			
		||||
    config.setEnum("index", null, "type", IndexType.ELASTICSEARCH);
 | 
			
		||||
    config.setString("elasticsearch", null, "server", "http://" + hostname + ":" + port);
 | 
			
		||||
    config.setString("elasticsearch", null, "prefix", prefix);
 | 
			
		||||
    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) {
 | 
			
		||||
@@ -54,7 +45,7 @@ public final class ElasticTestUtils {
 | 
			
		||||
    ElasticContainer container = ElasticContainer.createAndStart(version);
 | 
			
		||||
    String indicesPrefix = UUID.randomUUID().toString();
 | 
			
		||||
    Config cfg = new Config();
 | 
			
		||||
    configure(cfg, container, indicesPrefix, version);
 | 
			
		||||
    configure(cfg, container, indicesPrefix);
 | 
			
		||||
    return cfg;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -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));
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
@@ -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));
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
@@ -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));
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
@@ -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));
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
@@ -22,9 +22,6 @@ import org.junit.Test;
 | 
			
		||||
public class ElasticVersionTest extends GerritBaseTests {
 | 
			
		||||
  @Test
 | 
			
		||||
  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.4")).isEqualTo(ElasticVersion.V6_2);
 | 
			
		||||
 | 
			
		||||
@@ -78,7 +75,6 @@ public class ElasticVersionTest extends GerritBaseTests {
 | 
			
		||||
 | 
			
		||||
  @Test
 | 
			
		||||
  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_3.isAtLeastMinorVersion(ElasticVersion.V6_7)).isFalse();
 | 
			
		||||
    assertThat(ElasticVersion.V6_4.isAtLeastMinorVersion(ElasticVersion.V6_7)).isFalse();
 | 
			
		||||
@@ -97,7 +93,6 @@ public class ElasticVersionTest extends GerritBaseTests {
 | 
			
		||||
 | 
			
		||||
  @Test
 | 
			
		||||
  public void version6OrLater() throws Exception {
 | 
			
		||||
    assertThat(ElasticVersion.V5_6.isV6OrLater()).isFalse();
 | 
			
		||||
    assertThat(ElasticVersion.V6_2.isV6OrLater()).isTrue();
 | 
			
		||||
    assertThat(ElasticVersion.V6_3.isV6OrLater()).isTrue();
 | 
			
		||||
    assertThat(ElasticVersion.V6_4.isV6OrLater()).isTrue();
 | 
			
		||||
@@ -116,7 +111,6 @@ public class ElasticVersionTest extends GerritBaseTests {
 | 
			
		||||
 | 
			
		||||
  @Test
 | 
			
		||||
  public void version7OrLater() throws Exception {
 | 
			
		||||
    assertThat(ElasticVersion.V5_6.isV7OrLater()).isFalse();
 | 
			
		||||
    assertThat(ElasticVersion.V6_2.isV7OrLater()).isFalse();
 | 
			
		||||
    assertThat(ElasticVersion.V6_3.isV7OrLater()).isFalse();
 | 
			
		||||
    assertThat(ElasticVersion.V6_4.isV7OrLater()).isFalse();
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user