Skip to content
Merged
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 @@ -18,12 +18,10 @@
package org.apache.hadoop.hbase.master.snapshot;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import java.io.IOException;
import java.util.*;

import com.google.common.collect.Iterables;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.fs.FileStatus;
Expand Down Expand Up @@ -170,9 +168,7 @@ private void createAndTestSnapshot(final SnapshotFileCache cache,

// 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);
Expand All @@ -183,24 +179,31 @@ private void createAndTestSnapshot(final SnapshotFileCache cache,

// 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()));
assertFalse("Cache didn't find " + filePath,
contains(getNonSnapshotFiles(cache, filePath), filePath));
}

// 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()));
assertFalse("Cache found '" + filePath + "', but it shouldn't have.",
contains(getNonSnapshotFiles(cache, filePath), filePath));
}
}
}

private Iterable<FileStatus> getNonSnapshotFiles(SnapshotFileCache cache, Path storeFile)
private static boolean contains(Iterable<FileStatus> files, Path filePath) {
for (FileStatus status: files) {
if (filePath.equals(status.getPath())) {
return true;
}
}
return false;
}

private static Iterable<FileStatus> getNonSnapshotFiles(SnapshotFileCache cache, Path storeFile)
throws IOException {
return cache.getUnreferencedFiles(
Arrays.asList(FSUtils.listStatus(fs, storeFile.getParent())), null
Expand Down