Skip to content

Commit 190f5dc

Browse files
authored
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.....
1 parent 57b4002 commit 190f5dc

File tree

2 files changed

+76
-1
lines changed

2 files changed

+76
-1
lines changed

test/framework/build.gradle

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,8 @@ task namingConventionsMain(type: org.elasticsearch.gradle.precommit.NamingConven
6868
checkForTestsInMain = true
6969
}
7070
precommit.dependsOn namingConventionsMain
71+
72+
test.configure {
73+
systemProperty 'tests.gradle_index_compat_versions', indexCompatVersions.join(',')
74+
systemProperty 'tests.gradle_wire_compat_versions', wireCompatVersions.join(',')
75+
}

test/framework/src/test/java/org/elasticsearch/test/VersionUtilsTests.java

Lines changed: 71 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,13 @@
2121
import org.elasticsearch.Version;
2222
import org.elasticsearch.common.collect.Tuple;
2323

24+
import java.util.ArrayList;
2425
import java.util.Arrays;
2526
import java.util.List;
2627

2728
import static java.util.Collections.emptyList;
2829
import static java.util.Collections.singletonList;
30+
import static java.util.stream.Collectors.toList;
2931

3032
public class VersionUtilsTests extends ESTestCase {
3133

@@ -158,5 +160,73 @@ public void testResolveReleasedVersionsForUnstableBranch() {
158160
assertEquals(Arrays.asList(TestUnstableBranch.V_5_3_2, TestUnstableBranch.V_5_4_0), unreleased);
159161
}
160162

161-
// TODO add a test that compares gradle and VersionUtils.java in a followup
163+
/**
164+
* Tests that {@link Version#minimumCompatibilityVersion()} and {@link VersionUtils#allReleasedVersions()}
165+
* agree with the list of wire and index compatible versions we build in gradle.
166+
*/
167+
public void testGradleVersionsMatchVerionUtils() {
168+
// First check the index compatible versions
169+
VersionsFromProperty indexCompatible = new VersionsFromProperty("tests.gradle_index_compat_versions");
170+
171+
List<Version> released = VersionUtils.allReleasedVersions().stream()
172+
/* We skip alphas, betas, and the like in gradle because they don't have
173+
* backwards compatibility guarantees even though they are technically
174+
* released. */
175+
.filter(Version::isRelease)
176+
.collect(toList());
177+
List<String> releasedIndexCompatible = released.stream()
178+
.map(Object::toString)
179+
.collect(toList());
180+
assertEquals(releasedIndexCompatible, indexCompatible.released);
181+
182+
List<String> unreleasedIndexCompatible = VersionUtils.allUnreleasedVersions().stream()
183+
.map(Object::toString)
184+
.collect(toList());
185+
assertEquals(unreleasedIndexCompatible, indexCompatible.unreleased);
186+
187+
// Now the wire compatible versions
188+
VersionsFromProperty wireCompatible = new VersionsFromProperty("tests.gradle_wire_compat_versions");
189+
190+
// Big horrible hack:
191+
// This *should* be:
192+
// Version minimumCompatibleVersion = Version.CURRENT.minimumCompatibilityVersion();
193+
// But instead it is:
194+
Version minimumCompatibleVersion = Version.V_5_5_0;
195+
// Because things blow up all over the place if the minimum compatible version isn't released.
196+
// We'll fix this very, very soon. But for now, this hack.
197+
// end big horrible hack
198+
List<String> releasedWireCompatible = released.stream()
199+
.filter(v -> v.onOrAfter(minimumCompatibleVersion))
200+
.map(Object::toString)
201+
.collect(toList());
202+
assertEquals(releasedWireCompatible, wireCompatible.released);
203+
204+
List<String> unreleasedWireCompatible = VersionUtils.allUnreleasedVersions().stream()
205+
.filter(v -> v.onOrAfter(minimumCompatibleVersion))
206+
.map(Object::toString)
207+
.collect(toList());
208+
assertEquals(unreleasedWireCompatible, wireCompatible.unreleased);
209+
}
210+
211+
/**
212+
* Read a versions system property as set by gradle into a tuple of {@code (releasedVersion, unreleasedVersion)}.
213+
*/
214+
private class VersionsFromProperty {
215+
private final List<String> released = new ArrayList<>();
216+
private final List<String> unreleased = new ArrayList<>();
217+
218+
private VersionsFromProperty(String property) {
219+
String versions = System.getProperty(property);
220+
assertNotNull("Couldn't find [" + property + "]. Gradle should set these before running the tests.", versions);
221+
logger.info("Looked up versions [{}={}]", property, versions);
222+
223+
for (String version : versions.split(",")) {
224+
if (version.endsWith("-SNAPSHOT")) {
225+
unreleased.add(version.replace("-SNAPSHOT", ""));
226+
} else {
227+
released.add(version);
228+
}
229+
}
230+
}
231+
}
162232
}

0 commit comments

Comments
 (0)