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