From 054711dd885e652108820bfd9f1884a818d7fd33 Mon Sep 17 00:00:00 2001 From: Jason Tedor Date: Mon, 18 Dec 2017 13:17:13 -0500 Subject: [PATCH] More refinement of version is compatible test This test further refines the version is compatible test, adding additional handling of edge cases. --- .../java/org/elasticsearch/VersionTests.java | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/core/src/test/java/org/elasticsearch/VersionTests.java b/core/src/test/java/org/elasticsearch/VersionTests.java index 98566b9c507..1f6006dd2df 100644 --- a/core/src/test/java/org/elasticsearch/VersionTests.java +++ b/core/src/test/java/org/elasticsearch/VersionTests.java @@ -344,23 +344,25 @@ public class VersionTests extends ESTestCase { final Version currentMajorVersion = Version.fromId(Version.CURRENT.major * 1000000 + 99); final Version currentOrNextMajorVersion; - if (Version.CURRENT.after(currentMajorVersion)) { + if (Version.CURRENT.minor > 0) { currentOrNextMajorVersion = Version.fromId((Version.CURRENT.major + 1) * 1000000 + 99); } else { - assert Version.CURRENT.minor == 0; - currentOrNextMajorVersion = Version.CURRENT; + currentOrNextMajorVersion = currentMajorVersion; } - final List previousMajorVersions = + final Version lastMinorFromPreviousMajor = VersionUtils .allVersions() .stream() - .filter(v -> v.before(currentOrNextMajorVersion)) - .collect(Collectors.toList()); - final Version lastReleasedVersionFromPreviousMajor = previousMajorVersions.get(previousMajorVersions.size() - 1); + .filter(v -> v.major == currentOrNextMajorVersion.major - 1) + .max(Version::compareTo) + .orElseThrow( + () -> new IllegalStateException("expected previous minor version for [" + currentOrNextMajorVersion + "]")); final Version previousMinorVersion = VersionUtils.getPreviousMinorVersion(); - assert lastReleasedVersionFromPreviousMajor.major == previousMinorVersion.major; - boolean isCompatible = previousMinorVersion.minor == lastReleasedVersionFromPreviousMajor.minor; + assert previousMinorVersion.major == currentOrNextMajorVersion.major + || previousMinorVersion.major == lastMinorFromPreviousMajor.major; + boolean isCompatible = previousMinorVersion.major == currentOrNextMajorVersion.major + || previousMinorVersion.minor == lastMinorFromPreviousMajor.minor; final String message = String.format( Locale.ROOT,