Merge branch 'stable-2.14' into stable-2.15

* stable-2.14:
  GroupField: Change UUID fields' type to KEYWORD
  Add keyword type to index type system
  Elasticsearch: Encapsulate supported versions in an enum

Change-Id: Ic30a5bc0c69623a22f1305c96bfa70e3daeed054
This commit is contained in:
David Pursehouse
2018-06-04 16:38:41 +09:00
14 changed files with 153 additions and 40 deletions

View File

@@ -15,6 +15,7 @@
package com.google.gerrit.elasticsearch;
import com.google.common.collect.ImmutableSet;
import com.google.gerrit.elasticsearch.ElasticVersion;
import java.util.Set;
import org.apache.http.HttpHost;
import org.junit.internal.AssumptionViolatedException;
@@ -24,13 +25,7 @@ import org.testcontainers.containers.GenericContainer;
public class ElasticContainer<SELF extends ElasticContainer<SELF>> extends GenericContainer<SELF> {
private static final int ELASTICSEARCH_DEFAULT_PORT = 9200;
public enum Version {
V2,
V5,
V6
}
public static ElasticContainer<?> createAndStart(Version version) {
public static ElasticContainer<?> createAndStart(ElasticVersion version) {
// Assumption violation is not natively supported by Testcontainers.
// See https://github.com/testcontainers/testcontainers-java/issues/343
try {
@@ -43,22 +38,22 @@ public class ElasticContainer<SELF extends ElasticContainer<SELF>> extends Gener
}
public static ElasticContainer<?> createAndStart() {
return createAndStart(Version.V2);
return createAndStart(ElasticVersion.V2_4);
}
private static String getImageName(Version version) {
private static String getImageName(ElasticVersion version) {
switch (version) {
case V2:
case V2_4:
return "elasticsearch:2.4.6-alpine";
case V5:
case V5_6:
return "elasticsearch:5.6.9-alpine";
case V6:
case V6_2:
return "docker.elastic.co/elasticsearch/elasticsearch:6.2.4";
}
throw new IllegalStateException("Unsupported version: " + version.name());
throw new IllegalStateException("No tests for version: " + version.name());
}
private ElasticContainer(Version version) {
private ElasticContainer(ElasticVersion version) {
super(getImageName(version));
}

View File

@@ -0,0 +1,45 @@
// 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 static com.google.common.truth.Truth.assertThat;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
public class ElasticVersionTest {
@Rule public ExpectedException exception = ExpectedException.none();
@Test
public void supportedVersion() throws Exception {
assertThat(ElasticVersion.forVersion("2.4.0")).isEqualTo(ElasticVersion.V2_4);
assertThat(ElasticVersion.forVersion("2.4.6")).isEqualTo(ElasticVersion.V2_4);
assertThat(ElasticVersion.forVersion("5.6.0")).isEqualTo(ElasticVersion.V5_6);
assertThat(ElasticVersion.forVersion("5.6.9")).isEqualTo(ElasticVersion.V5_6);
assertThat(ElasticVersion.forVersion("6.2.0")).isEqualTo(ElasticVersion.V6_2);
assertThat(ElasticVersion.forVersion("6.2.4")).isEqualTo(ElasticVersion.V6_2);
}
@Test
public void unsupportedVersion() throws Exception {
exception.expect(ElasticVersion.InvalidVersion.class);
exception.expectMessage(
"Invalid version: [4.0.0]. Supported versions: " + ElasticVersion.supportedVersions());
ElasticVersion.forVersion("4.0.0");
}
}