Test that gradle and Java version types match (#24943)
Both gradle and java code attempt to infer the type of a each Version constant in Version.java. It is super important that they infer that each constant has the same type. If they disagree we might accidentally not be testing backwards compatibility for some version. This adds a test to make sure that they agree, modulo known and accepted differences (mostly around alphas). It also changes the minimum wire compatible version from the released 5.4.0 to the unreleased 5.5.0 as that lines up with the gradle logic. Relates to #24798 Note that the gradle and java version logic doesn't actually match so this contains a hack to make it *look* like it matches. Since this is a start, I'm merging it and going to work on some followups to make the logic actually match.....
This commit is contained in:
parent
57b4002357
commit
190f5dce10
|
@ -68,3 +68,8 @@ task namingConventionsMain(type: org.elasticsearch.gradle.precommit.NamingConven
|
|||
checkForTestsInMain = true
|
||||
}
|
||||
precommit.dependsOn namingConventionsMain
|
||||
|
||||
test.configure {
|
||||
systemProperty 'tests.gradle_index_compat_versions', indexCompatVersions.join(',')
|
||||
systemProperty 'tests.gradle_wire_compat_versions', wireCompatVersions.join(',')
|
||||
}
|
||||
|
|
|
@ -21,11 +21,13 @@ package org.elasticsearch.test;
|
|||
import org.elasticsearch.Version;
|
||||
import org.elasticsearch.common.collect.Tuple;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import static java.util.Collections.emptyList;
|
||||
import static java.util.Collections.singletonList;
|
||||
import static java.util.stream.Collectors.toList;
|
||||
|
||||
public class VersionUtilsTests extends ESTestCase {
|
||||
|
||||
|
@ -158,5 +160,73 @@ public class VersionUtilsTests extends ESTestCase {
|
|||
assertEquals(Arrays.asList(TestUnstableBranch.V_5_3_2, TestUnstableBranch.V_5_4_0), unreleased);
|
||||
}
|
||||
|
||||
// TODO add a test that compares gradle and VersionUtils.java in a followup
|
||||
/**
|
||||
* Tests that {@link Version#minimumCompatibilityVersion()} and {@link VersionUtils#allReleasedVersions()}
|
||||
* agree with the list of wire and index compatible versions we build in gradle.
|
||||
*/
|
||||
public void testGradleVersionsMatchVerionUtils() {
|
||||
// First check the index compatible versions
|
||||
VersionsFromProperty indexCompatible = new VersionsFromProperty("tests.gradle_index_compat_versions");
|
||||
|
||||
List<Version> released = VersionUtils.allReleasedVersions().stream()
|
||||
/* We skip alphas, betas, and the like in gradle because they don't have
|
||||
* backwards compatibility guarantees even though they are technically
|
||||
* released. */
|
||||
.filter(Version::isRelease)
|
||||
.collect(toList());
|
||||
List<String> releasedIndexCompatible = released.stream()
|
||||
.map(Object::toString)
|
||||
.collect(toList());
|
||||
assertEquals(releasedIndexCompatible, indexCompatible.released);
|
||||
|
||||
List<String> unreleasedIndexCompatible = VersionUtils.allUnreleasedVersions().stream()
|
||||
.map(Object::toString)
|
||||
.collect(toList());
|
||||
assertEquals(unreleasedIndexCompatible, indexCompatible.unreleased);
|
||||
|
||||
// Now the wire compatible versions
|
||||
VersionsFromProperty wireCompatible = new VersionsFromProperty("tests.gradle_wire_compat_versions");
|
||||
|
||||
// Big horrible hack:
|
||||
// This *should* be:
|
||||
// Version minimumCompatibleVersion = Version.CURRENT.minimumCompatibilityVersion();
|
||||
// But instead it is:
|
||||
Version minimumCompatibleVersion = Version.V_5_5_0;
|
||||
// Because things blow up all over the place if the minimum compatible version isn't released.
|
||||
// We'll fix this very, very soon. But for now, this hack.
|
||||
// end big horrible hack
|
||||
List<String> releasedWireCompatible = released.stream()
|
||||
.filter(v -> v.onOrAfter(minimumCompatibleVersion))
|
||||
.map(Object::toString)
|
||||
.collect(toList());
|
||||
assertEquals(releasedWireCompatible, wireCompatible.released);
|
||||
|
||||
List<String> unreleasedWireCompatible = VersionUtils.allUnreleasedVersions().stream()
|
||||
.filter(v -> v.onOrAfter(minimumCompatibleVersion))
|
||||
.map(Object::toString)
|
||||
.collect(toList());
|
||||
assertEquals(unreleasedWireCompatible, wireCompatible.unreleased);
|
||||
}
|
||||
|
||||
/**
|
||||
* Read a versions system property as set by gradle into a tuple of {@code (releasedVersion, unreleasedVersion)}.
|
||||
*/
|
||||
private class VersionsFromProperty {
|
||||
private final List<String> released = new ArrayList<>();
|
||||
private final List<String> unreleased = new ArrayList<>();
|
||||
|
||||
private VersionsFromProperty(String property) {
|
||||
String versions = System.getProperty(property);
|
||||
assertNotNull("Couldn't find [" + property + "]. Gradle should set these before running the tests.", versions);
|
||||
logger.info("Looked up versions [{}={}]", property, versions);
|
||||
|
||||
for (String version : versions.split(",")) {
|
||||
if (version.endsWith("-SNAPSHOT")) {
|
||||
unreleased.add(version.replace("-SNAPSHOT", ""));
|
||||
} else {
|
||||
released.add(version);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue