Skip to content

Instantly share code, notes, and snippets.

@hub-cap
Created February 2, 2018 19:11
Show Gist options
  • Save hub-cap/3a87a05090590d79af17bbafe547ddae to your computer and use it in GitHub Desktop.
Save hub-cap/3a87a05090590d79af17bbafe547ddae to your computer and use it in GitHub Desktop.
package org.elasticsearch.gradle
class VersionCollectionTest extends GroovyTestCase {
String formatVersion(String version) {
return " public static final Version V_${version.replaceAll("\\.", "_")} "
}
def allVersions = [formatVersion('5.0.0'), formatVersion('5.0.0_alpha1'), formatVersion('5.0.0_alpha2'), formatVersion('5.0.0_beta1'),
formatVersion('5.0.0_rc1'),formatVersion('5.0.0_rc2'),formatVersion('5.0.1'), formatVersion('5.0.2'),
formatVersion('5.1.1'), formatVersion('5.1.2'), formatVersion('5.2.0'), formatVersion('5.2.1'), formatVersion('6.0.0'),
formatVersion('6.0.1'), formatVersion('6.1.0'), formatVersion('6.1.1'), formatVersion('6.2.0'), formatVersion('6.3.0'),
formatVersion('7.0.0_alpha1'), formatVersion('7.0.0_alpha2')]
void testWireCompatSnapshotsContainsTheProperValues() {
VersionCollection vc = new VersionCollection(allVersions)
assertNotNull(vc)
assertEquals(vc.snapshotVersionsWireCompatibleWithCurrent.size(), 1)
assertEquals(vc.snapshotVersionsWireCompatibleWithCurrent.first(), Version.fromString("6.3.0-SNAPSHOT"))
}
void testIndexCompatSnapshotsContainsTheProperValues() {
VersionCollection vc = new VersionCollection(allVersions)
assertNotNull(vc)
assertEquals(vc.snapshotVersionsIndexCompatibleWithCurrent.size(), 3)
assertTrue(vc.snapshotVersionsIndexCompatibleWithCurrent.contains(Version.fromString("6.3.0-SNAPSHOT")))
assertTrue(vc.snapshotVersionsIndexCompatibleWithCurrent.contains(Version.fromString("6.2.0-SNAPSHOT")))
assertTrue(vc.snapshotVersionsIndexCompatibleWithCurrent.contains(Version.fromString("6.1.2-SNAPSHOT")))
}
void testAgainstMajorUnreleasedWithExistingStagedMinorRelease() {
VersionCollection vc = new VersionCollection(allVersions)
assertNotNull(vc)
assertEquals(vc.nextMinorSnapshot, Version.fromString("6.3.0-SNAPSHOT"))
assertEquals(vc.stagedMinorSnapshot, Version.fromString("6.2.0-SNAPSHOT"))
assertEquals(vc.nextBugfixSnapshot, Version.fromString("6.1.1-SNAPSHOT"))
assertEquals(vc.maintenanceBugfixSnapshot, Version.fromString("5.2.1-SNAPSHOT"))
vc.versionsIndexCompatibleWithCurrent.containsAll(vc.versions)
// This should contain the same list sans the current version
List indexCompatList = [Version.fromString("6.0.0"), Version.fromString("6.0.1"),
Version.fromString("6.1.0"), Version.fromString("6.1.1-SNAPSHOT"),
Version.fromString("6.2.0-SNAPSHOT"), Version.fromString("6.3.0-SNAPSHOT")]
assertTrue(indexCompatList.containsAll(vc.versionsIndexCompatibleWithCurrent))
assertTrue(vc.versionsIndexCompatibleWithCurrent.containsAll(indexCompatList))
List wireCompatList = [Version.fromString("6.3.0-SNAPSHOT")]
assertTrue(wireCompatList.containsAll(vc.versionsWireCompatibleWithCurrent))
assertTrue(vc.versionsWireCompatibleWithCurrent.containsAll(wireCompatList))
}
void testAgainstMinorReleasedBranch() {
List localVersion = allVersions.clone()
localVersion.removeAll { it.toString().contains('7_0_0')} // remove all the 7.x so that the actual version is 6.3 (6.x)
VersionCollection vc = new VersionCollection(localVersion)
assertNotNull(vc)
assertEquals(vc.nextMinorSnapshot, null)
assertEquals(vc.stagedMinorSnapshot, Version.fromString("6.2.0-SNAPSHOT"))
assertEquals(vc.nextBugfixSnapshot, Version.fromString("6.1.1-SNAPSHOT"))
assertEquals(vc.maintenanceBugfixSnapshot, Version.fromString("5.2.1-SNAPSHOT"))
// This should contain the same list sans the current version
List indexCompatList = vc.versions.subList(0, vc.versions.size() - 1)
assertTrue(indexCompatList.containsAll(vc.versionsIndexCompatibleWithCurrent))
assertTrue(vc.versionsIndexCompatibleWithCurrent.containsAll(indexCompatList))
List wireCompatList = [Version.fromString("5.2.0"), Version.fromString("5.2.1-SNAPSHOT"), Version.fromString("6.0.0"),
Version.fromString("6.0.1"), Version.fromString("6.1.0"), Version.fromString("6.1.1-SNAPSHOT"),
Version.fromString("6.2.0-SNAPSHOT")]
assertTrue(wireCompatList.containsAll(vc.versionsWireCompatibleWithCurrent))
assertTrue(vc.versionsWireCompatibleWithCurrent.containsAll(wireCompatList))
}
void testAgainstMinorReleasedBranchNoStagedMinor() {
List localVersion = allVersions.clone()
// remove all the 7.x and add a 6.2.1 which means 6.2 was released
localVersion.removeAll { it.toString().contains('7_0_0')}
localVersion.add(formatVersion('6.2.1'))
VersionCollection vc = new VersionCollection(localVersion)
assertNotNull(vc)
assertEquals(vc.nextMinorSnapshot, null)
assertEquals(vc.stagedMinorSnapshot, null)
assertEquals(vc.nextBugfixSnapshot, Version.fromString("6.2.1-SNAPSHOT"))
assertEquals(vc.maintenanceBugfixSnapshot, Version.fromString("5.2.1-SNAPSHOT"))
// This should contain the same list sans the current version
List indexCompatList = vc.versions.subList(0, vc.versions.size() - 1)
assertTrue(indexCompatList.containsAll(vc.versionsIndexCompatibleWithCurrent))
assertTrue(vc.versionsIndexCompatibleWithCurrent.containsAll(indexCompatList))
List wireCompatList = [Version.fromString("5.2.0"), Version.fromString("5.2.1-SNAPSHOT"), Version.fromString("6.0.0"),
Version.fromString("6.0.1"), Version.fromString("6.1.0"), Version.fromString("6.1.1"),
Version.fromString("6.2.0"), Version.fromString("6.2.1-SNAPSHOT")]
assertTrue(wireCompatList.containsAll(vc.versionsWireCompatibleWithCurrent))
assertTrue(vc.versionsWireCompatibleWithCurrent.containsAll(wireCompatList))
}
/**
* This validates the logic of being on a released minor branch. At the time of writing, 6.2 is unreleased, so this is equivalent of being
* on 6.1.
*/
void testAgainstOldMinor() {
List localVersion = allVersions.clone()
// remove the 7 alphas and the ones greater than 6.1
localVersion.removeAll { it.toString().contains('7_0_0') || it.toString().contains('V_6_2') || it.toString().contains('V_6_3') }
VersionCollection vc = new VersionCollection(localVersion)
assertNotNull(vc)
assertEquals(vc.nextMinorSnapshot, null)
assertEquals(vc.stagedMinorSnapshot, null)
assertEquals(vc.nextBugfixSnapshot, null)
assertEquals(vc.maintenanceBugfixSnapshot, Version.fromString("5.2.1-SNAPSHOT"))
// This should contain the same list sans the current version
List indexCompatList = vc.versions.subList(0, vc.versions.size() - 1)
assertTrue(indexCompatList.containsAll(vc.versionsIndexCompatibleWithCurrent))
assertTrue(vc.versionsIndexCompatibleWithCurrent.containsAll(indexCompatList))
List wireCompatList = [Version.fromString("5.2.0"), Version.fromString("5.2.1-SNAPSHOT"), Version.fromString("6.0.0"),
Version.fromString("6.0.1"), Version.fromString("6.1.0")]
assertTrue(wireCompatList.containsAll(vc.versionsWireCompatibleWithCurrent))
assertTrue(vc.versionsWireCompatibleWithCurrent.containsAll(wireCompatList))
}
void testFloorOfWireCompatVersions() {
List localVersion = [formatVersion('2.0.0'), formatVersion('2.0.1'), formatVersion('2.1.0'), formatVersion('2.1.1'),
formatVersion('5.0.0'), formatVersion('5.0.1'), formatVersion('5.1.0'), formatVersion('5.1.1'),
formatVersion('5.2.0'),formatVersion('5.2.1'),formatVersion('5.3.0'),formatVersion('5.3.1'),
formatVersion('5.3.2')]
VersionCollection vc = new VersionCollection(localVersion)
assertNotNull(vc)
assertEquals(vc.maintenanceBugfixSnapshot, Version.fromString("2.1.1-SNAPSHOT"))
vc.snapshotVersionsIndexCompatibleWithCurrent
// ensure none of the 2.x snapshots appear here
assertEquals(vc.snapshotVersionsWireCompatibleWithCurrent.size(), 0)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment