Skip to content

Commit

Permalink
Change the outdated File API to Path
Browse files Browse the repository at this point in the history
Signed-off-by: Tianli Feng <ftianli@amazon.com>
  • Loading branch information
Tianli Feng committed Feb 7, 2023
1 parent 832a59f commit 87e0b0a
Showing 1 changed file with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -466,10 +467,12 @@ public void testCacheFilesAreClosedAfterUse() throws Exception {
// Find all the files in the path
try (Stream<Path> 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.");
Expand Down

0 comments on commit 87e0b0a

Please sign in to comment.