|
42 | 42 | import org.elasticsearch.test.MockLog; |
43 | 43 | import org.elasticsearch.test.NodeRoles; |
44 | 44 | import org.elasticsearch.test.junit.annotations.TestLogging; |
45 | | -import org.hamcrest.Matchers; |
46 | 45 | import org.junit.AssumptionViolatedException; |
47 | 46 |
|
48 | 47 | import java.io.IOException; |
@@ -582,9 +581,9 @@ public void testIndexCompatibilityChecks() throws IOException { |
582 | 581 | containsString("it holds metadata for indices with version [" + oldIndexVersion.toReleaseVersion() + "]"), |
583 | 582 | containsString( |
584 | 583 | "Revert this node to version [" |
585 | | - + (previousNodeVersion.major == Version.CURRENT.major |
586 | | - ? Version.CURRENT.minimumCompatibilityVersion() |
587 | | - : previousNodeVersion) |
| 584 | + + (previousNodeVersion.onOrAfter(Version.CURRENT.minimumCompatibilityVersion()) |
| 585 | + ? previousNodeVersion |
| 586 | + : Version.CURRENT.minimumCompatibilityVersion()) |
588 | 587 | + "]" |
589 | 588 | ) |
590 | 589 | ) |
@@ -639,29 +638,37 @@ public void testSymlinkDataDirectory() throws Exception { |
639 | 638 | } |
640 | 639 |
|
641 | 640 | public void testGetBestDowngradeVersion() { |
642 | | - assertThat( |
643 | | - NodeEnvironment.getBestDowngradeVersion(BuildVersion.fromString("8.18.0")), |
644 | | - Matchers.equalTo(BuildVersion.fromString("8.18.0")) |
645 | | - ); |
646 | | - assertThat( |
647 | | - NodeEnvironment.getBestDowngradeVersion(BuildVersion.fromString("8.18.5")), |
648 | | - Matchers.equalTo(BuildVersion.fromString("8.18.5")) |
649 | | - ); |
650 | | - assertThat( |
651 | | - NodeEnvironment.getBestDowngradeVersion(BuildVersion.fromString("8.18.12")), |
652 | | - Matchers.equalTo(BuildVersion.fromString("8.18.12")) |
653 | | - ); |
654 | | - assertThat( |
655 | | - NodeEnvironment.getBestDowngradeVersion(BuildVersion.fromString("8.19.0")), |
656 | | - Matchers.equalTo(BuildVersion.fromString("8.19.0")) |
| 641 | + int prev = Version.CURRENT.minimumCompatibilityVersion().major; |
| 642 | + int last = Version.CURRENT.minimumCompatibilityVersion().minor; |
| 643 | + int old = prev - 1; |
| 644 | + |
| 645 | + assumeTrue("The current compatibility rules are active only from 8.x onward", prev >= 7); |
| 646 | + assertEquals(Version.CURRENT.major - 1, prev); |
| 647 | + |
| 648 | + assertEquals( |
| 649 | + "From an old major, recommend prev.last", |
| 650 | + NodeEnvironment.getBestDowngradeVersion(BuildVersion.fromString(old + ".0.0")), |
| 651 | + BuildVersion.fromString(prev + "." + last + ".0") |
657 | 652 | ); |
658 | | - assertThat( |
659 | | - NodeEnvironment.getBestDowngradeVersion(BuildVersion.fromString("8.17.0")), |
660 | | - Matchers.equalTo(BuildVersion.fromString("8.18.0")) |
| 653 | + |
| 654 | + if (last >= 1) { |
| 655 | + assertEquals( |
| 656 | + "From an old minor of the previous major, recommend prev.last", |
| 657 | + NodeEnvironment.getBestDowngradeVersion(BuildVersion.fromString(prev + "." + (last - 1) + ".0")), |
| 658 | + BuildVersion.fromString(prev + "." + last + ".0") |
| 659 | + ); |
| 660 | + } |
| 661 | + |
| 662 | + assertEquals( |
| 663 | + "From an old patch of prev.last, return that version itself", |
| 664 | + NodeEnvironment.getBestDowngradeVersion(BuildVersion.fromString(prev + "." + last + ".1")), |
| 665 | + BuildVersion.fromString(prev + "." + last + ".1") |
661 | 666 | ); |
662 | | - assertThat( |
663 | | - NodeEnvironment.getBestDowngradeVersion(BuildVersion.fromString("7.17.0")), |
664 | | - Matchers.equalTo(BuildVersion.fromString("8.18.0")) |
| 667 | + |
| 668 | + assertEquals( |
| 669 | + "From the first version of this major, return that version itself", |
| 670 | + NodeEnvironment.getBestDowngradeVersion(BuildVersion.fromString(Version.CURRENT.major + ".0.0")), |
| 671 | + BuildVersion.fromString(Version.CURRENT.major + ".0.0") |
665 | 672 | ); |
666 | 673 | } |
667 | 674 |
|
|
0 commit comments