Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
---
"Test Index and Search locale dependent mappings / dates":

- skip:
version: " - 6.8.4"
reason: JDK9 only supports this with a special sysproperty added in 6.2.0 and the fix for avoiding multiple 8 prefix is in 6.8.5
version: " - 6.8.4, 7.0.0 - 7.4.99"
reason: JDK9 only supports this with a special sysproperty added in 6.2.0 and java.time 8prefix fix is in 6.8.5, 7.5 and master

- do:
indices.create:
index: test_index
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ private static NodeSelector parseVersionSelector(XContentParser parser) throws I
if (false == parser.currentToken().isValue()) {
throw new XContentParseException(parser.getTokenLocation(), "expected [version] to be a value");
}
Version[] range = SkipSection.parseVersionRange(parser.text());
List<VersionRange> skipVersionRanges = SkipSection.parseVersionRanges(parser.text());
return new NodeSelector() {
@Override
public void select(Iterable<Node> nodes) {
Expand All @@ -446,15 +446,16 @@ public void select(Iterable<Node> nodes) {
+ node);
}
Version version = Version.fromString(node.getVersion());
if (false == (version.onOrAfter(range[0]) && version.onOrBefore(range[1]))) {
boolean skip = skipVersionRanges.stream().anyMatch(v -> v.contains(version));
if (false == skip) {
itr.remove();
}
}
}

@Override
public String toString() {
return "version between [" + range[0] + "] and [" + range[1] + "]";
return "version ranges "+skipVersionRanges;
}
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
Expand Down Expand Up @@ -98,33 +99,30 @@ public static SkipSection parse(XContentParser parser) throws IOException {

public static final SkipSection EMPTY = new SkipSection();

private final Version lowerVersion;
private final Version upperVersion;
private final List<VersionRange> versionRanges;
private final List<String> features;
private final String reason;

private SkipSection() {
this.lowerVersion = null;
this.upperVersion = null;
this.versionRanges = new ArrayList<>();
this.features = new ArrayList<>();
this.reason = null;
}

public SkipSection(String versionRange, List<String> features, String reason) {
assert features != null;
Version[] versions = parseVersionRange(versionRange);
this.lowerVersion = versions[0];
this.upperVersion = versions[1];
this.versionRanges = parseVersionRanges(versionRange);
assert versionRanges.isEmpty() == false;
this.features = features;
this.reason = reason;
}

public Version getLowerVersion() {
return lowerVersion;
return versionRanges.get(0).getLower();
}

public Version getUpperVersion() {
return upperVersion;
return versionRanges.get(versionRanges.size() - 1).getUpper();
}

public List<String> getFeatures() {
Expand All @@ -139,10 +137,8 @@ public boolean skip(Version currentVersion) {
if (isEmpty()) {
return false;
}
boolean skip = lowerVersion != null && upperVersion != null && currentVersion.onOrAfter(lowerVersion)
&& currentVersion.onOrBefore(upperVersion);
skip |= Features.areAllSupported(features) == false;
return skip;
boolean skip = versionRanges.stream().anyMatch(range -> range.contains(currentVersion));
return skip || Features.areAllSupported(features) == false;
}

public boolean isVersionCheck() {
Expand All @@ -153,24 +149,30 @@ public boolean isEmpty() {
return EMPTY.equals(this);
}

static Version[] parseVersionRange(String versionRange) {
if (versionRange == null) {
return new Version[] { null, null };
static List<VersionRange> parseVersionRanges(String rawRanges) {
if (rawRanges == null) {
return Collections.singletonList(new VersionRange(null, null));
}
if (versionRange.trim().equals("all")) {
return new Version[]{VersionUtils.getFirstVersion(), Version.CURRENT};
}
String[] skipVersions = versionRange.split("-");
if (skipVersions.length > 2) {
throw new IllegalArgumentException("version range malformed: " + versionRange);
if (rawRanges.trim().equals("all")) {
return Collections.singletonList(new VersionRange(VersionUtils.getFirstVersion(), Version.CURRENT));
}
String[] ranges = rawRanges.split(",");
List<VersionRange> versionRanges = new ArrayList<>();
for (String rawRange : ranges) {
String[] skipVersions = rawRange.split("-", -1);
if (skipVersions.length > 2) {
throw new IllegalArgumentException("version range malformed: " + rawRanges);
}

String lower = skipVersions[0].trim();
String upper = skipVersions[1].trim();
return new Version[] {
lower.isEmpty() ? VersionUtils.getFirstVersion() : Version.fromString(lower),
upper.isEmpty() ? Version.CURRENT : Version.fromString(upper)
};
String lower = skipVersions[0].trim();
String upper = skipVersions[1].trim();
VersionRange versionRange = new VersionRange(
lower.isEmpty() ? VersionUtils.getFirstVersion() : Version.fromString(lower),
upper.isEmpty() ? Version.CURRENT : Version.fromString(upper)
);
versionRanges.add(versionRange);
}
return versionRanges;
}

public String getSkipMessage(String description) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* 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.yaml.section;

import org.elasticsearch.Version;

public class VersionRange {
private final Version lower;
private final Version upper;

public VersionRange(Version lower, Version upper) {
this.lower = lower;
this.upper = upper;
}

public Version getLower() {
return lower;
}

public Version getUpper() {
return upper;
}

public boolean contains(Version currentVersion) {
return lower != null && upper != null && currentVersion.onOrAfter(lower)
&& currentVersion.onOrBefore(upper);
}

@Override
public String toString() {
return "[" + lower + " - " + upper + "]";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,26 @@

public class SkipSectionTests extends AbstractClientYamlTestFragmentParserTestCase {

public void testSkipMultiRange() {
SkipSection section = new SkipSection("6.0.0 - 6.1.0, 7.1.0 - 7.5.0",
Collections.emptyList() , "foobar");

assertFalse(section.skip(Version.CURRENT));
assertFalse(section.skip(Version.fromString("6.2.0")));
assertFalse(section.skip(Version.fromString("7.0.0")));
assertFalse(section.skip(Version.fromString("7.6.0")));

assertTrue(section.skip(Version.fromString("6.0.0")));
assertTrue(section.skip(Version.fromString("6.1.0")));
assertTrue(section.skip(Version.fromString("7.1.0")));
assertTrue(section.skip(Version.fromString("7.5.0")));

section = new SkipSection("- 7.1.0, 7.2.0 - 7.5.0",
Collections.emptyList() , "foobar");
assertTrue(section.skip(Version.fromString("7.0.0")));
assertTrue(section.skip(Version.fromString("7.3.0")));
}

public void testSkip() {
SkipSection section = new SkipSection("6.0.0 - 6.1.0",
randomBoolean() ? Collections.emptyList() : Collections.singletonList("warnings"), "foobar");
Expand Down