From b2644a72fdc05c7f4e431911449694e6e819b1c3 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 --- .../apache/hadoop/hbase/HBaseTestingUtility.java | 25 ++++++++++++++++------ .../hbase/snapshot/SnapshotTestingUtils.java | 21 +++++++++--------- 2 files changed, 30 insertions(+), 16 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 bbd9dbe..cbd0649 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 @@ -1468,17 +1468,30 @@ public class HBaseTestingUtility extends HBaseCommonTestingUtility { * @return An HTable instance for the created table. * @throws IOException */ - public HTable createTable(byte[] tableName, byte[][] families, byte[][] splitRows) - throws IOException { - HTableDescriptor desc = new HTableDescriptor(TableName.valueOf(tableName)); - for(byte[] family:families) { + public HTable createTable(TableName tableName, byte[][] families, byte[][] splitRows) + throws IOException { + HTableDescriptor desc = new HTableDescriptor(tableName); + for (byte[] family : families) { HColumnDescriptor hcd = new HColumnDescriptor(family); desc.addFamily(hcd); } getHBaseAdmin().createTable(desc, splitRows); // HBaseAdmin only waits for regions to appear in hbase:meta we should wait until they are assigned - waitUntilAllRegionsAssigned(desc.getTableName()); - return new HTable(getConfiguration(), desc.getTableName()); + waitUntilAllRegionsAssigned(tableName); + return new HTable(getConfiguration(), tableName); + } + + /** + * Create a table. + * @param tableName + * @param families + * @param splitRows + * @return An HTable instance for the created table. + * @throws IOException + */ + public HTable createTable(byte[] tableName, byte[][] families, byte[][] splitRows) + throws IOException { + return createTable(TableName.valueOf(tableName), families, splitRows); } /** 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 6a9c0dc..4af1964 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,26 @@ 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) { - HColumnDescriptor hcd = new HColumnDescriptor(family); - htd.addFamily(hcd); - } byte[][] splitKeys = getSplitKeys(); - util.getHBaseAdmin().createTable(htd, splitKeys); - waitForTableToBeOnline(util, tableName); + util.createTable(tableName, families, 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] }; } -- 1.9.3 (Apple Git-50)