diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/HBaseTestingUtility.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/HBaseTestingUtility.java index 797da7b8d9b..a848ff2ca3d 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/HBaseTestingUtility.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/HBaseTestingUtility.java @@ -1196,6 +1196,21 @@ public class HBaseTestingUtility extends HBaseCommonTestingUtility { return new HTable(c, htd.getTableName()); } + /** + * Create a table. + * @param htd + * @param splitRows + * @return An HTable instance for the created table. + * @throws IOException + */ + public HTable createTable(HTableDescriptor htd, byte[][] splitRows) + throws IOException { + getHBaseAdmin().createTable(htd, splitRows); + // HBaseAdmin only waits for regions to appear in hbase:meta we should wait until they are assigned + waitUntilAllRegionsAssigned(htd.getTableName()); + return new HTable(getConfiguration(), htd.getTableName()); + } + /** * Create a table. * @param tableName diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/snapshot/SnapshotTestingUtils.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/snapshot/SnapshotTestingUtils.java index c147fd07088..3da3b10c3fb 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/snapshot/SnapshotTestingUtils.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/snapshot/SnapshotTestingUtils.java @@ -44,8 +44,10 @@ import org.apache.hadoop.hbase.HRegionInfo; import org.apache.hadoop.hbase.HTableDescriptor; import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.TableNotEnabledException; +import org.apache.hadoop.hbase.Waiter; import org.apache.hadoop.hbase.client.Admin; import org.apache.hadoop.hbase.client.Durability; +import org.apache.hadoop.hbase.client.HBaseAdmin; import org.apache.hadoop.hbase.client.HTable; import org.apache.hadoop.hbase.client.Put; import org.apache.hadoop.hbase.client.Table; @@ -630,27 +632,32 @@ public class SnapshotTestingUtils { for (HRegion region : onlineRegions) { region.waitForFlushesAndCompactions(); } - util.getHBaseAdmin().isTableAvailable(tableName); + // Wait up to 60 seconds for a table to be available. + final HBaseAdmin hBaseAdmin = util.getHBaseAdmin(); + util.waitFor(60000, new Waiter.Predicate() { + @Override + public boolean evaluate() throws IOException { + return hBaseAdmin.isTableAvailable(tableName); + } + }); } public static void createTable(final HBaseTestingUtility util, final TableName tableName, int regionReplication, final byte[]... families) throws IOException, InterruptedException { HTableDescriptor htd = new HTableDescriptor(tableName); htd.setRegionReplication(regionReplication); - for (byte[] family: families) { + for (byte[] family : families) { HColumnDescriptor hcd = new HColumnDescriptor(family); htd.addFamily(hcd); } byte[][] splitKeys = getSplitKeys(); - util.getHBaseAdmin().createTable(htd, splitKeys); - waitForTableToBeOnline(util, tableName); + util.createTable(htd, splitKeys); assertEquals((splitKeys.length + 1) * regionReplication, util.getHBaseAdmin().getTableRegions(tableName).size()); } public static byte[][] getSplitKeys() { byte[][] splitKeys = new byte[KEYS.length-2][]; - byte[] hex = Bytes.toBytes("123456789abcde"); for (int i = 0; i < splitKeys.length; ++i) { splitKeys[i] = new byte[] { KEYS[i+1] }; }