Fix version tests for release tests

This commit fixes the version tests for release tests. The problem here
is that during release tests all version should be treated as released
so the assertions must be modified accordingly.

Relates #27815
This commit is contained in:
Jason Tedor 2017-12-18 08:19:35 -05:00
parent 9cd69e7ec1
commit 76771242e8
3 changed files with 200 additions and 38 deletions

View File

@ -20,6 +20,7 @@
package org.elasticsearch;
import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.common.Booleans;
import org.elasticsearch.common.lucene.Lucene;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.test.ESTestCase;
@ -339,8 +340,11 @@ public class VersionTests extends ESTestCase {
assertFalse(isCompatible(Version.fromId(2000099), Version.V_5_0_0));
assertFalse(isCompatible(Version.fromString("6.0.0"), Version.fromString("7.0.0")));
assertFalse(isCompatible(Version.fromString("6.0.0-alpha1"), Version.fromString("7.0.0")));
assertFalse("only compatible with the latest minor",
isCompatible(VersionUtils.getPreviousMinorVersion(), Version.fromString("7.0.0")));
final boolean buildSnapshot = Booleans.parseBoolean(System.getProperty("build.snapshot", "true"));
assertThat(
"[" + VersionUtils.getPreviousMinorVersion() + "] should" + (!buildSnapshot ? " not" : "") + " be compatible with 7.0.0",
isCompatible(VersionUtils.getPreviousMinorVersion(), Version.fromString("7.0.0")),
equalTo(!buildSnapshot));
assertFalse(isCompatible(Version.V_5_0_0, Version.fromString("6.0.0")));
assertFalse(isCompatible(Version.V_5_0_0, Version.fromString("7.0.0")));

View File

@ -20,6 +20,7 @@
package org.elasticsearch.test;
import org.elasticsearch.Version;
import org.elasticsearch.common.Booleans;
import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.collect.Tuple;
@ -47,6 +48,11 @@ public class VersionUtils {
*/
static Tuple<List<Version>, List<Version>> resolveReleasedVersions(Version current, Class<?> versionClass) {
List<Version> versions = Version.getDeclaredVersions(versionClass);
if (!Booleans.parseBoolean(System.getProperty("build.snapshot", "true"))) {
return Tuple.tuple(versions, Collections.emptyList());
}
Version last = versions.remove(versions.size() - 1);
assert last.equals(current) : "The highest version must be the current one "
+ "but was [" + last + "] and current was [" + current + "]";

View File

@ -19,16 +19,19 @@
package org.elasticsearch.test;
import org.elasticsearch.Version;
import org.elasticsearch.common.Booleans;
import org.elasticsearch.common.collect.Tuple;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.List;
import static java.util.Collections.singletonList;
import static java.util.stream.Collectors.toCollection;
import static java.util.stream.Collectors.toList;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
import static org.hamcrest.Matchers.lessThanOrEqualTo;
@ -94,11 +97,13 @@ public class VersionUtilsTests extends ESTestCase {
got = VersionUtils.randomVersionBetween(random(), Version.CURRENT, null);
assertEquals(got, Version.CURRENT);
// max or min can be an unreleased version
Version unreleased = randomFrom(VersionUtils.allUnreleasedVersions());
assertThat(VersionUtils.randomVersionBetween(random(), null, unreleased), lessThanOrEqualTo(unreleased));
assertThat(VersionUtils.randomVersionBetween(random(), unreleased, null), greaterThanOrEqualTo(unreleased));
assertEquals(unreleased, VersionUtils.randomVersionBetween(random(), unreleased, unreleased));
if (Booleans.parseBoolean(System.getProperty("build.snapshot", "true"))) {
// max or min can be an unreleased version
final Version unreleased = randomFrom(VersionUtils.allUnreleasedVersions());
assertThat(VersionUtils.randomVersionBetween(random(), null, unreleased), lessThanOrEqualTo(unreleased));
assertThat(VersionUtils.randomVersionBetween(random(), unreleased, null), greaterThanOrEqualTo(unreleased));
assertEquals(unreleased, VersionUtils.randomVersionBetween(random(), unreleased, unreleased));
}
}
public static class TestReleaseBranch {
@ -113,9 +118,28 @@ public class VersionUtilsTests extends ESTestCase {
Tuple<List<Version>, List<Version>> t = VersionUtils.resolveReleasedVersions(TestReleaseBranch.CURRENT, TestReleaseBranch.class);
List<Version> released = t.v1();
List<Version> unreleased = t.v2();
assertEquals(Arrays.asList(TestReleaseBranch.V_5_3_0, TestReleaseBranch.V_5_3_1, TestReleaseBranch.V_5_3_2,
TestReleaseBranch.V_5_4_0), released);
assertEquals(singletonList(TestReleaseBranch.V_5_4_1), unreleased);
final List<Version> expectedReleased;
final List<Version> expectedUnreleased;
if (Booleans.parseBoolean(System.getProperty("build.snapshot", "true"))) {
expectedReleased = Arrays.asList(
TestReleaseBranch.V_5_3_0,
TestReleaseBranch.V_5_3_1,
TestReleaseBranch.V_5_3_2,
TestReleaseBranch.V_5_4_0);
expectedUnreleased = Collections.singletonList(TestReleaseBranch.V_5_4_1);
} else {
expectedReleased = Arrays.asList(
TestReleaseBranch.V_5_3_0,
TestReleaseBranch.V_5_3_1,
TestReleaseBranch.V_5_3_2,
TestReleaseBranch.V_5_4_0,
TestReleaseBranch.V_5_4_1);
expectedUnreleased = Collections.emptyList();
}
assertThat(released, equalTo(expectedReleased));
assertThat(unreleased, equalTo(expectedUnreleased));
}
public static class TestStableBranch {
@ -130,8 +154,20 @@ public class VersionUtilsTests extends ESTestCase {
TestStableBranch.class);
List<Version> released = t.v1();
List<Version> unreleased = t.v2();
assertEquals(Arrays.asList(TestStableBranch.V_5_3_0, TestStableBranch.V_5_3_1), released);
assertEquals(Arrays.asList(TestStableBranch.V_5_3_2, TestStableBranch.V_5_4_0), unreleased);
final List<Version> expectedReleased;
final List<Version> expectedUnreleased;
if (Booleans.parseBoolean(System.getProperty("build.snapshot", "true"))) {
expectedReleased = Arrays.asList(TestStableBranch.V_5_3_0, TestStableBranch.V_5_3_1);
expectedUnreleased = Arrays.asList(TestStableBranch.V_5_3_2, TestStableBranch.V_5_4_0);
} else {
expectedReleased =
Arrays.asList(TestStableBranch.V_5_3_0, TestStableBranch.V_5_3_1, TestStableBranch.V_5_3_2, TestStableBranch.V_5_4_0);
expectedUnreleased = Collections.emptyList();
}
assertThat(released, equalTo(expectedReleased));
assertThat(unreleased, equalTo(expectedUnreleased));
}
public static class TestStableBranchBehindStableBranch {
@ -147,9 +183,26 @@ public class VersionUtilsTests extends ESTestCase {
TestStableBranchBehindStableBranch.class);
List<Version> released = t.v1();
List<Version> unreleased = t.v2();
assertEquals(Arrays.asList(TestStableBranchBehindStableBranch.V_5_3_0, TestStableBranchBehindStableBranch.V_5_3_1), released);
assertEquals(Arrays.asList(TestStableBranchBehindStableBranch.V_5_3_2, TestStableBranchBehindStableBranch.V_5_4_0,
TestStableBranchBehindStableBranch.V_5_5_0), unreleased);
final List<Version> expectedReleased;
final List<Version> expectedUnreleased;
if (Booleans.parseBoolean(System.getProperty("build.snapshot", "true"))) {
expectedReleased = Arrays.asList(TestStableBranchBehindStableBranch.V_5_3_0, TestStableBranchBehindStableBranch.V_5_3_1);
expectedUnreleased = Arrays.asList(
TestStableBranchBehindStableBranch.V_5_3_2,
TestStableBranchBehindStableBranch.V_5_4_0,
TestStableBranchBehindStableBranch.V_5_5_0);
} else {
expectedReleased = Arrays.asList(
TestStableBranchBehindStableBranch.V_5_3_0,
TestStableBranchBehindStableBranch.V_5_3_1,
TestStableBranchBehindStableBranch.V_5_3_2,
TestStableBranchBehindStableBranch.V_5_4_0,
TestStableBranchBehindStableBranch.V_5_5_0);
expectedUnreleased = Collections.emptyList();
}
assertThat(released, equalTo(expectedReleased));
assertThat(unreleased, equalTo(expectedUnreleased));
}
public static class TestUnstableBranch {
@ -168,9 +221,29 @@ public class VersionUtilsTests extends ESTestCase {
TestUnstableBranch.class);
List<Version> released = t.v1();
List<Version> unreleased = t.v2();
assertEquals(Arrays.asList(TestUnstableBranch.V_5_3_0, TestUnstableBranch.V_5_3_1,
TestUnstableBranch.V_6_0_0_alpha1, TestUnstableBranch.V_6_0_0_alpha2), released);
assertEquals(Arrays.asList(TestUnstableBranch.V_5_3_2, TestUnstableBranch.V_5_4_0, TestUnstableBranch.V_6_0_0_beta1), unreleased);
final List<Version> expectedReleased;
final List<Version> expectedUnreleased;
if (Booleans.parseBoolean(System.getProperty("build.snapshot", "true"))) {
expectedReleased = Arrays.asList(
TestUnstableBranch.V_5_3_0,
TestUnstableBranch.V_5_3_1,
TestUnstableBranch.V_6_0_0_alpha1,
TestUnstableBranch.V_6_0_0_alpha2);
expectedUnreleased = Arrays.asList(TestUnstableBranch.V_5_3_2, TestUnstableBranch.V_5_4_0, TestUnstableBranch.V_6_0_0_beta1);
} else {
expectedReleased = Arrays.asList(
TestUnstableBranch.V_5_3_0,
TestUnstableBranch.V_5_3_1,
TestUnstableBranch.V_5_3_2,
TestUnstableBranch.V_5_4_0,
TestUnstableBranch.V_6_0_0_alpha1,
TestUnstableBranch.V_6_0_0_alpha2,
TestUnstableBranch.V_6_0_0_beta1);
expectedUnreleased = Collections.emptyList();
}
assertThat(released, equalTo(expectedReleased));
assertThat(unreleased, equalTo(expectedUnreleased));
}
public static class TestNewMajorRelease {
@ -191,11 +264,35 @@ public class VersionUtilsTests extends ESTestCase {
TestNewMajorRelease.class);
List<Version> released = t.v1();
List<Version> unreleased = t.v2();
assertEquals(Arrays.asList(TestNewMajorRelease.V_5_6_0, TestNewMajorRelease.V_5_6_1,
TestNewMajorRelease.V_6_0_0_alpha1, TestNewMajorRelease.V_6_0_0_alpha2,
TestNewMajorRelease.V_6_0_0_beta1, TestNewMajorRelease.V_6_0_0_beta2,
TestNewMajorRelease.V_6_0_0), released);
assertEquals(Arrays.asList(TestNewMajorRelease.V_5_6_2, TestNewMajorRelease.V_6_0_1), unreleased);
final List<Version> expectedReleased;
final List<Version> expectedUnreleased;
if (Booleans.parseBoolean(System.getProperty("build.snapshot", "true"))) {
expectedReleased = Arrays.asList(
TestNewMajorRelease.V_5_6_0,
TestNewMajorRelease.V_5_6_1,
TestNewMajorRelease.V_6_0_0_alpha1,
TestNewMajorRelease.V_6_0_0_alpha2,
TestNewMajorRelease.V_6_0_0_beta1,
TestNewMajorRelease.V_6_0_0_beta2,
TestNewMajorRelease.V_6_0_0);
expectedUnreleased = Arrays.asList(TestNewMajorRelease.V_5_6_2, TestNewMajorRelease.V_6_0_1);
} else {
expectedReleased = Arrays.asList(
TestNewMajorRelease.V_5_6_0,
TestNewMajorRelease.V_5_6_1,
TestNewMajorRelease.V_5_6_2,
TestNewMajorRelease.V_6_0_0_alpha1,
TestNewMajorRelease.V_6_0_0_alpha2,
TestNewMajorRelease.V_6_0_0_beta1,
TestNewMajorRelease.V_6_0_0_beta2,
TestNewMajorRelease.V_6_0_0,
TestNewMajorRelease.V_6_0_1);
expectedUnreleased = Collections.emptyList();
}
assertThat(released, equalTo(expectedReleased));
assertThat(unreleased, equalTo(expectedUnreleased));
}
public static class TestVersionBumpIn6x {
@ -217,11 +314,37 @@ public class VersionUtilsTests extends ESTestCase {
TestVersionBumpIn6x.class);
List<Version> released = t.v1();
List<Version> unreleased = t.v2();
assertEquals(Arrays.asList(TestVersionBumpIn6x.V_5_6_0, TestVersionBumpIn6x.V_5_6_1,
TestVersionBumpIn6x.V_6_0_0_alpha1, TestVersionBumpIn6x.V_6_0_0_alpha2,
TestVersionBumpIn6x.V_6_0_0_beta1, TestVersionBumpIn6x.V_6_0_0_beta2,
TestVersionBumpIn6x.V_6_0_0), released);
assertEquals(Arrays.asList(TestVersionBumpIn6x.V_5_6_2, TestVersionBumpIn6x.V_6_0_1, TestVersionBumpIn6x.V_6_1_0), unreleased);
final List<Version> expectedReleased;
final List<Version> expectedUnreleased;
if (Booleans.parseBoolean(System.getProperty("build.snapshot", "true"))) {
expectedReleased = Arrays.asList(
TestVersionBumpIn6x.V_5_6_0,
TestVersionBumpIn6x.V_5_6_1,
TestVersionBumpIn6x.V_6_0_0_alpha1,
TestVersionBumpIn6x.V_6_0_0_alpha2,
TestVersionBumpIn6x.V_6_0_0_beta1,
TestVersionBumpIn6x.V_6_0_0_beta2,
TestVersionBumpIn6x.V_6_0_0);
expectedUnreleased = Arrays.asList(TestVersionBumpIn6x.V_5_6_2, TestVersionBumpIn6x.V_6_0_1, TestVersionBumpIn6x.V_6_1_0);
} else {
expectedReleased = Arrays.asList(
TestVersionBumpIn6x.V_5_6_0,
TestVersionBumpIn6x.V_5_6_1,
TestVersionBumpIn6x.V_5_6_2,
TestVersionBumpIn6x.V_6_0_0_alpha1,
TestVersionBumpIn6x.V_6_0_0_alpha2,
TestVersionBumpIn6x.V_6_0_0_beta1,
TestVersionBumpIn6x.V_6_0_0_beta2,
TestVersionBumpIn6x.V_6_0_0,
TestVersionBumpIn6x.V_6_0_1,
TestVersionBumpIn6x.V_6_1_0);
expectedUnreleased = Collections.emptyList();
}
assertThat(released, equalTo(expectedReleased));
assertThat(unreleased, equalTo(expectedUnreleased));
}
public static class TestNewMinorBranchIn6x {
@ -246,12 +369,45 @@ public class VersionUtilsTests extends ESTestCase {
TestNewMinorBranchIn6x.class);
List<Version> released = t.v1();
List<Version> unreleased = t.v2();
assertEquals(Arrays.asList(TestNewMinorBranchIn6x.V_5_6_0, TestNewMinorBranchIn6x.V_5_6_1,
TestNewMinorBranchIn6x.V_6_0_0_alpha1, TestNewMinorBranchIn6x.V_6_0_0_alpha2,
TestNewMinorBranchIn6x.V_6_0_0_beta1, TestNewMinorBranchIn6x.V_6_0_0_beta2,
TestNewMinorBranchIn6x.V_6_0_0, TestNewMinorBranchIn6x.V_6_1_0, TestNewMinorBranchIn6x.V_6_1_1), released);
assertEquals(Arrays.asList(TestNewMinorBranchIn6x.V_5_6_2, TestNewMinorBranchIn6x.V_6_0_1,
TestNewMinorBranchIn6x.V_6_1_2, TestNewMinorBranchIn6x.V_6_2_0), unreleased);
final List<Version> expectedReleased;
final List<Version> expectedUnreleased;
if (Booleans.parseBoolean(System.getProperty("build.snapshot", "true"))) {
expectedReleased = Arrays.asList(
TestNewMinorBranchIn6x.V_5_6_0,
TestNewMinorBranchIn6x.V_5_6_1,
TestNewMinorBranchIn6x.V_6_0_0_alpha1,
TestNewMinorBranchIn6x.V_6_0_0_alpha2,
TestNewMinorBranchIn6x.V_6_0_0_beta1,
TestNewMinorBranchIn6x.V_6_0_0_beta2,
TestNewMinorBranchIn6x.V_6_0_0,
TestNewMinorBranchIn6x.V_6_1_0,
TestNewMinorBranchIn6x.V_6_1_1);
expectedUnreleased = Arrays.asList(
TestNewMinorBranchIn6x.V_5_6_2,
TestNewMinorBranchIn6x.V_6_0_1,
TestNewMinorBranchIn6x.V_6_1_2,
TestNewMinorBranchIn6x.V_6_2_0);
} else {
expectedReleased = Arrays.asList(
TestNewMinorBranchIn6x.V_5_6_0,
TestNewMinorBranchIn6x.V_5_6_1,
TestNewMinorBranchIn6x.V_5_6_2,
TestNewMinorBranchIn6x.V_6_0_0_alpha1,
TestNewMinorBranchIn6x.V_6_0_0_alpha2,
TestNewMinorBranchIn6x.V_6_0_0_beta1,
TestNewMinorBranchIn6x.V_6_0_0_beta2,
TestNewMinorBranchIn6x.V_6_0_0,
TestNewMinorBranchIn6x.V_6_0_1,
TestNewMinorBranchIn6x.V_6_1_0,
TestNewMinorBranchIn6x.V_6_1_1,
TestNewMinorBranchIn6x.V_6_1_2,
TestNewMinorBranchIn6x.V_6_2_0);
expectedUnreleased = Collections.emptyList();
}
assertThat(released, equalTo(expectedReleased));
assertThat(unreleased, equalTo(expectedUnreleased));
}
/**
@ -259,10 +415,6 @@ public class VersionUtilsTests extends ESTestCase {
* agree with the list of wire and index compatible versions we build in gradle.
*/
public void testGradleVersionsMatchVersionUtils() {
if (System.getProperty("build.snapshot", "true").equals("false")) {
logger.warn("Skipping testGradleVersionsMatchVersionUtils(): See #27815 for details");
return;
}
// First check the index compatible versions
VersionsFromProperty indexCompatible = new VersionsFromProperty("tests.gradle_index_compat_versions");
List<Version> released = VersionUtils.allReleasedVersions().stream()