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 <stack@apache.org>
This commit is contained in:
parent
cad86cca00
commit
5e9360d80c
@ -1196,6 +1196,21 @@ public class HBaseTestingUtility extends HBaseCommonTestingUtility {
|
|||||||
return new HTable(c, htd.getTableName());
|
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.
|
* Create a table.
|
||||||
* @param tableName
|
* @param tableName
|
||||||
|
@ -44,8 +44,10 @@ import org.apache.hadoop.hbase.HRegionInfo;
|
|||||||
import org.apache.hadoop.hbase.HTableDescriptor;
|
import org.apache.hadoop.hbase.HTableDescriptor;
|
||||||
import org.apache.hadoop.hbase.TableName;
|
import org.apache.hadoop.hbase.TableName;
|
||||||
import org.apache.hadoop.hbase.TableNotEnabledException;
|
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.Admin;
|
||||||
import org.apache.hadoop.hbase.client.Durability;
|
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.HTable;
|
||||||
import org.apache.hadoop.hbase.client.Put;
|
import org.apache.hadoop.hbase.client.Put;
|
||||||
import org.apache.hadoop.hbase.client.Table;
|
import org.apache.hadoop.hbase.client.Table;
|
||||||
@ -630,7 +632,14 @@ public class SnapshotTestingUtils {
|
|||||||
for (HRegion region : onlineRegions) {
|
for (HRegion region : onlineRegions) {
|
||||||
region.waitForFlushesAndCompactions();
|
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<IOException>() {
|
||||||
|
@Override
|
||||||
|
public boolean evaluate() throws IOException {
|
||||||
|
return hBaseAdmin.isTableAvailable(tableName);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void createTable(final HBaseTestingUtility util, final TableName tableName,
|
public static void createTable(final HBaseTestingUtility util, final TableName tableName,
|
||||||
@ -642,15 +651,13 @@ public class SnapshotTestingUtils {
|
|||||||
htd.addFamily(hcd);
|
htd.addFamily(hcd);
|
||||||
}
|
}
|
||||||
byte[][] splitKeys = getSplitKeys();
|
byte[][] splitKeys = getSplitKeys();
|
||||||
util.getHBaseAdmin().createTable(htd, splitKeys);
|
util.createTable(htd, splitKeys);
|
||||||
waitForTableToBeOnline(util, tableName);
|
|
||||||
assertEquals((splitKeys.length + 1) * regionReplication,
|
assertEquals((splitKeys.length + 1) * regionReplication,
|
||||||
util.getHBaseAdmin().getTableRegions(tableName).size());
|
util.getHBaseAdmin().getTableRegions(tableName).size());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static byte[][] getSplitKeys() {
|
public static byte[][] getSplitKeys() {
|
||||||
byte[][] splitKeys = new byte[KEYS.length-2][];
|
byte[][] splitKeys = new byte[KEYS.length-2][];
|
||||||
byte[] hex = Bytes.toBytes("123456789abcde");
|
|
||||||
for (int i = 0; i < splitKeys.length; ++i) {
|
for (int i = 0; i < splitKeys.length; ++i) {
|
||||||
splitKeys[i] = new byte[] { KEYS[i+1] };
|
splitKeys[i] = new byte[] { KEYS[i+1] };
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user