diff --git a/server/src/test/java/org/elasticsearch/snapshots/AbstractSnapshotIntegTestCase.java b/server/src/test/java/org/elasticsearch/snapshots/AbstractSnapshotIntegTestCase.java index d5409821befd5..9fe7356877c8e 100644 --- a/server/src/test/java/org/elasticsearch/snapshots/AbstractSnapshotIntegTestCase.java +++ b/server/src/test/java/org/elasticsearch/snapshots/AbstractSnapshotIntegTestCase.java @@ -35,6 +35,7 @@ import java.nio.file.Path; import java.nio.file.SimpleFileVisitor; import java.nio.file.attribute.BasicFileAttributes; +import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.List; @@ -74,6 +75,18 @@ public static long getFailureCount(String repository) { return failureCount; } + public static void assertFileCount(Path dir, int expectedCount) throws IOException { + final List found = new ArrayList<>(); + Files.walkFileTree(dir, new SimpleFileVisitor() { + @Override + public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) { + found.add(file); + return FileVisitResult.CONTINUE; + } + }); + assertEquals("Unexpected file count, found: [" + found + "].", expectedCount, found.size()); + } + public static int numberOfFiles(Path dir) throws IOException { final AtomicInteger count = new AtomicInteger(); Files.walkFileTree(dir, new SimpleFileVisitor() { diff --git a/server/src/test/java/org/elasticsearch/snapshots/DedicatedClusterSnapshotRestoreIT.java b/server/src/test/java/org/elasticsearch/snapshots/DedicatedClusterSnapshotRestoreIT.java index 433cbe2fdaa6c..11a06cbbab868 100644 --- a/server/src/test/java/org/elasticsearch/snapshots/DedicatedClusterSnapshotRestoreIT.java +++ b/server/src/test/java/org/elasticsearch/snapshots/DedicatedClusterSnapshotRestoreIT.java @@ -457,7 +457,7 @@ public void testSnapshotWithStuckNode() throws Exception { // Remove it from the list of available nodes nodes.remove(blockedNode); - int numberOfFilesBeforeSnapshot = numberOfFiles(repo); + assertFileCount(repo, 0); logger.info("--> snapshot"); client.admin().cluster().prepareCreateSnapshot("test-repo", "test-snap") .setWaitForCompletion(false) @@ -493,8 +493,7 @@ public void testSnapshotWithStuckNode() throws Exception { // (2) index-0 (because we keep the previous version) and // (3) index-latest // (4) incompatible-snapshots - assertThat("not all files were deleted during snapshot cancellation", - numberOfFilesBeforeSnapshot, equalTo(numberOfFiles(repo) - 4)); + assertFileCount(repo, 4); logger.info("--> done"); }