Repository: hbase Updated Branches: refs/heads/branch-1 baeeaa1b2 -> e8e4beacb refs/heads/branch-1.4 7dc20d8a9 -> b4f97f574 refs/heads/branch-2 de2e84fe2 -> 44b01d590 refs/heads/branch-2.0 2155766d0 -> 615db1018 refs/heads/branch-2.1 259d12f73 -> 76a487c06 refs/heads/master 4d7235ec5 -> 1b7e4fdcf
HBASE-19275 TestSnapshotFileCache never worked properly Signed-off-by: Andrew Purtell <apurt...@apache.org> Project: http://git-wip-us.apache.org/repos/asf/hbase/repo Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/1b7e4fdc Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/1b7e4fdc Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/1b7e4fdc Branch: refs/heads/master Commit: 1b7e4fdcfc69a99d114910cd77a617f449eb33b1 Parents: 4d7235e Author: Xu Cang <xc...@salesforce.com> Authored: Sun Jul 22 20:37:55 2018 -0700 Committer: Andrew Purtell <apurt...@apache.org> Committed: Mon Oct 1 17:12:00 2018 -0700 ---------------------------------------------------------------------- .../master/snapshot/TestSnapshotFileCache.java | 38 +++++++++----------- 1 file changed, 17 insertions(+), 21 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/hbase/blob/1b7e4fdc/hbase-server/src/test/java/org/apache/hadoop/hbase/master/snapshot/TestSnapshotFileCache.java ---------------------------------------------------------------------- diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/snapshot/TestSnapshotFileCache.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/snapshot/TestSnapshotFileCache.java index e83dfa7..22d2734 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/snapshot/TestSnapshotFileCache.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/snapshot/TestSnapshotFileCache.java @@ -68,7 +68,6 @@ public class TestSnapshotFileCache { private static final Logger LOG = LoggerFactory.getLogger(TestSnapshotFileCache.class); private static final HBaseTestingUtility UTIL = new HBaseTestingUtility(); - private static long sequenceId = 0; private static FileSystem fs; private static Path rootDir; @@ -163,9 +162,6 @@ public class TestSnapshotFileCache { SnapshotMock.SnapshotBuilder complete = createAndTestSnapshotV1(cache, "snapshot", false, false); - SnapshotMock.SnapshotBuilder inProgress = - createAndTestSnapshotV1(cache, "snapshotInProgress", true, false); - int countBeforeCheck = count.get(); FSUtils.logFileSystemState(fs, rootDir, LOG); @@ -238,12 +234,11 @@ public class TestSnapshotFileCache { List<Path> files = new ArrayList<>(); for (int i = 0; i < 3; ++i) { for (Path filePath: builder.addRegion()) { - String fileName = filePath.getName(); if (tmp) { // We should be able to find all the files while the snapshot creation is in-progress FSUtils.logFileSystemState(fs, rootDir, LOG); - Iterable<FileStatus> nonSnapshot = getNonSnapshotFiles(cache, filePath); - assertFalse("Cache didn't find " + fileName, Iterables.contains(nonSnapshot, fileName)); + assertFalse("Cache didn't find " + filePath, + contains(getNonSnapshotFiles(cache, filePath), filePath)); } files.add(filePath); } @@ -256,9 +251,7 @@ public class TestSnapshotFileCache { // Make sure that all files are still present for (Path path: files) { - Iterable<FileStatus> nonSnapshotFiles = getNonSnapshotFiles(cache, path); - assertFalse("Cache didn't find " + path.getName(), - Iterables.contains(nonSnapshotFiles, path.getName())); + assertFalse("Cache didn't find " + path, contains(getNonSnapshotFiles(cache, path), path)); } FSUtils.logFileSystemState(fs, rootDir, LOG); @@ -267,25 +260,28 @@ public class TestSnapshotFileCache { fs.delete(builder.getSnapshotsDir(), true); FSUtils.logFileSystemState(fs, rootDir, LOG); - // The files should be in cache until next refresh - for (Path filePath: files) { - Iterable<FileStatus> nonSnapshotFiles = getNonSnapshotFiles(cache, filePath); - assertFalse("Cache didn't find " + filePath.getName(), Iterables.contains(nonSnapshotFiles, - filePath.getName())); - } - // then trigger a refresh cache.triggerCacheRefreshForTesting(); // and not it shouldn't find those files for (Path filePath: files) { - Iterable<FileStatus> nonSnapshotFiles = getNonSnapshotFiles(cache, filePath); - assertTrue("Cache found '" + filePath.getName() + "', but it shouldn't have.", - !Iterables.contains(nonSnapshotFiles, filePath.getName())); + assertTrue("Cache found '" + filePath + "', but it shouldn't have.", + contains(getNonSnapshotFiles(cache, filePath), filePath)); + + } + } + } + + private static boolean contains(Iterable<FileStatus> files, Path filePath) { + for (FileStatus status: files) { + LOG.debug("debug in contains, 3.1: " + status.getPath() + " filePath:" + filePath); + if (filePath.equals(status.getPath())) { + return true; } } + return false; } - private Iterable<FileStatus> getNonSnapshotFiles(SnapshotFileCache cache, Path storeFile) + private static Iterable<FileStatus> getNonSnapshotFiles(SnapshotFileCache cache, Path storeFile) throws IOException { return cache.getUnreferencedFiles( Arrays.asList(FSUtils.listStatus(fs, storeFile.getParent())), null