@Test (timeout=300000)
public void testCreateTableWithSplitRegion() throws Exception {
final byte[] tableName = Bytes.toBytes("testCreateTableWithSplitRegion");
final MiniHBaseCluster cluster = TEST_UTIL.getHBaseCluster();
final HMaster m = cluster.getMaster();
final HTableDescriptor desc = new HTableDescriptor(tableName);
desc.addFamily(new HColumnDescriptor(FAMILYNAME));
byte[] splitPoint = Bytes.toBytes("split-point");
long ts = System.currentTimeMillis();
HRegionInfo d1 = new HRegionInfo(tableName, null, splitPoint, false, ts);
HRegionInfo d2 = new HRegionInfo(tableName, splitPoint, null, false, ts + 1);
HRegionInfo parent = new HRegionInfo(tableName, null, null, true, ts + 2);
parent.setOffline(true);
Path tempdir = m.getMasterFileSystem().getTempDir();
FileSystem fs = m.getMasterFileSystem().getFileSystem();
Path tempTableDir = FSUtils.getTablePath(tempdir, tableName);
fs.delete(tempTableDir, true); // Clean up temp table dir if exists
final HRegionInfo[] hRegionInfos = new HRegionInfo[] {d1, d2, parent};
CreateTableHandler handler = new CreateTableHandler(m, m.getMasterFileSystem(),
m.getServerManager(), desc, cluster.getConfiguration(), hRegionInfos,
m.getCatalogTracker(), m.getAssignmentManager());
handler.process();
for (int i = 0; i < 200; i++) {
if (!TEST_UTIL.getHBaseAdmin().isTableAvailable(tableName)) {
Thread.sleep(300);
}
}
assertTrue(TEST_UTIL.getHBaseAdmin().isTableEnabled(tableName));
assertTrue(TEST_UTIL.getHBaseAdmin().isTableAvailable(tableName));
List<HRegionInfo> regions = m.getAssignmentManager().getRegionsOfTable(tableName);
assertFalse("Split parent should not be assigned", regions.contains(parent));
}