diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/normalizer/TestSimpleRegionNormalizer.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/normalizer/TestSimpleRegionNormalizer.java index df4638c44830..9c0350fa490b 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/normalizer/TestSimpleRegionNormalizer.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/normalizer/TestSimpleRegionNormalizer.java @@ -34,6 +34,7 @@ import static org.hamcrest.Matchers.not; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.RETURNS_DEEP_STUBS; @@ -371,28 +372,7 @@ public void testHonorsMergeEnabledInTD() { @Test public void testHonorsMinimumRegionCount() { - conf.setInt(MERGE_MIN_REGION_COUNT_KEY, 1); - final TableName tableName = name.getTableName(); - final List regionInfos = createRegionInfos(tableName, 3); - // create a table topology that results in both a merge plan and a split plan. Assert that the - // merge is only created when the when the number of table regions is above the region count - // threshold, and that the split plan is create in both cases. - final Map regionSizes = createRegionSizesMap(regionInfos, 1, 1, 10); - setupMocksForNormalizer(regionSizes, regionInfos); - - List plans = normalizer.computePlansForTable(tableDescriptor); - assertThat(plans, contains( - new SplitNormalizationPlan(regionInfos.get(2), 10), - new MergeNormalizationPlan.Builder() - .addTarget(regionInfos.get(0), 1) - .addTarget(regionInfos.get(1), 1) - .build())); - - // have to call setupMocks again because we don't have dynamic config update on normalizer. - conf.setInt(MERGE_MIN_REGION_COUNT_KEY, 4); - setupMocksForNormalizer(regionSizes, regionInfos); - assertThat(normalizer.computePlansForTable(tableDescriptor), contains( - new SplitNormalizationPlan(regionInfos.get(2), 10))); + honorsMinimumRegionCount(MERGE_MIN_REGION_COUNT_KEY); } /** @@ -400,7 +380,12 @@ public void testHonorsMinimumRegionCount() { */ @Test public void testHonorsOldMinimumRegionCount() { - conf.setInt(MIN_REGION_COUNT_KEY, 1); + honorsMinimumRegionCount(MIN_REGION_COUNT_KEY); + assertNull(conf.get(MERGE_MIN_REGION_COUNT_KEY)); + } + + private void honorsMinimumRegionCount(String confKey) { + conf.setInt(confKey, 1); final TableName tableName = name.getTableName(); final List regionInfos = createRegionInfos(tableName, 3); // create a table topology that results in both a merge plan and a split plan. Assert that the @@ -418,7 +403,7 @@ public void testHonorsOldMinimumRegionCount() { .build())); // have to call setupMocks again because we don't have dynamic config update on normalizer. - conf.setInt(MIN_REGION_COUNT_KEY, 4); + conf.setInt(confKey, 4); setupMocksForNormalizer(regionSizes, regionInfos); assertThat(normalizer.computePlansForTable(tableDescriptor), contains( new SplitNormalizationPlan(regionInfos.get(2), 10))); @@ -426,26 +411,7 @@ public void testHonorsOldMinimumRegionCount() { @Test public void testHonorsMinimumRegionCountInTD() { - conf.setInt(MERGE_MIN_REGION_COUNT_KEY, 1); - final TableName tableName = name.getTableName(); - final List regionInfos = createRegionInfos(tableName, 3); - // create a table topology that results in both a merge plan and a split plan. Assert that the - // merge is only created when the when the number of table regions is above the region count - // threshold, and that the split plan is create in both cases. - final Map regionSizes = createRegionSizesMap(regionInfos, 1, 1, 10); - setupMocksForNormalizer(regionSizes, regionInfos); - - List plans = normalizer.computePlansForTable(tableDescriptor); - assertThat(plans, contains( - new SplitNormalizationPlan(regionInfos.get(2), 10), - new MergeNormalizationPlan.Builder() - .addTarget(regionInfos.get(0), 1) - .addTarget(regionInfos.get(1), 1) - .build())); - - when(tableDescriptor.getValue(MIN_REGION_COUNT_KEY)).thenReturn("4"); - assertThat(normalizer.computePlansForTable(tableDescriptor), contains( - new SplitNormalizationPlan(regionInfos.get(2), 10))); + honorsOldMinimumRegionCountInTD(MERGE_MIN_REGION_COUNT_KEY); } /** @@ -454,7 +420,11 @@ public void testHonorsMinimumRegionCountInTD() { */ @Test public void testHonorsOldMinimumRegionCountInTD() { - conf.setInt(MIN_REGION_COUNT_KEY, 1); + honorsOldMinimumRegionCountInTD(MIN_REGION_COUNT_KEY); + } + + private void honorsOldMinimumRegionCountInTD(String confKey) { + conf.setInt(confKey, 1); final TableName tableName = name.getTableName(); final List regionInfos = createRegionInfos(tableName, 3); // create a table topology that results in both a merge plan and a split plan. Assert that the @@ -471,7 +441,7 @@ public void testHonorsOldMinimumRegionCountInTD() { .addTarget(regionInfos.get(1), 1) .build())); - when(tableDescriptor.getValue(MIN_REGION_COUNT_KEY)).thenReturn("4"); + when(tableDescriptor.getValue(confKey)).thenReturn("4"); assertThat(normalizer.computePlansForTable(tableDescriptor), contains( new SplitNormalizationPlan(regionInfos.get(2), 10))); }