From 7e995b6496a44c057337535363aee778f52318b9 Mon Sep 17 00:00:00 2001 From: Dima Spivak Date: Wed, 15 Oct 2014 22:02:54 -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 * Remove unused byte[] hex Signed-off-by: stack --- .../hadoop/hbase/HBaseTestingUtility.java | 15 +++++++++++++++ .../hbase/snapshot/SnapshotTestingUtils.java | 17 ++++++++++++----- 2 files changed, 27 insertions(+), 5 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 bbd9dbe3c3f..450e805028e 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 @@ -1206,6 +1206,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 6a9c0dc2358..f0070d8dbc4 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 @@ -45,8 +45,10 @@ import org.apache.hadoop.hbase.HTableDescriptor; import org.apache.hadoop.hbase.TableDescriptor; 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; @@ -633,27 +635,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] }; }