From 7d89adcc1733eb2ddc1460f05600ddc824272bec Mon Sep 17 00:00:00 2001 From: Dima Spivak Date: Sat, 18 Oct 2014 00:19:25 -0700 Subject: [PATCH] HBASE-12229 NullPointerException in SnapshotTestingUtils * Implemented the waitUntilAllRegionsOnline in HBaseTestingUtility#createTable * Add waitFor around #isTableAvailable call that previously didn't do anything --- .../java/org/apache/hadoop/hbase/HBaseTestingUtility.java | 15 +++++++++++++++ .../hadoop/hbase/snapshot/SnapshotTestingUtils.java | 15 +++++++++++---- 2 files changed, 26 insertions(+), 4 deletions(-) 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 16fd631..cc173f1 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 @@ -1207,6 +1207,21 @@ public class HBaseTestingUtility extends HBaseCommonTestingUtility { /** * 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 * @param families * @param c Configuration to use 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 f3a399e..072e044 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 @@ -46,6 +46,7 @@ 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.Durability; import org.apache.hadoop.hbase.client.HBaseAdmin; import org.apache.hadoop.hbase.client.HTable; @@ -630,13 +631,20 @@ 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, final byte[]... families) throws IOException, InterruptedException { HTableDescriptor htd = new HTableDescriptor(tableName); - for (byte[] family: families) { + for (byte[] family : families) { HColumnDescriptor hcd = new HColumnDescriptor(family); htd.addFamily(hcd); } @@ -644,8 +652,7 @@ public class SnapshotTestingUtils { for (int i = 0; i < splitKeys.length; ++i) { splitKeys[i] = new byte[] { KEYS[i+1] }; } - util.getHBaseAdmin().createTable(htd, splitKeys); - waitForTableToBeOnline(util, tableName); + util.createTable(htd, splitKeys); assertEquals(KEYS.length-1, util.getHBaseAdmin().getTableRegions(tableName).size()); } -- 1.9.3 (Apple Git-50)