Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More Verbose Assertion in testSnapshotWithStuckNode #39893

Merged
merged 1 commit into from
Mar 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -74,6 +75,18 @@ public static long getFailureCount(String repository) {
return failureCount;
}

public static void assertFileCount(Path dir, int expectedCount) throws IOException {
final List<Path> found = new ArrayList<>();
Files.walkFileTree(dir, new SimpleFileVisitor<Path>() {
@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<Path>() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,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)
Expand Down Expand Up @@ -490,8 +490,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");
}

Expand Down