Source:
<code>public void testNormalizerCannotMergeNonAdjacentRegions() throws Exception { final TableName tableName = TableName.valueOf(name.getMethodName()); MiniHBaseCluster cluster = TEST_UTIL.getHBaseCluster(); HMaster m = cluster.getMaster(); final byte[][] keys = { Bytes.toBytes("aa"), Bytes.toBytes("aa1"), Bytes.toBytes("aa1!"), Bytes.toBytes("aa2") }; try (Table ht = TEST_UTIL.createMultiRegionTable(tableName, new byte[][]{FAMILYNAME}, keys)) { List<HRegion> generatedRegions = TEST_UTIL.getHBaseCluster().getRegions(tableName); Collections.sort(generatedRegions, Comparator.comparing(HRegion::getRegionInfo, RegionInfo.COMPARATOR)); HRegion region = generatedRegions.get(0); generateTestData(region, 3); region.flush(true); region = generatedRegions.get(1); generateTestData(region, 1); region.flush(true); region = generatedRegions.get(2); generateTestData(region, 3); region.flush(true); region = generatedRegions.get(3); generateTestData(region, 1); region.flush(true); region = generatedRegions.get(4); generateTestData(region, 5); region.flush(true); ModifyableTableDescriptor htd = new ModifyableTableDescriptor(tableName, admin.getDescriptor(tableName)); htd.setNormalizationEnabled(true); admin.modifyTable(htd); admin.flush(tableName); <START> <END> assertEquals(5, MetaTableAccessor.getRegionCount(TEST_UTIL.getConnection(), tableName)); Thread.sleep(5000); final List<NormalizationPlan> plans = m.getRegionNormalizer().computePlanForTable(tableName); assertNull(plans); } finally { admin.disableTable(tableName); admin.deleteTable(tableName); } }</code><technical_language>Is a condition waitFor instead of a fixed sleep? fixed sleeps lead slow flakey tests :(</technical_language>

Target:
public void testNormalizerCannotMergeNonAdjacentRegions() throws Exception { final TableName tableName = TableName.valueOf(name.getMethodName()); MiniHBaseCluster cluster = TEST_UTIL.getHBaseCluster(); HMaster m = cluster.getMaster(); final byte[][] keys = { Bytes.toBytes("aa"), Bytes.toBytes("aa1"), Bytes.toBytes("aa1!"), Bytes.toBytes("aa2") }; try (Table ht = TEST_UTIL.createTable(tableName, FAMILYNAME, keys)) { List<HRegion> generatedRegions = TEST_UTIL.getHBaseCluster().getRegions(tableName); generatedRegions.sort(Comparator.comparing(HRegion::getRegionInfo, RegionInfo.COMPARATOR)); HRegion region = generatedRegions.get(0); generateTestData(region, 3); region.flush(true); region = generatedRegions.get(1); generateTestData(region, 1); region.flush(true); region = generatedRegions.get(2); generateTestData(region, 3); region.flush(true); region = generatedRegions.get(3); generateTestData(region, 1); region.flush(true); region = generatedRegions.get(4); generateTestData(region, 5); region.flush(true); final TableDescriptor td = TableDescriptorBuilder.newBuilder(admin.getDescriptor(tableName)) .setNormalizationEnabled(true) .build(); admin.modifyTable(td); admin.flush(tableName); assertEquals(5, MetaTableAccessor.getRegionCount(TEST_UTIL.getConnection(), tableName)); Thread.sleep(5000); final List<NormalizationPlan> plans = m.getRegionNormalizer().computePlanForTable(tableName); assertNull(plans); } finally { if (admin.tableExists(tableName)) { admin.disableTable(tableName); admin.deleteTable(tableName); } } }