Source:
public void testWithSplitRegions() throws Exception { MiniHBaseCluster cluster = TEST_UTIL.getHBaseCluster(); Admin admin = TEST_UTIL.getAdmin(); Table table = TEST_UTIL.getConnection().getTable(TABLE_NAME); List<Put> puts = new ArrayList<>(); for (int i = 10; i < 50000; i++) { puts.add(new Put(Bytes.toBytes(i)) .addColumn(Bytes.toBytes("fam1"), Bytes.toBytes("q1"), Bytes.toBytes("val_" + i))); } table.put(puts); admin.flush(TABLE_NAME); admin.compact(TABLE_NAME); HRegionServer regionServer = cluster.getRegionServer(0); String rsName = regionServer.getServerName().getAddress().toString(); int numRegions = regionServer.getNumberOfOnlineRegions(); List<HRegion> hRegions = regionServer.getRegions().stream() .filter(hRegion -> hRegion.getRegionInfo().getTable().equals(TABLE_NAME)) .collect(Collectors.toList()); RegionMover.RegionMoverBuilder rmBuilder = new RegionMover.RegionMoverBuilder(rsName, TEST_UTIL.getConfiguration()).ack(true) .maxthreads(8); try (RegionMover rm = rmBuilder.build()) { LOG.debug("Unloading " + regionServer.getServerName()); rm.unload(); Assert.assertEquals(0, regionServer.getNumberOfOnlineRegions()); LOG.debug("Successfully Unloaded\nNow Loading"); HRegion hRegion = hRegions.get(1); int startKey = 0; int endKey = Integer.MAX_VALUE; if (hRegion.getRegionInfo().getStartKey().length > 0) { startKey = Bytes.toInt(hRegion.getRegionInfo().getStartKey()); } if (hRegion.getRegionInfo().getEndKey().length > 0) { endKey = Bytes.toInt(hRegion.getRegionInfo().getEndKey()); } int midKey = startKey + (endKey - startKey) / 2; admin.splitRegionAsync(hRegion.getRegionInfo().getRegionName(), Bytes.toBytes(midKey)) .get(5, TimeUnit.SECONDS); Assert.assertTrue(rm.load()); Assert.assertEquals(numRegions - 1, regionServer.getNumberOfOnlineRegions()); } }

Target:
public void testWithSplitRegions() throws Exception { final TableName tableName = TableName.valueOf(name.getMethodName()); MiniHBaseCluster cluster = TEST_UTIL.getHBaseCluster(); Admin admin = TEST_UTIL.getAdmin(); Table table = TEST_UTIL.getConnection().getTable(tableName); List<Put> puts = new ArrayList<>(); for (int i = 10; i < 50000; i++) { puts.add(new Put(Bytes.toBytes(i)) .addColumn(Bytes.toBytes("fam1"), Bytes.toBytes("q1"), Bytes.toBytes("val_" + i))); } table.put(puts); admin.flush(tableName); admin.compact(tableName); HRegionServer regionServer = cluster.getRegionServer(0); String rsName = regionServer.getServerName().getAddress().toString(); int numRegions = regionServer.getNumberOfOnlineRegions(); List<HRegion> hRegions = regionServer.getRegions().stream() .filter(hRegion -> hRegion.getRegionInfo().getTable().equals(tableName)) .collect(Collectors.toList()); RegionMover.RegionMoverBuilder rmBuilder = new RegionMover.RegionMoverBuilder(rsName, TEST_UTIL.getConfiguration()).ack(true) .maxthreads(8); try (RegionMover rm = rmBuilder.build()) { LOG.debug("Unloading {}", regionServer.getServerName()); rm.unload(); Assert.assertEquals(0, regionServer.getNumberOfOnlineRegions()); LOG.debug("Successfully Unloaded, now Loading"); HRegion hRegion = hRegions.get(1); int startKey = 0; int endKey = Integer.MAX_VALUE; if (hRegion.getRegionInfo().getStartKey().length > 0) { startKey = Bytes.toInt(hRegion.getRegionInfo().getStartKey()); } if (hRegion.getRegionInfo().getEndKey().length > 0) { endKey = Bytes.toInt(hRegion.getRegionInfo().getEndKey()); } int midKey = startKey + (endKey - startKey) / 2; admin.splitRegionAsync(hRegion.getRegionInfo().getRegionName(), Bytes.toBytes(midKey)) .get(5, TimeUnit.SECONDS); Assert.assertTrue(rm.load()); Assert.assertEquals(numRegions - 1, regionServer.getNumberOfOnlineRegions()); } }