Skip to content

Commit 483889b

Browse files
n1v0lgsmalyshev
authored andcommitted
Fix file settings service test on windows (elastic#115234)
Fix unit test on windows: it looks like the replace-existing flag is necessary to avoid AccessDeniedExceptions like this [example failure](https://gradle-enterprise.elastic.co/s/4tjgx5vzblv36/tests/task/:server:test/details/org.elasticsearch.reservedstate.service.FileSettingsServiceTests/testProcessFileChanges?top-execution=1). Resolves: elastic#115280
1 parent 7a86665 commit 483889b

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

server/src/test/java/org/elasticsearch/reservedstate/service/FileSettingsServiceTests.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ public void testProcessFileChanges() throws Exception {
250250
fileSettingsService.start();
251251
fileSettingsService.clusterChanged(new ClusterChangedEvent("test", clusterService.state(), ClusterState.EMPTY_STATE));
252252
// second file change; contents still don't matter
253-
writeTestFile(fileSettingsService.watchedFile(), "{}");
253+
overwriteTestFile(fileSettingsService.watchedFile(), "{}");
254254

255255
// wait for listener to be called (once for initial processing, once for subsequent update)
256256
assertTrue(latch.await(20, TimeUnit.SECONDS));
@@ -355,6 +355,12 @@ public void testHandleSnapshotRestoreResetsMetadata() throws Exception {
355355
private void writeTestFile(Path path, String contents) throws IOException {
356356
Path tempFilePath = createTempFile();
357357
Files.writeString(tempFilePath, contents);
358-
Files.move(tempFilePath, path, StandardCopyOption.ATOMIC_MOVE);
358+
Files.move(tempFilePath, path, StandardCopyOption.ATOMIC_MOVE, StandardCopyOption.REPLACE_EXISTING);
359+
}
360+
361+
private void overwriteTestFile(Path path, String contents) throws IOException {
362+
Path tempFilePath = createTempFile();
363+
Files.writeString(tempFilePath, contents);
364+
Files.move(tempFilePath, path, StandardCopyOption.REPLACE_EXISTING);
359365
}
360366
}

0 commit comments

Comments
 (0)