diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/cleaner/TestSnapshotFromMaster.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/cleaner/TestSnapshotFromMaster.java index 0bffa92733e..1d3b9f1a4e8 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/cleaner/TestSnapshotFromMaster.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/cleaner/TestSnapshotFromMaster.java @@ -279,6 +279,7 @@ public class TestSnapshotFromMaster { */ @Test(timeout = 300000) public void testSnapshotHFileArchiving() throws Exception { + int hfileCount = 20; Admin admin = UTIL.getHBaseAdmin(); // make sure we don't fail on listing snapshots SnapshotTestingUtils.assertNoSnapshots(admin); @@ -291,10 +292,14 @@ public class TestSnapshotFromMaster { UTIL.createTable(htd, new byte[][] { TEST_FAM }, null); - // load the table (creates at least 4 hfiles) - for ( int i = 0; i < 5; i++) { + // load the table + while(true) { UTIL.loadTable(UTIL.getConnection().getTable(TABLE_NAME), TEST_FAM); UTIL.flush(TABLE_NAME); + Collection hfiles = getHFiles(rootDir, fs, TABLE_NAME); + if (hfiles.size() >= hfileCount) { + break; + } } // disable the table so we can take a snapshot @@ -354,12 +359,16 @@ public class TestSnapshotFromMaster { LOG.debug(fileName); } // get the archived files for the table - Collection files = getArchivedHFiles(archiveDir, rootDir, fs, TABLE_NAME); + Collection archives = getHFiles(archiveDir, fs, TABLE_NAME); + + // get the hfiles for the table + Collection hfiles = getHFiles(rootDir, fs, TABLE_NAME); // and make sure that there is a proper subset for (String fileName : snapshotHFiles) { - assertTrue("Archived hfiles " + files + " is missing snapshot file:" + fileName, - files.contains(fileName)); + boolean exist = archives.contains(fileName) || hfiles.contains(fileName); + assertTrue("Archived hfiles " + archives + + " and table hfiles " + hfiles + " is missing snapshot file:" + fileName, exist); } // delete the existing snapshot @@ -381,19 +390,18 @@ public class TestSnapshotFromMaster { LOG.info("After delete snapshot cleaners run File-System state"); FSUtils.logFileSystemState(fs, rootDir, LOG); - files = getArchivedHFiles(archiveDir, rootDir, fs, TABLE_NAME); + archives = getHFiles(archiveDir, fs, TABLE_NAME); assertEquals("Still have some hfiles in the archive, when their snapshot has been deleted.", 0, - files.size()); + archives.size()); } /** - * @return all the HFiles for a given table that have been archived + * @return all the HFiles for a given table in the specified dir * @throws IOException on expected failure */ - private final Collection getArchivedHFiles(Path archiveDir, Path rootDir, - FileSystem fs, TableName tableName) throws IOException { - Path tableArchive = FSUtils.getTableDir(archiveDir, tableName); - return SnapshotTestingUtils.listHFileNames(fs, tableArchive); + private final Collection getHFiles(Path dir, FileSystem fs, TableName tableName) throws IOException { + Path tableDir = FSUtils.getTableDir(dir, tableName); + return SnapshotTestingUtils.listHFileNames(fs, tableDir); } /**