From 93d00f1d9201c824f15ffdfb29e4475a7377657a Mon Sep 17 00:00:00 2001 From: Dima Spivak Date: Tue, 14 Oct 2014 17:23:21 -0700 Subject: [PATCH] HBASE-12229 NullPointerException in SnapshotTestingUtils * Implemented the waitUntilAllRegionsOnline in HBaseTestingUtility#createTable * Remove stale imports from SnapshotTestingUtils * Add waitFor around #isTableAvailable call that previously didn't do anything --- .../apache/hadoop/hbase/HBaseTestingUtility.java | 21 +++++++++++++++---- .../hbase/snapshot/SnapshotTestingUtils.java | 24 +++++++++------------- 2 files changed, 27 insertions(+), 18 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..7d51d5e 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 @@ -1467,20 +1467,33 @@ public class HBaseTestingUtility extends HBaseCommonTestingUtility { * @return An HTable instance for the created table. * @throws IOException */ - public HTable createTable(byte[] tableName, byte[][] families, byte[][] splitRows) + public HTable createTable(TableName tableName, byte[][] families, byte[][] splitRows) throws IOException { - HTableDescriptor desc = new HTableDescriptor(TableName.valueOf(tableName)); - for(byte[] family:families) { + 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(TableName.valueOf(tableName)); + 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); + } + + /** * Drop an existing table * @param tableName existing table */ 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..d7b47f2 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 @@ -24,12 +24,9 @@ import static org.junit.Assert.assertTrue; import java.io.IOException; import java.util.Arrays; import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; import java.util.List; import java.util.Map; import java.util.Set; -import java.util.HashSet; import java.util.TreeSet; import org.apache.commons.logging.Log; @@ -38,7 +35,6 @@ import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.FSDataOutputStream; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; -import org.apache.hadoop.fs.PathFilter; import org.apache.hadoop.hbase.HBaseTestingUtility; import org.apache.hadoop.hbase.HColumnDescriptor; import org.apache.hadoop.hbase.HConstants; @@ -46,6 +42,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; @@ -62,12 +59,10 @@ import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.IsSnapshotDoneRes import org.apache.hadoop.hbase.regionserver.HRegion; import org.apache.hadoop.hbase.regionserver.HRegionFileSystem; import org.apache.hadoop.hbase.regionserver.HRegionServer; -import org.apache.hadoop.hbase.snapshot.SnapshotReferenceUtil; import org.apache.hadoop.hbase.util.Bytes; import org.apache.hadoop.hbase.util.FSTableDescriptors; import org.apache.hadoop.hbase.util.FSUtils; import org.apache.hadoop.hbase.util.FSVisitor; -import org.apache.hadoop.hbase.util.FSUtils; import org.apache.hadoop.hbase.util.MD5Hash; import org.junit.Assert; @@ -630,22 +625,23 @@ 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) { - HColumnDescriptor hcd = new HColumnDescriptor(family); - htd.addFamily(hcd); - } byte[][] splitKeys = new byte[KEYS.length-2][]; 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(tableName, families, splitKeys); assertEquals(KEYS.length-1, util.getHBaseAdmin().getTableRegions(tableName).size()); } -- 1.9.3 (Apple Git-50)