More refinement of version is compatible test

This test further refines the version is compatible test, adding
additional handling of edge cases.
This commit is contained in:
Jason Tedor 2017-12-18 13:17:13 -05:00
parent 0d99fadd2a
commit 054711dd88
1 changed files with 11 additions and 9 deletions

View File

@ -344,23 +344,25 @@ public class VersionTests extends ESTestCase {
final Version currentMajorVersion = Version.fromId(Version.CURRENT.major * 1000000 + 99); final Version currentMajorVersion = Version.fromId(Version.CURRENT.major * 1000000 + 99);
final Version currentOrNextMajorVersion; final Version currentOrNextMajorVersion;
if (Version.CURRENT.after(currentMajorVersion)) { if (Version.CURRENT.minor > 0) {
currentOrNextMajorVersion = Version.fromId((Version.CURRENT.major + 1) * 1000000 + 99); currentOrNextMajorVersion = Version.fromId((Version.CURRENT.major + 1) * 1000000 + 99);
} else { } else {
assert Version.CURRENT.minor == 0; currentOrNextMajorVersion = currentMajorVersion;
currentOrNextMajorVersion = Version.CURRENT;
} }
final List<Version> previousMajorVersions = final Version lastMinorFromPreviousMajor =
VersionUtils VersionUtils
.allVersions() .allVersions()
.stream() .stream()
.filter(v -> v.before(currentOrNextMajorVersion)) .filter(v -> v.major == currentOrNextMajorVersion.major - 1)
.collect(Collectors.toList()); .max(Version::compareTo)
final Version lastReleasedVersionFromPreviousMajor = previousMajorVersions.get(previousMajorVersions.size() - 1); .orElseThrow(
() -> new IllegalStateException("expected previous minor version for [" + currentOrNextMajorVersion + "]"));
final Version previousMinorVersion = VersionUtils.getPreviousMinorVersion(); 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( final String message = String.format(
Locale.ROOT, Locale.ROOT,