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