Skip to content

Commit cb81e65

Browse files
authored
Change bad file settings when node is shut down (#137978)
testNewErrorOnRestartProcessing modifies file settings with a different error case. However, it checks the error hasn't yet been processed before stopping the node. The point of the test is to check restarting processes the file, but since there is an error, the version check is never applied, so the new error state may materialize before the node is restarted. This commit moves the file settings modification to occur after the node is stopped. closes #131098
1 parent fc10209 commit cb81e65

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

server/src/internalClusterTest/java/org/elasticsearch/reservedstate/service/FileSettingsServiceIT.java

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,7 @@ public static void writeJSONFile(String node, String json, Logger logger, Long v
138138
}
139139

140140
public static void writeJSONFile(String node, String json, Logger logger, Long version, Path targetPath) throws Exception {
141-
FileSettingsService fileSettingsService = internalCluster().getInstance(FileSettingsService.class, node);
142-
143-
Files.createDirectories(fileSettingsService.watchedFileDir());
141+
Files.createDirectories(targetPath.getParent());
144142
Path tempFilePath = createTempFile();
145143

146144
String jsonWithVersion = Strings.format(json, version);
@@ -519,11 +517,19 @@ public void testNewErrorOnRestartReprocessing() throws Exception {
519517
assertClusterStateNotSaved(savedClusterState.v1(), metadataVersion);
520518
assertHasErrors(metadataVersion, "not_cluster_settings");
521519

522-
// write json with new error without version increment to simulate ES failing to process settings after a restart for a new reason
523-
// (usually, this would be due to a code change)
524-
writeJSONFile(masterNode, testOtherErrorJSON, logger, versionCounter.get());
525-
assertHasErrors(metadataVersion, "not_cluster_settings");
526-
internalCluster().restartNode(masterNode);
520+
// capture the watched file settings file before shutting down the master node
521+
FileSettingsService fileSettingsService = internalCluster().getInstance(FileSettingsService.class, masterNode);
522+
Path fileSettingsFile = fileSettingsService.watchedFile();
523+
524+
internalCluster().restartNode(masterNode, new InternalTestCluster.RestartCallback() {
525+
@Override
526+
public Settings onNodeStopped(String nodeName) throws Exception {
527+
// write json with new error without version increment to simulate ES failing to process settings after a restart for
528+
// a new reason (usually, this would be due to a code change)
529+
writeJSONFile(masterNode, testOtherErrorJSON, logger, versionCounter.get(), fileSettingsFile);
530+
return Settings.EMPTY;
531+
}
532+
});
527533
ensureGreen();
528534

529535
assertBusy(() -> assertHasErrors(metadataVersion, "bad_cluster_settings"));

0 commit comments

Comments
 (0)