From 87e0b0a1ada752cb2c692a6dc0b6a949e50cc311 Mon Sep 17 00:00:00 2001 From: Tianli Feng Date: Tue, 7 Feb 2023 00:52:44 -0800 Subject: [PATCH] Change the outdated File API to Path Signed-off-by: Tianli Feng --- .../opensearch/snapshots/SearchableSnapshotIT.java | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/server/src/internalClusterTest/java/org/opensearch/snapshots/SearchableSnapshotIT.java b/server/src/internalClusterTest/java/org/opensearch/snapshots/SearchableSnapshotIT.java index 3607e843027d7..c92f1815bca81 100644 --- a/server/src/internalClusterTest/java/org/opensearch/snapshots/SearchableSnapshotIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/snapshots/SearchableSnapshotIT.java @@ -32,10 +32,11 @@ import org.opensearch.monitor.fs.FsInfo; import org.opensearch.repositories.fs.FsRepository; -import java.io.File; +import java.io.IOException; import java.nio.file.Files; import java.nio.file.NoSuchFileException; import java.nio.file.Path; +import java.nio.file.StandardCopyOption; import java.util.List; import java.util.stream.Stream; @@ -466,10 +467,12 @@ public void testCacheFilesAreClosedAfterUse() throws Exception { // Find all the files in the path try (Stream paths = Files.walk(shardRootPath)) { paths.filter(Files::isRegularFile).forEach(path -> { - File file = path.toFile(); - // Testing renaming the file to check the file is closed or not. - boolean fileIsClosed = file.renameTo(file); - assertThat(fileIsClosed, is(true)); + // Testing moving the file to check the file is closed or not. + try { + Files.move(path, path, StandardCopyOption.REPLACE_EXISTING); + } catch (IOException e) { + fail("No exception is expected. The file can't be moved, so it may not be closed."); + } }); } catch (NoSuchFileException e) { logger.debug("--> the root path for the restored index data doesn't exist.");