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
349a56ae2c
commit
7e995b6496
|
@ -1206,6 +1206,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
|
||||||
|
|
|
@ -45,8 +45,10 @@ import org.apache.hadoop.hbase.HTableDescriptor;
|
||||||
import org.apache.hadoop.hbase.TableDescriptor;
|
import org.apache.hadoop.hbase.TableDescriptor;
|
||||||
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;
|
||||||
|
@ -633,27 +635,32 @@ 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,
|
||||||
int regionReplication, final byte[]... families) throws IOException, InterruptedException {
|
int regionReplication, final byte[]... families) throws IOException, InterruptedException {
|
||||||
HTableDescriptor htd = new HTableDescriptor(tableName);
|
HTableDescriptor htd = new HTableDescriptor(tableName);
|
||||||
htd.setRegionReplication(regionReplication);
|
htd.setRegionReplication(regionReplication);
|
||||||
for (byte[] family: families) {
|
for (byte[] family : families) {
|
||||||
HColumnDescriptor hcd = new HColumnDescriptor(family);
|
HColumnDescriptor hcd = new HColumnDescriptor(family);
|
||||||
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…
Reference in New Issue