move bwc specific stuff to backcompat base class
This commit is contained in:
parent
52c4af6115
commit
621f502b12
|
@ -42,7 +42,6 @@ import org.apache.lucene.store.Directory;
|
|||
import org.apache.lucene.store.MockDirectoryWrapper;
|
||||
import org.apache.lucene.util.IOUtils;
|
||||
import org.apache.lucene.util.LuceneTestCase.SuppressFileSystems;
|
||||
import org.apache.lucene.util.TestUtil;
|
||||
import org.elasticsearch.ElasticsearchException;
|
||||
import org.elasticsearch.Version;
|
||||
import org.elasticsearch.cluster.metadata.IndexMetaData;
|
||||
|
@ -103,14 +102,9 @@ import java.util.List;
|
|||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import static com.carrotsearch.randomizedtesting.RandomizedTest.randomBoolean;
|
||||
import static com.carrotsearch.randomizedtesting.RandomizedTest.randomDouble;
|
||||
import static com.carrotsearch.randomizedtesting.RandomizedTest.randomIntBetween;
|
||||
import static org.elasticsearch.common.settings.ImmutableSettings.Builder.EMPTY_SETTINGS;
|
||||
import static org.elasticsearch.index.engine.Engine.Operation.Origin.PRIMARY;
|
||||
import static org.elasticsearch.index.engine.Engine.Operation.Origin.REPLICA;
|
||||
import static org.elasticsearch.test.ElasticsearchTestCase.assertBusy;
|
||||
import static org.elasticsearch.test.ElasticsearchTestCase.terminate;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.greaterThan;
|
||||
import static org.hamcrest.Matchers.notNullValue;
|
||||
|
|
|
@ -26,8 +26,8 @@ import org.elasticsearch.Version;
|
|||
import org.elasticsearch.common.settings.ImmutableSettings;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.test.ElasticsearchBackwardsCompatIntegrationTest;
|
||||
import org.elasticsearch.test.ElasticsearchIntegrationTest;
|
||||
import org.elasticsearch.test.ElasticsearchTestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
@ -40,7 +40,7 @@ import static org.hamcrest.Matchers.is;
|
|||
import static org.hamcrest.Matchers.notNullValue;
|
||||
|
||||
@ElasticsearchIntegrationTest.ClusterScope(scope = ElasticsearchIntegrationTest.Scope.SUITE)
|
||||
@ElasticsearchTestCase.CompatibilityVersion(version = Version.V_1_2_0_ID) // we throw an exception if we create an index with _field_names that is 1.3
|
||||
@ElasticsearchBackwardsCompatIntegrationTest.CompatibilityVersion(version = Version.V_1_2_0_ID) // we throw an exception if we create an index with _field_names that is 1.3
|
||||
public class PreBuiltAnalyzerIntegrationTests extends ElasticsearchIntegrationTest {
|
||||
|
||||
@Override
|
||||
|
|
|
@ -18,11 +18,13 @@
|
|||
*/
|
||||
package org.elasticsearch.test;
|
||||
|
||||
import com.carrotsearch.randomizedtesting.annotations.TestGroup;
|
||||
import org.elasticsearch.Version;
|
||||
import org.elasticsearch.cluster.ClusterState;
|
||||
import org.elasticsearch.cluster.routing.IndexRoutingTable;
|
||||
import org.elasticsearch.cluster.routing.IndexShardRoutingTable;
|
||||
import org.elasticsearch.cluster.routing.ShardRouting;
|
||||
import org.elasticsearch.common.Strings;
|
||||
import org.elasticsearch.common.io.PathUtils;
|
||||
import org.elasticsearch.common.regex.Regex;
|
||||
import org.elasticsearch.common.settings.ImmutableSettings;
|
||||
|
@ -34,14 +36,18 @@ import org.elasticsearch.transport.Transport;
|
|||
import org.elasticsearch.transport.TransportModule;
|
||||
import org.elasticsearch.transport.TransportService;
|
||||
import org.elasticsearch.transport.netty.NettyTransport;
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Inherited;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
|
||||
import static org.hamcrest.Matchers.is;
|
||||
|
||||
|
@ -58,12 +64,12 @@ import static org.hamcrest.Matchers.is;
|
|||
* <p>
|
||||
* Note: this base class is still experimental and might have bugs or leave external processes running behind.
|
||||
* </p>
|
||||
* Backwards compatibility tests are disabled by default via {@link org.apache.lucene.util.AbstractRandomizedTest.Backwards} annotation.
|
||||
* Backwards compatibility tests are disabled by default via {@link Backwards} annotation.
|
||||
* The following system variables control the test execution:
|
||||
* <ul>
|
||||
* <li>
|
||||
* <tt>{@value #TESTS_BACKWARDS_COMPATIBILITY}</tt> enables / disables
|
||||
* tests annotated with {@link org.apache.lucene.util.AbstractRandomizedTest.Backwards} (defaults to
|
||||
* tests annotated with {@link Backwards} (defaults to
|
||||
* <tt>false</tt>)
|
||||
* </li>
|
||||
* <li>
|
||||
|
@ -81,11 +87,29 @@ import static org.hamcrest.Matchers.is;
|
|||
*
|
||||
*/
|
||||
// the transportClientRatio is tricky here since we don't fully control the cluster nodes
|
||||
@ElasticsearchTestCase.Backwards
|
||||
@ElasticsearchBackwardsCompatIntegrationTest.Backwards
|
||||
@ElasticsearchIntegrationTest.ClusterScope(minNumDataNodes = 0, maxNumDataNodes = 2, scope = ElasticsearchIntegrationTest.Scope.SUITE, numClientNodes = 0, transportClientRatio = 0.0)
|
||||
@Ignore
|
||||
public abstract class ElasticsearchBackwardsCompatIntegrationTest extends ElasticsearchIntegrationTest {
|
||||
|
||||
/**
|
||||
* Key used to set the path for the elasticsearch executable used to run backwards compatibility tests from
|
||||
* via the commandline -D{@value #TESTS_BACKWARDS_COMPATIBILITY}
|
||||
*/
|
||||
public static final String TESTS_BACKWARDS_COMPATIBILITY = "tests.bwc";
|
||||
public static final String TESTS_BACKWARDS_COMPATIBILITY_VERSION = "tests.bwc.version";
|
||||
/**
|
||||
* Key used to set the path for the elasticsearch executable used to run backwards compatibility tests from
|
||||
* via the commandline -D{@value #TESTS_BACKWARDS_COMPATIBILITY_PATH}
|
||||
*/
|
||||
public static final String TESTS_BACKWARDS_COMPATIBILITY_PATH = "tests.bwc.path";
|
||||
/**
|
||||
* Property that allows to adapt the tests behaviour to older features/bugs based on the input version
|
||||
*/
|
||||
private static final String TESTS_COMPATIBILITY = "tests.compatibility";
|
||||
|
||||
private static final Version GLOABL_COMPATIBILITY_VERSION = Version.fromString(compatibilityVersionProperty());
|
||||
|
||||
private static Path backwardsCompatibilityPath() {
|
||||
String path = System.getProperty(TESTS_BACKWARDS_COMPATIBILITY_PATH);
|
||||
if (path == null || path.isEmpty()) {
|
||||
|
@ -109,6 +133,53 @@ public abstract class ElasticsearchBackwardsCompatIntegrationTest extends Elasti
|
|||
return file;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ImmutableSettings.Builder setRandomSettings(Random random, ImmutableSettings.Builder builder) {
|
||||
if (globalCompatibilityVersion().before(Version.V_1_3_2)) {
|
||||
// if we test against nodes before 1.3.2 we disable all the compression due to a known bug
|
||||
// see #7210
|
||||
builder.put(RecoverySettings.INDICES_RECOVERY_COMPRESS, false);
|
||||
}
|
||||
return builder;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retruns the tests compatibility version.
|
||||
*/
|
||||
public Version compatibilityVersion() {
|
||||
return compatibilityVersion(getClass());
|
||||
}
|
||||
|
||||
private Version compatibilityVersion(Class<?> clazz) {
|
||||
if (clazz == Object.class || clazz == ElasticsearchIntegrationTest.class) {
|
||||
return globalCompatibilityVersion();
|
||||
}
|
||||
CompatibilityVersion annotation = clazz.getAnnotation(CompatibilityVersion.class);
|
||||
if (annotation != null) {
|
||||
return Version.smallest(Version.fromId(annotation.version()), compatibilityVersion(clazz.getSuperclass()));
|
||||
}
|
||||
return compatibilityVersion(clazz.getSuperclass());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a global compatibility version that is set via the
|
||||
* {@value #TESTS_COMPATIBILITY} or {@value #TESTS_BACKWARDS_COMPATIBILITY_VERSION} system property.
|
||||
* If both are unset the current version is used as the global compatibility version. This
|
||||
* compatibility version is used for static randomization. For per-suite compatibility version see
|
||||
* {@link #compatibilityVersion()}
|
||||
*/
|
||||
public static Version globalCompatibilityVersion() {
|
||||
return GLOABL_COMPATIBILITY_VERSION;
|
||||
}
|
||||
|
||||
private static String compatibilityVersionProperty() {
|
||||
final String version = System.getProperty(TESTS_COMPATIBILITY);
|
||||
if (Strings.hasLength(version)) {
|
||||
return version;
|
||||
}
|
||||
return System.getProperty(TESTS_BACKWARDS_COMPATIBILITY_VERSION);
|
||||
}
|
||||
|
||||
public CompositeTestCluster backwardsCluster() {
|
||||
return (CompositeTestCluster) cluster();
|
||||
}
|
||||
|
@ -193,4 +264,25 @@ public abstract class ElasticsearchBackwardsCompatIntegrationTest extends Elasti
|
|||
protected Settings externalNodeSettings(int nodeOrdinal) {
|
||||
return addLoggerSettings(commonNodeSettings(nodeOrdinal));
|
||||
}
|
||||
|
||||
/**
|
||||
* Annotation for backwards compat tests
|
||||
*/
|
||||
@Inherited
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.TYPE)
|
||||
@TestGroup(enabled = false, sysProperty = ElasticsearchBackwardsCompatIntegrationTest.TESTS_BACKWARDS_COMPATIBILITY)
|
||||
public @interface Backwards {
|
||||
}
|
||||
|
||||
/**
|
||||
* If a test is annotated with {@link CompatibilityVersion}
|
||||
* all randomized settings will only contain settings or mappings which are compatible with the specified version ID.
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target({ElementType.TYPE})
|
||||
@Ignore
|
||||
public @interface CompatibilityVersion {
|
||||
int version();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -450,7 +450,7 @@ public abstract class ElasticsearchIntegrationTest extends ElasticsearchTestCase
|
|||
}
|
||||
}
|
||||
|
||||
private static ImmutableSettings.Builder setRandomSettings(Random random, ImmutableSettings.Builder builder) {
|
||||
protected ImmutableSettings.Builder setRandomSettings(Random random, ImmutableSettings.Builder builder) {
|
||||
setRandomMerge(random, builder);
|
||||
setRandomTranslogSettings(random, builder);
|
||||
setRandomNormsLoading(random, builder);
|
||||
|
@ -502,11 +502,6 @@ public abstract class ElasticsearchIntegrationTest extends ElasticsearchTestCase
|
|||
builder.put(IndicesFieldDataCache.FIELDDATA_CACHE_CONCURRENCY_LEVEL, RandomInts.randomIntBetween(random, 1, 32));
|
||||
builder.put(IndicesFilterCache.INDICES_CACHE_FILTER_CONCURRENCY_LEVEL, RandomInts.randomIntBetween(random, 1, 32));
|
||||
}
|
||||
if (globalCompatibilityVersion().before(Version.V_1_3_2)) {
|
||||
// if we test against nodes before 1.3.2 we disable all the compression due to a known bug
|
||||
// see #7210
|
||||
builder.put(RecoverySettings.INDICES_RECOVERY_COMPRESS, false);
|
||||
}
|
||||
if (random.nextBoolean()) {
|
||||
builder.put(NettyTransport.PING_SCHEDULE, RandomInts.randomIntBetween(random, 100, 2000) + "ms");
|
||||
}
|
||||
|
|
|
@ -40,13 +40,11 @@ import org.apache.lucene.uninverting.UninvertingReader;
|
|||
import org.apache.lucene.util.LuceneTestCase;
|
||||
import org.apache.lucene.util.TestUtil;
|
||||
import org.apache.lucene.util.TimeUnits;
|
||||
import org.apache.lucene.util.LuceneTestCase.Nightly;
|
||||
import org.apache.lucene.util.LuceneTestCase.SuppressCodecs;
|
||||
import org.elasticsearch.Version;
|
||||
import org.elasticsearch.client.Requests;
|
||||
import org.elasticsearch.cluster.metadata.IndexMetaData;
|
||||
import org.elasticsearch.cluster.routing.DjbHashFunction;
|
||||
import org.elasticsearch.common.Strings;
|
||||
import org.elasticsearch.common.io.PathUtils;
|
||||
import org.elasticsearch.common.logging.ESLogger;
|
||||
import org.elasticsearch.common.logging.Loggers;
|
||||
|
@ -178,30 +176,6 @@ public abstract class ElasticsearchTestCase extends LuceneTestCase {
|
|||
*/
|
||||
public static final int CHILD_JVM_ID = Integer.parseInt(System.getProperty(SysGlobals.CHILDVM_SYSPROP_JVM_ID, "0"));
|
||||
|
||||
/**
|
||||
* Annotation for backwards compat tests
|
||||
*/
|
||||
@Inherited
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.TYPE)
|
||||
@TestGroup(enabled = false, sysProperty = TESTS_BACKWARDS_COMPATIBILITY)
|
||||
public @interface Backwards {
|
||||
}
|
||||
|
||||
/**
|
||||
* Key used to set the path for the elasticsearch executable used to run backwards compatibility tests from
|
||||
* via the commandline -D{@value #TESTS_BACKWARDS_COMPATIBILITY}
|
||||
*/
|
||||
public static final String TESTS_BACKWARDS_COMPATIBILITY = "tests.bwc";
|
||||
|
||||
public static final String TESTS_BACKWARDS_COMPATIBILITY_VERSION = "tests.bwc.version";
|
||||
|
||||
/**
|
||||
* Key used to set the path for the elasticsearch executable used to run backwards compatibility tests from
|
||||
* via the commandline -D{@value #TESTS_BACKWARDS_COMPATIBILITY_PATH}
|
||||
*/
|
||||
public static final String TESTS_BACKWARDS_COMPATIBILITY_PATH = "tests.bwc.path";
|
||||
|
||||
/**
|
||||
* Annotation for REST tests
|
||||
*/
|
||||
|
@ -434,12 +408,7 @@ public abstract class ElasticsearchTestCase extends LuceneTestCase {
|
|||
|
||||
protected final ESLogger logger = Loggers.getLogger(getClass());
|
||||
|
||||
/**
|
||||
* Property that allows to adapt the tests behaviour to older features/bugs based on the input version
|
||||
*/
|
||||
private static final String TESTS_COMPATIBILITY = "tests.compatibility";
|
||||
|
||||
private static final Version GLOABL_COMPATIBILITY_VERSION = Version.fromString(compatibilityVersionProperty());
|
||||
|
||||
static {
|
||||
SecurityHack.ensureInitialized();
|
||||
|
@ -803,55 +772,6 @@ public abstract class ElasticsearchTestCase extends LuceneTestCase {
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* If a test is annotated with {@link org.elasticsearch.test.ElasticsearchTestCase.CompatibilityVersion}
|
||||
* all randomized settings will only contain settings or mappings which are compatible with the specified version ID.
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target({ElementType.TYPE})
|
||||
@Ignore
|
||||
public @interface CompatibilityVersion {
|
||||
int version();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a global compatibility version that is set via the
|
||||
* {@value #TESTS_COMPATIBILITY} or {@value #TESTS_BACKWARDS_COMPATIBILITY_VERSION} system property.
|
||||
* If both are unset the current version is used as the global compatibility version. This
|
||||
* compatibility version is used for static randomization. For per-suite compatibility version see
|
||||
* {@link #compatibilityVersion()}
|
||||
*/
|
||||
public static Version globalCompatibilityVersion() {
|
||||
return GLOABL_COMPATIBILITY_VERSION;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retruns the tests compatibility version.
|
||||
*/
|
||||
public Version compatibilityVersion() {
|
||||
return compatibilityVersion(getClass());
|
||||
}
|
||||
|
||||
private Version compatibilityVersion(Class<?> clazz) {
|
||||
if (clazz == Object.class || clazz == ElasticsearchIntegrationTest.class) {
|
||||
return globalCompatibilityVersion();
|
||||
}
|
||||
CompatibilityVersion annotation = clazz.getAnnotation(CompatibilityVersion.class);
|
||||
if (annotation != null) {
|
||||
return Version.smallest(Version.fromId(annotation.version()), compatibilityVersion(clazz.getSuperclass()));
|
||||
}
|
||||
return compatibilityVersion(clazz.getSuperclass());
|
||||
}
|
||||
|
||||
private static String compatibilityVersionProperty() {
|
||||
final String version = System.getProperty(TESTS_COMPATIBILITY);
|
||||
if (Strings.hasLength(version)) {
|
||||
return version;
|
||||
}
|
||||
return System.getProperty(TESTS_BACKWARDS_COMPATIBILITY_VERSION);
|
||||
}
|
||||
|
||||
|
||||
public static boolean terminate(ExecutorService... services) throws InterruptedException {
|
||||
boolean terminated = true;
|
||||
for (ExecutorService service : services) {
|
||||
|
|
Loading…
Reference in New Issue