Skip to content

Commit c6033d4

Browse files
committed
Fix tests involving getBestDowngradeVersion (#127646)
* Fix tests involving getBestDowngradeVersion * [CI] Auto commit changes from spotless * Typo in assume message --------- Co-authored-by: elasticsearchmachine <[email protected]> (cherry picked from commit 64568ee) # Conflicts: # muted-tests.yml
1 parent b5e5ce3 commit c6033d4

File tree

3 files changed

+40
-34
lines changed

3 files changed

+40
-34
lines changed

muted-tests.yml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -204,9 +204,6 @@ tests:
204204
issue: https://github.com/elastic/elasticsearch/issues/120816
205205
- class: org.elasticsearch.xpack.security.authc.ldap.ActiveDirectorySessionFactoryTests
206206
issue: https://github.com/elastic/elasticsearch/issues/121285
207-
- class: org.elasticsearch.env.NodeEnvironmentTests
208-
method: testGetBestDowngradeVersion
209-
issue: https://github.com/elastic/elasticsearch/issues/121316
210207
- class: org.elasticsearch.index.engine.ShuffleForcedMergePolicyTests
211208
method: testDiagnostics
212209
issue: https://github.com/elastic/elasticsearch/issues/121336
@@ -282,9 +279,6 @@ tests:
282279
- class: org.elasticsearch.action.admin.cluster.node.tasks.CancellableTasksIT
283280
method: testChildrenTasksCancelledOnTimeout
284281
issue: https://github.com/elastic/elasticsearch/issues/123568
285-
- class: org.elasticsearch.env.NodeEnvironmentTests
286-
method: testIndexCompatibilityChecks
287-
issue: https://github.com/elastic/elasticsearch/issues/130276
288282

289283
# Examples:
290284
#

server/src/main/java/org/elasticsearch/env/NodeEnvironment.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1501,10 +1501,15 @@ private static void tryWriteTempFile(Path path) throws IOException {
15011501

15021502
/**
15031503
* Get a useful version string to direct a user's downgrade operation
1504+
* <p>
1505+
* Assuming that the index was compatible with {@code previousNodeVersion},
1506+
* the user should downgrade to that {@code previousNodeVersion},
1507+
* unless it's prior to the minimum compatible version,
1508+
* in which case the user should downgrade to that instead.
1509+
* (If the index version is so old that the minimum compatible version is incompatible with the index,
1510+
* then the cluster was already borked before the node upgrade began,
1511+
* and we can't probably help them without more info than we have here.)
15041512
*
1505-
* <p>If a user is trying to install current major N but has incompatible indices, the user should
1506-
* downgrade to last minor of the previous major (N-1).last. We return (N-1).last, unless the user is trying to upgrade from
1507-
* a (N-1).last.x release, in which case we return the last installed version.
15081513
* @return Version to downgrade to
15091514
*/
15101515
// visible for testing

server/src/test/java/org/elasticsearch/env/NodeEnvironmentTests.java

Lines changed: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242
import org.elasticsearch.test.MockLog;
4343
import org.elasticsearch.test.NodeRoles;
4444
import org.elasticsearch.test.junit.annotations.TestLogging;
45-
import org.hamcrest.Matchers;
4645
import org.junit.AssumptionViolatedException;
4746

4847
import java.io.IOException;
@@ -581,9 +580,9 @@ public void testIndexCompatibilityChecks() throws IOException {
581580
containsString("it holds metadata for indices with version [" + oldIndexVersion.toReleaseVersion() + "]"),
582581
containsString(
583582
"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())
587586
+ "]"
588587
)
589588
)
@@ -638,29 +637,37 @@ public void testSymlinkDataDirectory() throws Exception {
638637
}
639638

640639
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")
656651
);
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")
660665
);
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")
664671
);
665672
}
666673

0 commit comments

Comments
 (0)