simplify version handling in rest tests, add tests for version utilities
This commit is contained in:
parent
d301567ecf
commit
06eee11dbb
|
@ -202,7 +202,7 @@ setup:
|
|||
"Getting alias on an non-existent index should return 404":
|
||||
|
||||
- skip:
|
||||
version: 1 - 999
|
||||
version: 0 - 999
|
||||
reason: not implemented yet
|
||||
- do:
|
||||
catch: missing
|
||||
|
|
|
@ -81,7 +81,7 @@ setup:
|
|||
---
|
||||
"put settings in list of indices":
|
||||
- skip:
|
||||
version: 1 - 999
|
||||
version: 0 - 999
|
||||
reason: list of indices not implemented yet
|
||||
- do:
|
||||
indices.put_settings:
|
||||
|
|
|
@ -485,7 +485,7 @@ public class Version {
|
|||
}
|
||||
String[] parts = version.split("\\.");
|
||||
if (parts.length < 3 || parts.length > 4) {
|
||||
throw new IllegalArgumentException("the version needs to contain major, minor and revision, and optionally the build");
|
||||
throw new IllegalArgumentException("the version needs to contain major, minor and revision, and optionally the build: " + version);
|
||||
}
|
||||
|
||||
try {
|
||||
|
|
|
@ -23,7 +23,7 @@ import org.elasticsearch.cluster.metadata.IndexMetaData;
|
|||
import org.elasticsearch.common.lucene.Lucene;
|
||||
import org.elasticsearch.common.settings.ImmutableSettings;
|
||||
import org.elasticsearch.test.ElasticsearchTestCase;
|
||||
import org.elasticsearch.test.VersionTestUtil;
|
||||
import org.elasticsearch.test.VersionUtils;
|
||||
import org.hamcrest.Matchers;
|
||||
import org.junit.Test;
|
||||
|
||||
|
@ -34,7 +34,7 @@ import java.util.Map;
|
|||
|
||||
import static org.elasticsearch.Version.V_0_20_0;
|
||||
import static org.elasticsearch.Version.V_0_90_0;
|
||||
import static org.elasticsearch.test.VersionTestUtil.randomVersion;
|
||||
import static org.elasticsearch.test.VersionUtils.randomVersion;
|
||||
import static org.hamcrest.CoreMatchers.equalTo;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.sameInstance;
|
||||
|
@ -152,7 +152,7 @@ public class VersionTests extends ElasticsearchTestCase {
|
|||
|
||||
public void testParseLenient() {
|
||||
// note this is just a silly sanity check, we test it in lucene
|
||||
for (Version version : VersionTestUtil.allVersions()) {
|
||||
for (Version version : VersionUtils.allVersions()) {
|
||||
org.apache.lucene.util.Version luceneVersion = version.luceneVersion;
|
||||
String string = luceneVersion.toString().toUpperCase(Locale.ROOT)
|
||||
.replaceFirst("^LUCENE_(\\d+)_(\\d+)$", "$1.$2");
|
||||
|
|
|
@ -27,7 +27,7 @@ import org.junit.Test;
|
|||
|
||||
import java.io.IOException;
|
||||
|
||||
import static org.elasticsearch.test.VersionTestUtil.randomVersion;
|
||||
import static org.elasticsearch.test.VersionUtils.randomVersion;
|
||||
import static org.hamcrest.CoreMatchers.equalTo;
|
||||
|
||||
public class OriginalIndicesTests extends ElasticsearchTestCase {
|
||||
|
|
|
@ -24,7 +24,7 @@ import org.elasticsearch.action.support.IndicesOptions;
|
|||
import org.elasticsearch.common.io.stream.BytesStreamInput;
|
||||
import org.elasticsearch.common.io.stream.BytesStreamOutput;
|
||||
import org.elasticsearch.test.ElasticsearchTestCase;
|
||||
import org.elasticsearch.test.VersionTestUtil;
|
||||
import org.elasticsearch.test.VersionUtils;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.equalTo;
|
||||
|
@ -43,7 +43,7 @@ public class ClusterStateRequestTest extends ElasticsearchTestCase {
|
|||
ClusterStateRequest clusterStateRequest = new ClusterStateRequest().routingTable(randomBoolean()).metaData(randomBoolean())
|
||||
.nodes(randomBoolean()).blocks(randomBoolean()).indices("testindex", "testindex2").indicesOptions(indicesOptions);
|
||||
|
||||
Version testVersion = VersionTestUtil.randomVersionBetween(random(), Version.CURRENT.minimumCompatibilityVersion(), Version.CURRENT);
|
||||
Version testVersion = VersionUtils.randomVersionBetween(random(), Version.CURRENT.minimumCompatibilityVersion(), Version.CURRENT);
|
||||
BytesStreamOutput output = new BytesStreamOutput();
|
||||
output.setVersion(testVersion);
|
||||
clusterStateRequest.writeTo(output);
|
||||
|
|
|
@ -28,7 +28,7 @@ import org.junit.Test;
|
|||
|
||||
import java.io.IOException;
|
||||
|
||||
import static org.elasticsearch.test.VersionTestUtil.randomVersion;
|
||||
import static org.elasticsearch.test.VersionUtils.randomVersion;
|
||||
import static org.hamcrest.CoreMatchers.equalTo;
|
||||
|
||||
public class MultiGetShardRequestTests extends ElasticsearchTestCase {
|
||||
|
|
|
@ -27,7 +27,7 @@ import org.junit.Test;
|
|||
|
||||
import java.io.IOException;
|
||||
|
||||
import static org.elasticsearch.test.VersionTestUtil.randomVersion;
|
||||
import static org.elasticsearch.test.VersionUtils.randomVersion;
|
||||
import static org.hamcrest.CoreMatchers.equalTo;
|
||||
|
||||
public class GetIndexedScriptRequestTests extends ElasticsearchTestCase {
|
||||
|
|
|
@ -32,7 +32,7 @@ import org.junit.Test;
|
|||
|
||||
import java.io.IOException;
|
||||
|
||||
import static org.elasticsearch.test.VersionTestUtil.randomVersion;
|
||||
import static org.elasticsearch.test.VersionUtils.randomVersion;
|
||||
import static org.hamcrest.CoreMatchers.*;
|
||||
|
||||
public class MoreLikeThisRequestTests extends ElasticsearchTestCase {
|
||||
|
|
|
@ -25,7 +25,7 @@ import org.elasticsearch.common.io.stream.BytesStreamOutput;
|
|||
import org.elasticsearch.test.ElasticsearchTestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.elasticsearch.test.VersionTestUtil.randomVersion;
|
||||
import static org.elasticsearch.test.VersionUtils.randomVersion;
|
||||
import static org.hamcrest.CoreMatchers.equalTo;
|
||||
|
||||
public class IndicesOptionsTests extends ElasticsearchTestCase {
|
||||
|
|
|
@ -48,18 +48,16 @@ import org.elasticsearch.search.aggregations.bucket.histogram.Histogram;
|
|||
import org.elasticsearch.search.aggregations.bucket.terms.Terms;
|
||||
import org.elasticsearch.search.sort.SortOrder;
|
||||
import org.elasticsearch.test.ElasticsearchIntegrationTest;
|
||||
import org.elasticsearch.test.VersionTestUtil;
|
||||
import org.elasticsearch.test.VersionUtils;
|
||||
import org.elasticsearch.test.hamcrest.ElasticsearchAssertions;
|
||||
import org.elasticsearch.test.index.merge.NoMergePolicyProvider;
|
||||
import org.elasticsearch.test.rest.client.http.HttpRequestBuilder;
|
||||
import org.hamcrest.Matchers;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.nio.file.DirectoryStream;
|
||||
import java.nio.file.FileVisitResult;
|
||||
import java.nio.file.Files;
|
||||
|
@ -227,7 +225,7 @@ public class OldIndexBackwardsCompatibilityTests extends ElasticsearchIntegratio
|
|||
|
||||
public void testAllVersionsTested() throws Exception {
|
||||
SortedSet<String> expectedVersions = new TreeSet<>();
|
||||
for (Version v : VersionTestUtil.allVersions()) {
|
||||
for (Version v : VersionUtils.allVersions()) {
|
||||
if (v.snapshot()) continue; // snapshots are unreleased, so there is no backcompat yet
|
||||
if (v.onOrBefore(Version.V_0_20_6)) continue; // we can only test back one major lucene version
|
||||
if (v.equals(Version.CURRENT)) continue; // the current version is always compatible with itself
|
||||
|
|
|
@ -33,7 +33,7 @@ import java.io.IOException;
|
|||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.elasticsearch.test.VersionTestUtil.randomVersion;
|
||||
import static org.elasticsearch.test.VersionUtils.randomVersion;
|
||||
|
||||
public class DiscoveryNodeTests extends ElasticsearchTestCase {
|
||||
|
||||
|
|
|
@ -29,7 +29,7 @@ import org.elasticsearch.common.settings.ImmutableSettings;
|
|||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.node.Node;
|
||||
import org.elasticsearch.test.ElasticsearchTestCase;
|
||||
import org.elasticsearch.test.VersionTestUtil;
|
||||
import org.elasticsearch.test.VersionUtils;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStreamReader;
|
||||
|
@ -58,7 +58,7 @@ public class RoutingBackwardCompatibilityTests extends ElasticsearchTestCase {
|
|||
final int currentExpectedShard = Integer.parseInt(parts[6]);
|
||||
|
||||
OperationRouting operationRouting = node.injector().getInstance(OperationRouting.class);
|
||||
for (Version version : VersionTestUtil.allVersions()) {
|
||||
for (Version version : VersionUtils.allVersions()) {
|
||||
final Settings settings = settings(version).build();
|
||||
IndexMetaData indexMetaData = IndexMetaData.builder(index).settings(settings).numberOfShards(numberOfShards).numberOfReplicas(randomInt(3)).build();
|
||||
MetaData.Builder metaData = MetaData.builder().put(indexMetaData, false);
|
||||
|
|
|
@ -33,7 +33,7 @@ import org.elasticsearch.cluster.routing.allocation.decider.ClusterRebalanceAllo
|
|||
import org.elasticsearch.common.logging.ESLogger;
|
||||
import org.elasticsearch.common.logging.Loggers;
|
||||
import org.elasticsearch.test.ElasticsearchAllocationTestCase;
|
||||
import org.elasticsearch.test.VersionTestUtil;
|
||||
import org.elasticsearch.test.VersionUtils;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
@ -42,7 +42,7 @@ import java.util.List;
|
|||
|
||||
import static org.elasticsearch.cluster.routing.ShardRoutingState.*;
|
||||
import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder;
|
||||
import static org.elasticsearch.test.VersionTestUtil.randomVersion;
|
||||
import static org.elasticsearch.test.VersionUtils.randomVersion;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
|
||||
/**
|
||||
|
@ -124,7 +124,7 @@ public class NodeVersionAllocationDeciderTests extends ElasticsearchAllocationTe
|
|||
}
|
||||
|
||||
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder(clusterState.nodes())
|
||||
.put(newNode("node3", VersionTestUtil.getPreviousVersion())))
|
||||
.put(newNode("node3", VersionUtils.getPreviousVersion())))
|
||||
.build();
|
||||
prevRoutingTable = routingTable;
|
||||
routingTable = strategy.reroute(clusterState).routingTable();
|
||||
|
@ -204,7 +204,7 @@ public class NodeVersionAllocationDeciderTests extends ElasticsearchAllocationTe
|
|||
} else {
|
||||
for (int j = nodes.size(); j < numNodes; j++) {
|
||||
if (frequently()) {
|
||||
nodes.add(newNode("node" + (nodeIdx++), randomBoolean() ? VersionTestUtil.getPreviousVersion() : Version.CURRENT));
|
||||
nodes.add(newNode("node" + (nodeIdx++), randomBoolean() ? VersionUtils.getPreviousVersion() : Version.CURRENT));
|
||||
} else {
|
||||
nodes.add(newNode("node" + (nodeIdx++), randomVersion(random())));
|
||||
}
|
||||
|
@ -249,20 +249,20 @@ public class NodeVersionAllocationDeciderTests extends ElasticsearchAllocationTe
|
|||
assertThat(routingTable.index("test").shard(i).shards().get(2).currentNodeId(), nullValue());
|
||||
}
|
||||
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder()
|
||||
.put(newNode("old0", VersionTestUtil.getPreviousVersion()))
|
||||
.put(newNode("old1", VersionTestUtil.getPreviousVersion()))
|
||||
.put(newNode("old2", VersionTestUtil.getPreviousVersion()))).build();
|
||||
.put(newNode("old0", VersionUtils.getPreviousVersion()))
|
||||
.put(newNode("old1", VersionUtils.getPreviousVersion()))
|
||||
.put(newNode("old2", VersionUtils.getPreviousVersion()))).build();
|
||||
clusterState = stabilize(clusterState, service);
|
||||
|
||||
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder()
|
||||
.put(newNode("old0", VersionTestUtil.getPreviousVersion()))
|
||||
.put(newNode("old1", VersionTestUtil.getPreviousVersion()))
|
||||
.put(newNode("old0", VersionUtils.getPreviousVersion()))
|
||||
.put(newNode("old1", VersionUtils.getPreviousVersion()))
|
||||
.put(newNode("new0"))).build();
|
||||
|
||||
clusterState = stabilize(clusterState, service);
|
||||
|
||||
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder()
|
||||
.put(newNode("node0", VersionTestUtil.getPreviousVersion()))
|
||||
.put(newNode("node0", VersionUtils.getPreviousVersion()))
|
||||
.put(newNode("new1"))
|
||||
.put(newNode("new0"))).build();
|
||||
|
||||
|
|
|
@ -29,7 +29,7 @@ import org.elasticsearch.index.IndexService;
|
|||
import org.elasticsearch.index.mapper.DocumentMapperParser;
|
||||
import org.elasticsearch.index.mapper.MapperParsingException;
|
||||
import org.elasticsearch.test.ElasticsearchSingleNodeTest;
|
||||
import org.elasticsearch.test.VersionTestUtil;
|
||||
import org.elasticsearch.test.VersionUtils;
|
||||
import org.junit.Assert;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -46,7 +46,7 @@ public class CodecTests extends ElasticsearchSingleNodeTest {
|
|||
.startObject("properties").startObject("field").field("type", "string").field("postings_format", Codec.getDefault().postingsFormat().getName()).endObject().endObject()
|
||||
.endObject().endObject().string();
|
||||
int i = 0;
|
||||
for (Version v : VersionTestUtil.allVersions()) {
|
||||
for (Version v : VersionUtils.allVersions()) {
|
||||
IndexService indexService = createIndex("test-" + i++, ImmutableSettings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, v).build());
|
||||
DocumentMapperParser parser = indexService.mapperService().documentMapperParser();
|
||||
try {
|
||||
|
@ -69,7 +69,7 @@ public class CodecTests extends ElasticsearchSingleNodeTest {
|
|||
.startObject("properties").startObject("field").field("type", "string").field("doc_values_format", Codec.getDefault().docValuesFormat().getName()).endObject().endObject()
|
||||
.endObject().endObject().string();
|
||||
int i = 0;
|
||||
for (Version v : VersionTestUtil.allVersions()) {
|
||||
for (Version v : VersionUtils.allVersions()) {
|
||||
IndexService indexService = createIndex("test-" + i++, ImmutableSettings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, v).build());
|
||||
DocumentMapperParser parser = indexService.mapperService().documentMapperParser();
|
||||
try {
|
||||
|
|
|
@ -37,7 +37,7 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import static org.elasticsearch.test.VersionTestUtil.randomVersion;
|
||||
import static org.elasticsearch.test.VersionUtils.randomVersion;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
|
||||
/**
|
||||
|
|
|
@ -27,7 +27,7 @@ import org.elasticsearch.Version;
|
|||
import org.elasticsearch.common.settings.ImmutableSettings;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.test.ElasticsearchTokenStreamTestCase;
|
||||
import org.elasticsearch.test.VersionTestUtil;
|
||||
import org.elasticsearch.test.VersionUtils;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -47,7 +47,7 @@ public class StemmerTokenFilterFactoryTests extends ElasticsearchTokenStreamTest
|
|||
int iters = scaledRandomIntBetween(20, 100);
|
||||
for (int i = 0; i < iters; i++) {
|
||||
|
||||
Version v = VersionTestUtil.randomVersion(random());
|
||||
Version v = VersionUtils.randomVersion(random());
|
||||
Settings settings = ImmutableSettings.settingsBuilder()
|
||||
.put("index.analysis.filter.my_english.type", "stemmer")
|
||||
.put("index.analysis.filter.my_english.language", "english")
|
||||
|
@ -80,7 +80,7 @@ public class StemmerTokenFilterFactoryTests extends ElasticsearchTokenStreamTest
|
|||
int iters = scaledRandomIntBetween(20, 100);
|
||||
for (int i = 0; i < iters; i++) {
|
||||
|
||||
Version v = VersionTestUtil.randomVersion(random());
|
||||
Version v = VersionUtils.randomVersion(random());
|
||||
Settings settings = ImmutableSettings.settingsBuilder()
|
||||
.put("index.analysis.filter.my_porter2.type", "stemmer")
|
||||
.put("index.analysis.filter.my_porter2.language", "porter2")
|
||||
|
|
|
@ -51,7 +51,7 @@ import java.util.Map;
|
|||
|
||||
import static org.elasticsearch.Version.V_1_5_0;
|
||||
import static org.elasticsearch.Version.V_2_0_0;
|
||||
import static org.elasticsearch.test.VersionTestUtil.randomVersion;
|
||||
import static org.elasticsearch.test.VersionUtils.randomVersion;
|
||||
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
|
||||
|
|
|
@ -36,7 +36,7 @@ import java.util.Locale;
|
|||
import java.util.Map;
|
||||
|
||||
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
|
||||
import static org.elasticsearch.test.VersionTestUtil.randomVersion;
|
||||
import static org.elasticsearch.test.VersionUtils.randomVersion;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.notNullValue;
|
||||
|
||||
|
|
|
@ -39,7 +39,7 @@ import java.util.Collections;
|
|||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import static org.elasticsearch.test.VersionTestUtil.randomVersion;
|
||||
import static org.elasticsearch.test.VersionUtils.randomVersion;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
|
||||
public class RecoveryStateTest extends ElasticsearchTestCase {
|
||||
|
|
|
@ -33,7 +33,7 @@ import java.io.ByteArrayInputStream;
|
|||
import java.io.ByteArrayOutputStream;
|
||||
import java.util.Collections;
|
||||
|
||||
import static org.elasticsearch.test.VersionTestUtil.randomVersion;
|
||||
import static org.elasticsearch.test.VersionUtils.randomVersion;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.nullValue;
|
||||
|
||||
|
|
|
@ -40,7 +40,7 @@ import java.util.HashSet;
|
|||
import java.util.Set;
|
||||
|
||||
import static org.elasticsearch.Version.CURRENT;
|
||||
import static org.elasticsearch.test.VersionTestUtil.randomVersion;
|
||||
import static org.elasticsearch.test.VersionUtils.randomVersion;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
|
||||
/**
|
||||
|
|
|
@ -44,7 +44,7 @@ import java.util.HashSet;
|
|||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.elasticsearch.test.VersionTestUtil.randomVersion;
|
||||
import static org.elasticsearch.test.VersionUtils.randomVersion;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.greaterThan;
|
||||
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
|
||||
|
|
|
@ -59,7 +59,7 @@ import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
|
|||
import static org.elasticsearch.index.query.FilterBuilders.*;
|
||||
import static org.elasticsearch.index.query.QueryBuilders.*;
|
||||
import static org.elasticsearch.index.query.functionscore.ScoreFunctionBuilders.scriptFunction;
|
||||
import static org.elasticsearch.test.VersionTestUtil.randomVersion;
|
||||
import static org.elasticsearch.test.VersionUtils.randomVersion;
|
||||
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.*;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
|
||||
|
|
|
@ -443,6 +443,16 @@ public abstract class ElasticsearchTestCase extends LuceneTestCase {
|
|||
}
|
||||
}
|
||||
|
||||
/** Returns a random number of temporary paths. */
|
||||
public String[] tmpPaths() {
|
||||
final int numPaths = TestUtil.nextInt(random(), 1, 3);
|
||||
final String[] absPaths = new String[numPaths];
|
||||
for (int i = 0; i < numPaths; i++) {
|
||||
absPaths[i] = createTempDir().toAbsolutePath().toString();
|
||||
}
|
||||
return absPaths;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return consistent index settings for the provided index version.
|
||||
*/
|
||||
|
@ -484,9 +494,7 @@ public abstract class ElasticsearchTestCase extends LuceneTestCase {
|
|||
logger.error(formatThreadStacks(allStackTraces));
|
||||
}
|
||||
|
||||
/**
|
||||
* Dump threads and their current stack trace.
|
||||
*/
|
||||
/** Dump threads and their current stack trace. */
|
||||
private static String formatThreadStacks(Map<Thread, StackTraceElement[]> threads) {
|
||||
StringBuilder message = new StringBuilder();
|
||||
int cnt = 1;
|
||||
|
@ -547,17 +555,7 @@ public abstract class ElasticsearchTestCase extends LuceneTestCase {
|
|||
return ThreadPool.terminate(service, 10, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a random number of temporary paths.
|
||||
*/
|
||||
public String[] tmpPaths() {
|
||||
final int numPaths = TestUtil.nextInt(random(), 1, 3);
|
||||
final String[] absPaths = new String[numPaths];
|
||||
for (int i = 0; i < numPaths; i++) {
|
||||
absPaths[i] = createTempDir().toAbsolutePath().toString();
|
||||
}
|
||||
return absPaths;
|
||||
}
|
||||
|
||||
|
||||
public NodeEnvironment newNodeEnvironment() throws IOException {
|
||||
return newNodeEnvironment(ImmutableSettings.EMPTY);
|
||||
|
|
|
@ -47,7 +47,7 @@ public abstract class ElasticsearchTokenStreamTestCase extends BaseTokenStreamTe
|
|||
}
|
||||
|
||||
public static Version randomVersion() {
|
||||
return VersionTestUtil.randomVersion(random());
|
||||
return VersionUtils.randomVersion(random());
|
||||
}
|
||||
|
||||
public ImmutableSettings.Builder newAnalysisSettingsBuilder() {
|
||||
|
|
|
@ -31,8 +31,8 @@ import java.util.List;
|
|||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
|
||||
/** Utilities for selection versions in tests */
|
||||
public class VersionTestUtil {
|
||||
/** Utilities for selecting versions in tests */
|
||||
public class VersionUtils {
|
||||
|
||||
private static final List<Version> SORTED_VERSIONS;
|
||||
static {
|
||||
|
@ -53,7 +53,6 @@ public class VersionTestUtil {
|
|||
}
|
||||
List<Integer> idList = new ArrayList<>(ids);
|
||||
Collections.sort(idList);
|
||||
Collections.reverse(idList);
|
||||
ImmutableList.Builder<Version> version = ImmutableList.builder();
|
||||
for (Integer integer : idList) {
|
||||
version.add(Version.fromId(integer));
|
||||
|
@ -68,10 +67,15 @@ public class VersionTestUtil {
|
|||
|
||||
/** Returns the {@link Version} before the {@link Version#CURRENT} */
|
||||
public static Version getPreviousVersion() {
|
||||
Version version = SORTED_VERSIONS.get(1);
|
||||
Version version = SORTED_VERSIONS.get(SORTED_VERSIONS.size() - 2);
|
||||
assert version.before(Version.CURRENT);
|
||||
return version;
|
||||
}
|
||||
|
||||
/** Returns the oldest {@link Version} */
|
||||
public static Version getFirstVersion() {
|
||||
return SORTED_VERSIONS.get(0);
|
||||
}
|
||||
|
||||
/** Returns a random {@link Version} from all available versions. */
|
||||
public static Version randomVersion(Random random) {
|
||||
|
@ -80,11 +84,11 @@ public class VersionTestUtil {
|
|||
|
||||
/** Returns a random {@link Version} between <code>minVersion</code> and <code>maxVersion</code> (inclusive). */
|
||||
public static Version randomVersionBetween(Random random, Version minVersion, Version maxVersion) {
|
||||
int minVersionIndex = SORTED_VERSIONS.size();
|
||||
int minVersionIndex = 0;
|
||||
if (minVersion != null) {
|
||||
minVersionIndex = SORTED_VERSIONS.indexOf(minVersion);
|
||||
}
|
||||
int maxVersionIndex = 0;
|
||||
int maxVersionIndex = SORTED_VERSIONS.size();
|
||||
if (maxVersion != null) {
|
||||
maxVersionIndex = SORTED_VERSIONS.indexOf(maxVersion);
|
||||
}
|
||||
|
@ -92,10 +96,12 @@ public class VersionTestUtil {
|
|||
throw new IllegalArgumentException("minVersion [" + minVersion + "] does not exist.");
|
||||
} else if (maxVersionIndex == -1) {
|
||||
throw new IllegalArgumentException("maxVersion [" + maxVersion + "] does not exist.");
|
||||
} else if (minVersionIndex > maxVersionIndex) {
|
||||
throw new IllegalArgumentException("maxVersion [" + maxVersion + "] cannot be less than minVersion [" + minVersion + "]");
|
||||
} else {
|
||||
// minVersionIndex is inclusive so need to add 1 to this index
|
||||
int range = minVersionIndex + 1 - maxVersionIndex;
|
||||
return SORTED_VERSIONS.get(maxVersionIndex + random.nextInt(range));
|
||||
int range = maxVersionIndex + 1 - minVersionIndex;
|
||||
return SORTED_VERSIONS.get(minVersionIndex + random.nextInt(range));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -64,7 +64,7 @@ import org.elasticsearch.common.io.stream.Streamable;
|
|||
import org.elasticsearch.rest.RestStatus;
|
||||
import org.elasticsearch.search.SearchHit;
|
||||
import org.elasticsearch.search.suggest.Suggest;
|
||||
import org.elasticsearch.test.VersionTestUtil;
|
||||
import org.elasticsearch.test.VersionUtils;
|
||||
import org.elasticsearch.test.engine.AssertingSearcher;
|
||||
import org.elasticsearch.test.engine.MockInternalEngine;
|
||||
import org.elasticsearch.test.engine.MockShadowEngine;
|
||||
|
@ -83,7 +83,7 @@ import java.util.concurrent.TimeUnit;
|
|||
|
||||
import static com.google.common.base.Predicates.isNull;
|
||||
import static org.elasticsearch.test.ElasticsearchTestCase.*;
|
||||
import static org.elasticsearch.test.VersionTestUtil.randomVersion;
|
||||
import static org.elasticsearch.test.VersionUtils.randomVersion;
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
|
@ -587,7 +587,7 @@ public class ElasticsearchAssertions {
|
|||
}
|
||||
|
||||
public static void assertVersionSerializable(Streamable streamable) {
|
||||
assertTrue(Version.CURRENT.after(VersionTestUtil.getPreviousVersion()));
|
||||
assertTrue(Version.CURRENT.after(VersionUtils.getPreviousVersion()));
|
||||
assertVersionSerializable(randomVersion(random()), streamable);
|
||||
}
|
||||
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
package org.elasticsearch.test.rest;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
import org.elasticsearch.Version;
|
||||
import org.elasticsearch.common.logging.ESLogger;
|
||||
import org.elasticsearch.common.logging.Loggers;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
|
@ -145,7 +146,7 @@ public class RestTestExecutionContext implements Closeable {
|
|||
/**
|
||||
* Returns the current es version as a string
|
||||
*/
|
||||
public String esVersion() {
|
||||
public Version esVersion() {
|
||||
return restClient.getEsVersion();
|
||||
}
|
||||
|
||||
|
|
|
@ -25,6 +25,7 @@ import org.apache.http.impl.client.CloseableHttpClient;
|
|||
import org.apache.http.impl.client.HttpClients;
|
||||
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
|
||||
import org.apache.lucene.util.IOUtils;
|
||||
import org.elasticsearch.Version;
|
||||
import org.elasticsearch.client.support.Headers;
|
||||
import org.elasticsearch.common.Strings;
|
||||
import org.elasticsearch.common.logging.ESLogger;
|
||||
|
@ -54,7 +55,7 @@ public class RestClient implements Closeable {
|
|||
private final CloseableHttpClient httpClient;
|
||||
private final Headers headers;
|
||||
private final InetSocketAddress[] addresses;
|
||||
private final String esVersion;
|
||||
private final Version esVersion;
|
||||
|
||||
public RestClient(RestSpec restSpec, Settings settings, InetSocketAddress[] addresses) throws IOException, RestException {
|
||||
assert addresses.length > 0;
|
||||
|
@ -66,7 +67,7 @@ public class RestClient implements Closeable {
|
|||
logger.info("REST client initialized {}, elasticsearch version: [{}]", addresses, esVersion);
|
||||
}
|
||||
|
||||
private String readAndCheckVersion() throws IOException, RestException {
|
||||
private Version readAndCheckVersion() throws IOException, RestException {
|
||||
//we make a manual call here without using callApi method, mainly because we are initializing
|
||||
//and the randomized context doesn't exist for the current thread (would be used to choose the method otherwise)
|
||||
RestApi restApi = restApi("info");
|
||||
|
@ -93,10 +94,10 @@ public class RestClient implements Closeable {
|
|||
}
|
||||
}
|
||||
}
|
||||
return version;
|
||||
return Version.fromString(version);
|
||||
}
|
||||
|
||||
public String getEsVersion() {
|
||||
public Version getEsVersion() {
|
||||
return esVersion;
|
||||
}
|
||||
|
||||
|
|
|
@ -19,9 +19,10 @@
|
|||
package org.elasticsearch.test.rest.section;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import org.elasticsearch.Version;
|
||||
import org.elasticsearch.common.Strings;
|
||||
import org.elasticsearch.test.VersionUtils;
|
||||
import org.elasticsearch.test.rest.support.Features;
|
||||
import org.elasticsearch.test.rest.support.VersionUtils;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
@ -33,20 +34,36 @@ import java.util.List;
|
|||
*/
|
||||
public class SkipSection {
|
||||
|
||||
public static final SkipSection EMPTY = new SkipSection("", Lists.<String>newArrayList(), "");
|
||||
public static final SkipSection EMPTY = new SkipSection();
|
||||
|
||||
private final String version;
|
||||
private final Version lowerVersion;
|
||||
private final Version upperVersion;
|
||||
private final List<String> features;
|
||||
private final String reason;
|
||||
|
||||
private SkipSection() {
|
||||
this.lowerVersion = null;
|
||||
this.upperVersion = null;
|
||||
this.features = Lists.newArrayList();
|
||||
this.reason = null;
|
||||
}
|
||||
|
||||
public SkipSection(String version, List<String> features, String reason) {
|
||||
this.version = version;
|
||||
public SkipSection(String versionRange, List<String> features, String reason) {
|
||||
assert features != null;
|
||||
assert versionRange != null && features.isEmpty() || versionRange == null && features.isEmpty() == false;
|
||||
Version[] versions = parseVersionRange(versionRange);
|
||||
this.lowerVersion = versions[0];
|
||||
this.upperVersion = versions[1];
|
||||
this.features = features;
|
||||
this.reason = reason;
|
||||
}
|
||||
|
||||
public String getVersion() {
|
||||
return version;
|
||||
public Version getLowerVersion() {
|
||||
return lowerVersion;
|
||||
}
|
||||
|
||||
public Version getUpperVersion() {
|
||||
return upperVersion;
|
||||
}
|
||||
|
||||
public List<String> getFeatures() {
|
||||
|
@ -57,27 +74,39 @@ public class SkipSection {
|
|||
return reason;
|
||||
}
|
||||
|
||||
public boolean skip(String currentVersion) {
|
||||
public boolean skip(Version currentVersion) {
|
||||
if (isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (version != null) {
|
||||
return VersionUtils.skipCurrentVersion(version, currentVersion);
|
||||
if (isVersionCheck()) {
|
||||
return currentVersion.onOrAfter(lowerVersion) && currentVersion.onOrBefore(upperVersion);
|
||||
} else {
|
||||
return Features.areAllSupported(features) == false;
|
||||
}
|
||||
|
||||
if (features != null && !this.features.isEmpty()) {
|
||||
return !Features.areAllSupported(this.features);
|
||||
}
|
||||
|
||||
throw new IllegalArgumentException("version or feature should be not null in a non empty skip section");
|
||||
}
|
||||
|
||||
public boolean isVersionCheck() {
|
||||
return Strings.hasLength(version);
|
||||
return features.isEmpty();
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
return EMPTY.equals(this);
|
||||
}
|
||||
|
||||
private Version[] parseVersionRange(String versionRange) {
|
||||
if (versionRange == null) {
|
||||
return new Version[] { null, null };
|
||||
}
|
||||
String[] skipVersions = versionRange.split("-");
|
||||
if (skipVersions.length > 2) {
|
||||
throw new IllegalArgumentException("version range malformed: " + versionRange);
|
||||
}
|
||||
|
||||
String lower = skipVersions[0].trim();
|
||||
String upper = skipVersions[1].trim();
|
||||
return new Version[] {
|
||||
lower.equals("0") ? VersionUtils.getFirstVersion() : Version.fromString(lower),
|
||||
upper.equals("999") ? Version.CURRENT : Version.fromString(upper)
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,87 +0,0 @@
|
|||
/*
|
||||
* Licensed to Elasticsearch under one or more contributor
|
||||
* license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright
|
||||
* ownership. Elasticsearch licenses this file to you 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 org.elasticsearch.test.rest.support;
|
||||
|
||||
public final class VersionUtils {
|
||||
|
||||
private VersionUtils() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses an elasticsearch version string into an int array with an element per part
|
||||
* e.g. 0.90.7 => [0,90,7]
|
||||
*/
|
||||
public static int[] parseVersionNumber(String version) {
|
||||
String[] split = version.split("\\.");
|
||||
//we only take the first 3 parts if there are more, but less is ok too (e.g. 999)
|
||||
int length = Math.min(3, split.length);
|
||||
int[] versionNumber = new int[length];
|
||||
for (int i = 0; i < length; i++) {
|
||||
try {
|
||||
versionNumber[i] = Integer.valueOf(split[i]);
|
||||
} catch (NumberFormatException e) {
|
||||
throw new IllegalArgumentException("version is not a number", e);
|
||||
}
|
||||
|
||||
}
|
||||
return versionNumber;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compares the skip version read from a test fragment with the elasticsearch version
|
||||
* the tests are running against and determines whether the test fragment needs to be skipped
|
||||
*/
|
||||
public static boolean skipCurrentVersion(String skipVersion, String currentVersion) {
|
||||
int[] currentVersionNumber = parseVersionNumber(currentVersion);
|
||||
|
||||
String[] skipVersions = skipVersion.split("-");
|
||||
if (skipVersions.length > 2) {
|
||||
throw new IllegalArgumentException("too many skip versions found");
|
||||
}
|
||||
|
||||
String skipVersionLowerBound = skipVersions[0].trim();
|
||||
String skipVersionUpperBound = skipVersions[1].trim();
|
||||
|
||||
int[] skipVersionLowerBoundNumber = parseVersionNumber(skipVersionLowerBound);
|
||||
int[] skipVersionUpperBoundNumber = parseVersionNumber(skipVersionUpperBound);
|
||||
|
||||
int length = Math.min(skipVersionLowerBoundNumber.length, currentVersionNumber.length);
|
||||
for (int i = 0; i < length; i++) {
|
||||
if (currentVersionNumber[i] < skipVersionLowerBoundNumber[i]) {
|
||||
return false;
|
||||
}
|
||||
if (currentVersionNumber[i] > skipVersionLowerBoundNumber[i]) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
length = Math.min(skipVersionUpperBoundNumber.length, currentVersionNumber.length);
|
||||
for (int i = 0; i < length; i++) {
|
||||
if (currentVersionNumber[i] > skipVersionUpperBoundNumber[i]) {
|
||||
return false;
|
||||
}
|
||||
if (currentVersionNumber[i] < skipVersionUpperBoundNumber[i]) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -18,9 +18,11 @@
|
|||
*/
|
||||
package org.elasticsearch.test.rest.test;
|
||||
|
||||
import org.elasticsearch.Version;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.common.xcontent.yaml.YamlXContent;
|
||||
import org.elasticsearch.test.ElasticsearchTestCase;
|
||||
import org.elasticsearch.test.VersionUtils;
|
||||
import org.elasticsearch.test.rest.parser.RestTestParseException;
|
||||
import org.elasticsearch.test.rest.parser.RestTestSuiteParseContext;
|
||||
import org.elasticsearch.test.rest.parser.RestTestSuiteParser;
|
||||
|
@ -119,7 +121,8 @@ public class RestTestParserTests extends ElasticsearchTestCase {
|
|||
assertThat(restTestSuite.getTestSections().get(1).getName(), equalTo("Get type mapping - pre 1.0"));
|
||||
assertThat(restTestSuite.getTestSections().get(1).getSkipSection().isEmpty(), equalTo(false));
|
||||
assertThat(restTestSuite.getTestSections().get(1).getSkipSection().getReason(), equalTo("for newer versions the index name is always returned"));
|
||||
assertThat(restTestSuite.getTestSections().get(1).getSkipSection().getVersion(), equalTo("0.90.9 - 999"));
|
||||
assertThat(restTestSuite.getTestSections().get(1).getSkipSection().getLowerVersion(), equalTo(Version.V_0_90_9));
|
||||
assertThat(restTestSuite.getTestSections().get(1).getSkipSection().getUpperVersion(), equalTo(Version.CURRENT));
|
||||
assertThat(restTestSuite.getTestSections().get(1).getExecutableSections().size(), equalTo(3));
|
||||
assertThat(restTestSuite.getTestSections().get(1).getExecutableSections().get(0), instanceOf(DoSection.class));
|
||||
doSection = (DoSection) restTestSuite.getTestSections().get(1).getExecutableSections().get(0);
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
*/
|
||||
package org.elasticsearch.test.rest.test;
|
||||
|
||||
import org.elasticsearch.Version;
|
||||
import org.elasticsearch.common.xcontent.yaml.YamlXContent;
|
||||
import org.elasticsearch.test.rest.parser.RestTestSuiteParseContext;
|
||||
import org.elasticsearch.test.rest.parser.SetupSectionParser;
|
||||
|
@ -84,7 +85,8 @@ public class SetupSectionParserTests extends AbstractParserTests {
|
|||
assertThat(setupSection, notNullValue());
|
||||
assertThat(setupSection.getSkipSection().isEmpty(), equalTo(false));
|
||||
assertThat(setupSection.getSkipSection(), notNullValue());
|
||||
assertThat(setupSection.getSkipSection().getVersion(), equalTo("0.90.0 - 0.90.7"));
|
||||
assertThat(setupSection.getSkipSection().getLowerVersion(), equalTo(Version.V_0_90_0));
|
||||
assertThat(setupSection.getSkipSection().getUpperVersion(), equalTo(Version.V_0_90_7));
|
||||
assertThat(setupSection.getSkipSection().getReason(), equalTo("Update doesn't return metadata fields, waiting for #3259"));
|
||||
assertThat(setupSection.getDoSections().size(), equalTo(2));
|
||||
assertThat(setupSection.getDoSections().get(0).getApiCallSection().getApi(), equalTo("index1"));
|
||||
|
|
|
@ -18,7 +18,9 @@
|
|||
*/
|
||||
package org.elasticsearch.test.rest.test;
|
||||
|
||||
import org.elasticsearch.Version;
|
||||
import org.elasticsearch.common.xcontent.yaml.YamlXContent;
|
||||
import org.elasticsearch.test.VersionUtils;
|
||||
import org.elasticsearch.test.rest.parser.RestTestParseException;
|
||||
import org.elasticsearch.test.rest.parser.RestTestSuiteParseContext;
|
||||
import org.elasticsearch.test.rest.parser.SkipSectionParser;
|
||||
|
@ -41,7 +43,8 @@ public class SkipSectionParserTests extends AbstractParserTests {
|
|||
SkipSection skipSection = skipSectionParser.parse(new RestTestSuiteParseContext("api", "suite", parser));
|
||||
|
||||
assertThat(skipSection, notNullValue());
|
||||
assertThat(skipSection.getVersion(), equalTo("0 - 0.90.2"));
|
||||
assertThat(skipSection.getLowerVersion(), equalTo(VersionUtils.getFirstVersion()));
|
||||
assertThat(skipSection.getUpperVersion(), equalTo(Version.V_0_90_2));
|
||||
assertThat(skipSection.getFeatures().size(), equalTo(0));
|
||||
assertThat(skipSection.getReason(), equalTo("Delete ignores the parent param"));
|
||||
}
|
||||
|
@ -57,7 +60,7 @@ public class SkipSectionParserTests extends AbstractParserTests {
|
|||
SkipSection skipSection = skipSectionParser.parse(new RestTestSuiteParseContext("api", "suite", parser));
|
||||
|
||||
assertThat(skipSection, notNullValue());
|
||||
assertThat(skipSection.getVersion(), nullValue());
|
||||
assertThat(skipSection.isVersionCheck(), equalTo(false));
|
||||
assertThat(skipSection.getFeatures().size(), equalTo(1));
|
||||
assertThat(skipSection.getFeatures().get(0), equalTo("regex"));
|
||||
assertThat(skipSection.getReason(), nullValue());
|
||||
|
@ -74,7 +77,7 @@ public class SkipSectionParserTests extends AbstractParserTests {
|
|||
SkipSection skipSection = skipSectionParser.parse(new RestTestSuiteParseContext("api", "suite", parser));
|
||||
|
||||
assertThat(skipSection, notNullValue());
|
||||
assertThat(skipSection.getVersion(), nullValue());
|
||||
assertThat(skipSection.isVersionCheck(), equalTo(false));
|
||||
assertThat(skipSection.getFeatures().size(), equalTo(3));
|
||||
assertThat(skipSection.getFeatures().get(0), equalTo("regex1"));
|
||||
assertThat(skipSection.getFeatures().get(1), equalTo("regex2"));
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
*/
|
||||
package org.elasticsearch.test.rest.test;
|
||||
|
||||
import org.elasticsearch.Version;
|
||||
import org.elasticsearch.common.xcontent.yaml.YamlXContent;
|
||||
import org.elasticsearch.test.rest.parser.RestTestSectionParser;
|
||||
import org.elasticsearch.test.rest.parser.RestTestSuiteParseContext;
|
||||
|
@ -78,7 +79,8 @@ public class TestSectionParserTests extends AbstractParserTests {
|
|||
assertThat(testSection, notNullValue());
|
||||
assertThat(testSection.getName(), equalTo("First test section"));
|
||||
assertThat(testSection.getSkipSection(), notNullValue());
|
||||
assertThat(testSection.getSkipSection().getVersion(), equalTo("0.90.0 - 0.90.7"));
|
||||
assertThat(testSection.getSkipSection().getLowerVersion(), equalTo(Version.V_0_90_0));
|
||||
assertThat(testSection.getSkipSection().getUpperVersion(), equalTo(Version.V_0_90_7));
|
||||
assertThat(testSection.getSkipSection().getReason(), equalTo("Update doesn't return metadata fields, waiting for #3259"));
|
||||
assertThat(testSection.getExecutableSections().size(), equalTo(2));
|
||||
DoSection doSection = (DoSection)testSection.getExecutableSections().get(0);
|
||||
|
|
|
@ -1,120 +0,0 @@
|
|||
/*
|
||||
* Licensed to Elasticsearch under one or more contributor
|
||||
* license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright
|
||||
* ownership. Elasticsearch licenses this file to you 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 org.elasticsearch.test.rest.test;
|
||||
|
||||
import org.elasticsearch.test.ElasticsearchTestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.elasticsearch.test.rest.support.VersionUtils.parseVersionNumber;
|
||||
import static org.elasticsearch.test.rest.support.VersionUtils.skipCurrentVersion;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
|
||||
public class VersionUtilsTests extends ElasticsearchTestCase {
|
||||
|
||||
@Test
|
||||
public void testParseVersionNumber() {
|
||||
|
||||
int[] versionNumber = parseVersionNumber("0.90.6");
|
||||
assertThat(versionNumber.length, equalTo(3));
|
||||
assertThat(versionNumber[0], equalTo(0));
|
||||
assertThat(versionNumber[1], equalTo(90));
|
||||
assertThat(versionNumber[2], equalTo(6));
|
||||
|
||||
versionNumber = parseVersionNumber("0.90.999");
|
||||
assertThat(versionNumber.length, equalTo(3));
|
||||
assertThat(versionNumber[0], equalTo(0));
|
||||
assertThat(versionNumber[1], equalTo(90));
|
||||
assertThat(versionNumber[2], equalTo(999));
|
||||
|
||||
versionNumber = parseVersionNumber("0.20.11");
|
||||
assertThat(versionNumber.length, equalTo(3));
|
||||
assertThat(versionNumber[0], equalTo(0));
|
||||
assertThat(versionNumber[1], equalTo(20));
|
||||
assertThat(versionNumber[2], equalTo(11));
|
||||
|
||||
versionNumber = parseVersionNumber("1.0.0.Beta1");
|
||||
assertThat(versionNumber.length, equalTo(3));
|
||||
assertThat(versionNumber[0], equalTo(1));
|
||||
assertThat(versionNumber[1], equalTo(0));
|
||||
assertThat(versionNumber[2], equalTo(0));
|
||||
|
||||
versionNumber = parseVersionNumber("1.0.0.RC1");
|
||||
assertThat(versionNumber.length, equalTo(3));
|
||||
assertThat(versionNumber[0], equalTo(1));
|
||||
assertThat(versionNumber[1], equalTo(0));
|
||||
assertThat(versionNumber[2], equalTo(0));
|
||||
|
||||
versionNumber = parseVersionNumber("1.0.0");
|
||||
assertThat(versionNumber.length, equalTo(3));
|
||||
assertThat(versionNumber[0], equalTo(1));
|
||||
assertThat(versionNumber[1], equalTo(0));
|
||||
assertThat(versionNumber[2], equalTo(0));
|
||||
|
||||
versionNumber = parseVersionNumber("1.0");
|
||||
assertThat(versionNumber.length, equalTo(2));
|
||||
assertThat(versionNumber[0], equalTo(1));
|
||||
assertThat(versionNumber[1], equalTo(0));
|
||||
|
||||
versionNumber = parseVersionNumber("999");
|
||||
assertThat(versionNumber.length, equalTo(1));
|
||||
assertThat(versionNumber[0], equalTo(999));
|
||||
|
||||
versionNumber = parseVersionNumber("0");
|
||||
assertThat(versionNumber.length, equalTo(1));
|
||||
assertThat(versionNumber[0], equalTo(0));
|
||||
|
||||
try {
|
||||
parseVersionNumber("1.0.Beta1");
|
||||
fail("parseVersionNumber should have thrown an error");
|
||||
} catch(IllegalArgumentException e) {
|
||||
assertThat(e.getMessage(), containsString("version is not a number"));
|
||||
assertThat(e.getCause(), instanceOf(NumberFormatException.class));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSkipCurrentVersion() {
|
||||
assertThat(skipCurrentVersion("0.90.2 - 0.90.6", "0.90.2"), equalTo(true));
|
||||
assertThat(skipCurrentVersion("0.90.2 - 0.90.6", "0.90.3"), equalTo(true));
|
||||
assertThat(skipCurrentVersion("0.90.2 - 0.90.6", "0.90.6"), equalTo(true));
|
||||
|
||||
assertThat(skipCurrentVersion("0.90.2 - 0.90.6", "0.20.10"), equalTo(false));
|
||||
assertThat(skipCurrentVersion("0.90.2 - 0.90.6", "0.90.1"), equalTo(false));
|
||||
assertThat(skipCurrentVersion("0.90.2 - 0.90.6", "0.90.7"), equalTo(false));
|
||||
assertThat(skipCurrentVersion("0.90.2 - 0.90.6", "1.0.0"), equalTo(false));
|
||||
|
||||
assertThat(skipCurrentVersion(" 0.90.2 - 0.90.999 ", "0.90.15"), equalTo(true));
|
||||
assertThat(skipCurrentVersion("0.90.2 - 0.90.999", "1.0.0"), equalTo(false));
|
||||
|
||||
assertThat(skipCurrentVersion("0 - 999", "0.90.15"), equalTo(true));
|
||||
assertThat(skipCurrentVersion("0 - 999", "0.20.1"), equalTo(true));
|
||||
assertThat(skipCurrentVersion("0 - 999", "1.0.0"), equalTo(true));
|
||||
|
||||
assertThat(skipCurrentVersion("0.90.9 - 999", "1.0.0"), equalTo(true));
|
||||
assertThat(skipCurrentVersion("0.90.9 - 999", "0.90.8"), equalTo(false));
|
||||
|
||||
try {
|
||||
assertThat(skipCurrentVersion("0.90.2 - 0.90.999 - 1.0.0", "1.0.0"), equalTo(false));
|
||||
fail("skipCurrentVersion should have thrown an error");
|
||||
} catch(IllegalArgumentException e) {
|
||||
assertThat(e.getMessage(), containsString("too many skip versions found"));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,63 @@
|
|||
/*
|
||||
* Licensed to Elasticsearch under one or more contributor
|
||||
* license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright
|
||||
* ownership. Elasticsearch licenses this file to you 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 org.elasticsearch.test.test;
|
||||
|
||||
import org.elasticsearch.Version;
|
||||
import org.elasticsearch.test.ElasticsearchTestCase;
|
||||
import org.elasticsearch.test.VersionUtils;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class VersionUtilsTests extends ElasticsearchTestCase {
|
||||
|
||||
public void testAllVersionsSorted() {
|
||||
List<Version> allVersions = VersionUtils.allVersions();
|
||||
for (int i = 0, j = 1; j < allVersions.size(); ++i, ++j) {
|
||||
assertTrue(allVersions.get(i).before(allVersions.get(j)));
|
||||
}
|
||||
}
|
||||
|
||||
public void testRandomVersionBetween() {
|
||||
int numReps = randomIntBetween(10, 20);
|
||||
while (numReps-- > 0) {
|
||||
Version v1 = VersionUtils.randomVersion(random());
|
||||
Version v2 = VersionUtils.randomVersion(random());
|
||||
if (v1.after(v2)) {
|
||||
Version tmp = v1;
|
||||
v1 = v2;
|
||||
v2 = tmp;
|
||||
}
|
||||
Version got = VersionUtils.randomVersionBetween(random(), v1, v2);
|
||||
assertTrue(got.onOrAfter(v1));
|
||||
assertTrue(got.onOrBefore(v2));
|
||||
|
||||
got = VersionUtils.randomVersionBetween(random(), null, v2);
|
||||
assertTrue(got.onOrAfter(VersionUtils.getFirstVersion()));
|
||||
assertTrue(got.onOrBefore(v2));
|
||||
|
||||
got = VersionUtils.randomVersionBetween(random(), v1, null);
|
||||
assertTrue(got.onOrAfter(v1));
|
||||
assertTrue(got.onOrBefore(Version.CURRENT));
|
||||
|
||||
got = VersionUtils.randomVersionBetween(random(), v1, v1);
|
||||
assertEquals(got, v1);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -24,7 +24,7 @@ import org.elasticsearch.cluster.node.DiscoveryNode;
|
|||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.test.ElasticsearchIntegrationTest;
|
||||
import org.elasticsearch.test.VersionTestUtil;
|
||||
import org.elasticsearch.test.VersionUtils;
|
||||
import org.elasticsearch.test.hamcrest.ElasticsearchAssertions;
|
||||
import org.elasticsearch.threadpool.ThreadPool;
|
||||
import org.elasticsearch.transport.*;
|
||||
|
@ -55,13 +55,13 @@ public class AssertingLocalTransport extends LocalTransport {
|
|||
|
||||
@Override
|
||||
protected void handleParsedResponse(final TransportResponse response, final TransportResponseHandler handler) {
|
||||
ElasticsearchAssertions.assertVersionSerializable(VersionTestUtil.randomVersionBetween(random, minVersion, maxVersion), response);
|
||||
ElasticsearchAssertions.assertVersionSerializable(VersionUtils.randomVersionBetween(random, minVersion, maxVersion), response);
|
||||
super.handleParsedResponse(response, handler);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendRequest(final DiscoveryNode node, final long requestId, final String action, final TransportRequest request, TransportRequestOptions options) throws IOException, TransportException {
|
||||
ElasticsearchAssertions.assertVersionSerializable(VersionTestUtil.randomVersionBetween(random, minVersion, maxVersion), request);
|
||||
ElasticsearchAssertions.assertVersionSerializable(VersionUtils.randomVersionBetween(random, minVersion, maxVersion), request);
|
||||
super.sendRequest(node, requestId, action, request, options);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue