Skip to content

Commit 79fcbe0

Browse files
committed
Test
1 parent da5ab57 commit 79fcbe0

File tree

1 file changed

+56
-2
lines changed

1 file changed

+56
-2
lines changed

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

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,11 @@ private void assertMasterNode(Client client, String node) {
134134

135135
public static void writeJSONFile(String node, String json, Logger logger, Long version) throws Exception {
136136
FileSettingsService fileSettingsService = internalCluster().getInstance(FileSettingsService.class, node);
137+
writeJSONFile(node, json, logger, version, fileSettingsService.watchedFile());
138+
}
139+
140+
public static void writeJSONFile(String node, String json, Logger logger, Long version, Path targetPath) throws Exception {
141+
FileSettingsService fileSettingsService = internalCluster().getInstance(FileSettingsService.class, node);
137142

138143
Files.createDirectories(fileSettingsService.watchedFileDir());
139144
Path tempFilePath = createTempFile();
@@ -147,8 +152,8 @@ public static void writeJSONFile(String node, String json, Logger logger, Long v
147152
do {
148153
try {
149154
// this can fail on Windows because of timing
150-
Files.move(tempFilePath, fileSettingsService.watchedFile(), StandardCopyOption.ATOMIC_MOVE);
151-
logger.info("--> after writing JSON config to node {} with path {}", node, tempFilePath);
155+
Files.move(tempFilePath, targetPath, StandardCopyOption.ATOMIC_MOVE);
156+
logger.info("--> after writing JSON config to node {} with path {}", node, targetPath);
152157
return;
153158
} catch (IOException e) {
154159
logger.info("--> retrying writing a settings file [{}]", retryCount);
@@ -498,6 +503,55 @@ public void testSettingsAppliedOnMasterReElection() throws Exception {
498503
assertClusterStateSaveOK(savedClusterState.v1(), savedClusterState.v2(), "43mb");
499504
}
500505

506+
public void testSymlinkUpdateTriggerReload() throws Exception {
507+
internalCluster().setBootstrapMasterNodeIndex(0);
508+
logger.info("--> start data node / non master node");
509+
String dataNode = internalCluster().startNode(Settings.builder().put(dataOnlyNode()).put("discovery.initial_state_timeout", "1s"));
510+
FileSettingsService dataFileSettingsService = internalCluster().getInstance(FileSettingsService.class, dataNode);
511+
512+
assertFalse(dataFileSettingsService.watching());
513+
514+
logger.info("--> start master node");
515+
final String masterNode = internalCluster().startMasterOnlyNode();
516+
assertMasterNode(internalCluster().nonMasterClient(), masterNode);
517+
{
518+
var savedClusterState = setupClusterStateListener(masterNode);
519+
520+
FileSettingsService masterFileSettingsService = internalCluster().getInstance(FileSettingsService.class, masterNode);
521+
522+
assertBusy(() -> assertTrue(masterFileSettingsService.watching()));
523+
assertFalse(dataFileSettingsService.watching());
524+
525+
createK8sLikeMount(masterNode);
526+
assertClusterStateSaveOK(savedClusterState.v1(), savedClusterState.v2(), "50mb");
527+
}
528+
{
529+
var savedClusterState = setupClusterStateListener(masterNode);
530+
updateSymbolicLink(masterNode, testJSON43mb);
531+
assertClusterStateSaveOK(savedClusterState.v1(), savedClusterState.v2(), "43mb");
532+
}
533+
}
534+
535+
public Path createK8sLikeMount(String node) throws Exception {
536+
FileSettingsService fileSettingsService = internalCluster().getInstance(FileSettingsService.class, node);
537+
Path baseDir = fileSettingsService.watchedFileDir();
538+
var fileDir = Files.createDirectories(baseDir.resolve("..TIMESTAMP_TEMP_FOLDER_1"));
539+
writeJSONFile(node, testJSON, logger, versionCounter.incrementAndGet(), fileDir.resolve("settings.json"));
540+
541+
var dataDir = Files.createSymbolicLink(baseDir.resolve("..data"), fileDir.getFileName());
542+
543+
return Files.createSymbolicLink(baseDir.resolve("settings.json"), dataDir.getFileName().resolve("settings.json"));
544+
}
545+
546+
public void updateSymbolicLink(String node, String json) throws Exception {
547+
FileSettingsService fileSettingsService = internalCluster().getInstance(FileSettingsService.class, node);
548+
Path baseDir = fileSettingsService.watchedFileDir();
549+
var fileDir = Files.createDirectories(baseDir.resolve("..TIMESTAMP_TEMP_FOLDER_2"));
550+
writeJSONFile(node, json, logger, versionCounter.incrementAndGet(), fileDir.resolve("settings.json"));
551+
Files.deleteIfExists(baseDir.resolve("..data"));
552+
Files.createSymbolicLink(baseDir.resolve("..data"), fileDir.getFileName());
553+
}
554+
501555
private void assertHasErrors(AtomicLong waitForMetadataVersion, String expectedError) {
502556
var errorMetadata = getErrorMetadata(waitForMetadataVersion);
503557
assertThat(errorMetadata, is(notNullValue()));

0 commit comments

Comments
 (0)