|
21 | 21 | import org.elasticsearch.Version; |
22 | 22 | import org.elasticsearch.common.collect.Tuple; |
23 | 23 |
|
| 24 | +import java.util.ArrayList; |
24 | 25 | import java.util.Arrays; |
25 | 26 | import java.util.List; |
26 | 27 |
|
27 | 28 | import static java.util.Collections.emptyList; |
28 | 29 | import static java.util.Collections.singletonList; |
| 30 | +import static java.util.stream.Collectors.toList; |
29 | 31 |
|
30 | 32 | public class VersionUtilsTests extends ESTestCase { |
31 | 33 |
|
@@ -158,5 +160,73 @@ public void testResolveReleasedVersionsForUnstableBranch() { |
158 | 160 | assertEquals(Arrays.asList(TestUnstableBranch.V_5_3_2, TestUnstableBranch.V_5_4_0), unreleased); |
159 | 161 | } |
160 | 162 |
|
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 | + } |
162 | 232 | } |
0 commit comments