From eae7523cefeb3893ccedb4c69c31686145c3c83e Mon Sep 17 00:00:00 2001 From: huaxiangsun Date: Thu, 9 Apr 2020 21:08:10 -0700 Subject: [PATCH] HBASE-24159 [flakey test] regionserver.TestRegionMergeTransactionOnCluster (#1472) (#1475) Delete tables after each test cases to avoid polluting states. Signed-off-by: stack --- .../TestRegionMergeTransactionOnCluster.java | 139 +++++++++--------- 1 file changed, 71 insertions(+), 68 deletions(-) diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionMergeTransactionOnCluster.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionMergeTransactionOnCluster.java index e156ba8d34a..7f56f2daa66 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionMergeTransactionOnCluster.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionMergeTransactionOnCluster.java @@ -140,37 +140,36 @@ public class TestRegionMergeTransactionOnCluster { LOG.info("Starting " + name.getMethodName()); final TableName tableName = TableName.valueOf(name.getMethodName()); - // Create table and load data. - Table table = createTableAndLoadData(MASTER, tableName); - // Merge 1st and 2nd region - mergeRegionsAndVerifyRegionNum(MASTER, tableName, 0, 1, - INITIAL_REGION_NUM - 1); + try { + // Create table and load data. + Table table = createTableAndLoadData(MASTER, tableName); + // Merge 1st and 2nd region + mergeRegionsAndVerifyRegionNum(MASTER, tableName, 0, 1, INITIAL_REGION_NUM - 1); - // Merge 2nd and 3th region - PairOfSameType mergedRegions = - mergeRegionsAndVerifyRegionNum(MASTER, tableName, 1, 2, - INITIAL_REGION_NUM - 2); + // Merge 2nd and 3th region + PairOfSameType mergedRegions = + mergeRegionsAndVerifyRegionNum(MASTER, tableName, 1, 2, INITIAL_REGION_NUM - 2); - verifyRowCount(table, ROWSIZE); + verifyRowCount(table, ROWSIZE); - // Randomly choose one of the two merged regions - RegionInfo hri = RandomUtils.nextBoolean() ? - mergedRegions.getFirst() : mergedRegions.getSecond(); - MiniHBaseCluster cluster = TEST_UTIL.getHBaseCluster(); - AssignmentManager am = cluster.getMaster().getAssignmentManager(); - RegionStates regionStates = am.getRegionStates(); + // Randomly choose one of the two merged regions + RegionInfo hri = RandomUtils.nextBoolean() ? mergedRegions.getFirst() : mergedRegions.getSecond(); + MiniHBaseCluster cluster = TEST_UTIL.getHBaseCluster(); + AssignmentManager am = cluster.getMaster().getAssignmentManager(); + RegionStates regionStates = am.getRegionStates(); - // We should not be able to assign it again - am.assign(hri); - assertFalse("Merged region can't be assigned", - regionStates.isRegionInTransition(hri)); + // We should not be able to assign it again + am.assign(hri); + assertFalse("Merged region can't be assigned", regionStates.isRegionInTransition(hri)); - // We should not be able to unassign it either - am.unassign(hri); - assertFalse("Merged region can't be unassigned", - regionStates.isRegionInTransition(hri)); + // We should not be able to unassign it either + am.unassign(hri); + assertFalse("Merged region can't be unassigned", regionStates.isRegionInTransition(hri)); - table.close(); + table.close(); + } finally { + TEST_UTIL.deleteTable(tableName); + } } /** @@ -181,27 +180,31 @@ public class TestRegionMergeTransactionOnCluster { public void testMergeAndRestartingMaster() throws Exception { final TableName tableName = TableName.valueOf(name.getMethodName()); - // Create table and load data. - Table table = createTableAndLoadData(MASTER, tableName); - try { - MyMasterRpcServices.enabled.set(true); + // Create table and load data. + Table table = createTableAndLoadData(MASTER, tableName); - // Merge 1st and 2nd region - mergeRegionsAndVerifyRegionNum(MASTER, tableName, 0, 1, INITIAL_REGION_NUM - 1); + try { + MyMasterRpcServices.enabled.set(true); + + // Merge 1st and 2nd region + mergeRegionsAndVerifyRegionNum(MASTER, tableName, 0, 1, INITIAL_REGION_NUM - 1); + } finally { + MyMasterRpcServices.enabled.set(false); + } + + table.close(); } finally { - MyMasterRpcServices.enabled.set(false); + TEST_UTIL.deleteTable(tableName); } - - table.close(); } @Test public void testCleanMergeReference() throws Exception { LOG.info("Starting " + name.getMethodName()); ADMIN.enableCatalogJanitor(false); + final TableName tableName = TableName.valueOf(name.getMethodName()); try { - final TableName tableName = TableName.valueOf(name.getMethodName()); // Create table and load data. Table table = createTableAndLoadData(MASTER, tableName); // Merge 1st and 2nd region @@ -304,6 +307,7 @@ public class TestRegionMergeTransactionOnCluster { assertFalse(MetaTableAccessor.hasMergeRegions(mergedRegionResult.rawCells())); } finally { ADMIN.enableCatalogJanitor(true); + TEST_UTIL.deleteTable(tableName); } } @@ -368,40 +372,39 @@ public class TestRegionMergeTransactionOnCluster { @Test public void testMergeWithReplicas() throws Exception { final TableName tableName = TableName.valueOf(name.getMethodName()); - // Create table and load data. - createTableAndLoadData(MASTER, tableName, 5, 2); - List> initialRegionToServers = - MetaTableAccessor.getTableRegionsAndLocations( - TEST_UTIL.getConnection(), tableName); - // Merge 1st and 2nd region - PairOfSameType mergedRegions = mergeRegionsAndVerifyRegionNum(MASTER, tableName, - 0, 2, 5 * 2 - 2); - List> currentRegionToServers = - MetaTableAccessor.getTableRegionsAndLocations( - TEST_UTIL.getConnection(), tableName); - List initialRegions = new ArrayList<>(); - for (Pair p : initialRegionToServers) { - initialRegions.add(p.getFirst()); + try { + // Create table and load data. + Table table = createTableAndLoadData(MASTER, tableName, 5, 2); + List> initialRegionToServers = + MetaTableAccessor.getTableRegionsAndLocations(TEST_UTIL.getConnection(), tableName); + // Merge 1st and 2nd region + PairOfSameType mergedRegions = + mergeRegionsAndVerifyRegionNum(MASTER, tableName, 0, 2, 5 * 2 - 2); + List> currentRegionToServers = + MetaTableAccessor.getTableRegionsAndLocations(TEST_UTIL.getConnection(), tableName); + List initialRegions = new ArrayList<>(); + for (Pair p : initialRegionToServers) { + initialRegions.add(p.getFirst()); + } + List currentRegions = new ArrayList<>(); + for (Pair p : currentRegionToServers) { + currentRegions.add(p.getFirst()); + } + assertTrue(initialRegions.contains(mergedRegions.getFirst())); //this is the first region + assertTrue(initialRegions.contains(RegionReplicaUtil + .getRegionInfoForReplica(mergedRegions.getFirst(), 1))); //this is the replica of the first region + assertTrue(initialRegions.contains(mergedRegions.getSecond())); //this is the second region + assertTrue(initialRegions.contains(RegionReplicaUtil + .getRegionInfoForReplica(mergedRegions.getSecond(), 1))); //this is the replica of the second region + assertTrue(!initialRegions.contains(currentRegions.get(0))); //this is the new region + assertTrue(!initialRegions.contains(RegionReplicaUtil.getRegionInfoForReplica(currentRegions.get(0), 1))); //replica of the new region + assertTrue(currentRegions.contains(RegionReplicaUtil.getRegionInfoForReplica(currentRegions.get(0), 1))); //replica of the new region + assertTrue(!currentRegions.contains(RegionReplicaUtil.getRegionInfoForReplica(mergedRegions.getFirst(), 1))); //replica of the merged region + assertTrue(!currentRegions.contains(RegionReplicaUtil.getRegionInfoForReplica(mergedRegions.getSecond(), 1))); //replica of the merged region + table.close(); + } finally { + TEST_UTIL.deleteTable(tableName); } - List currentRegions = new ArrayList<>(); - for (Pair p : currentRegionToServers) { - currentRegions.add(p.getFirst()); - } - assertTrue(initialRegions.contains(mergedRegions.getFirst())); //this is the first region - assertTrue(initialRegions.contains(RegionReplicaUtil.getRegionInfoForReplica( - mergedRegions.getFirst(), 1))); //this is the replica of the first region - assertTrue(initialRegions.contains(mergedRegions.getSecond())); //this is the second region - assertTrue(initialRegions.contains(RegionReplicaUtil.getRegionInfoForReplica( - mergedRegions.getSecond(), 1))); //this is the replica of the second region - assertTrue(!initialRegions.contains(currentRegions.get(0))); //this is the new region - assertTrue(!initialRegions.contains(RegionReplicaUtil.getRegionInfoForReplica( - currentRegions.get(0), 1))); //replica of the new region - assertTrue(currentRegions.contains(RegionReplicaUtil.getRegionInfoForReplica( - currentRegions.get(0), 1))); //replica of the new region - assertTrue(!currentRegions.contains(RegionReplicaUtil.getRegionInfoForReplica( - mergedRegions.getFirst(), 1))); //replica of the merged region - assertTrue(!currentRegions.contains(RegionReplicaUtil.getRegionInfoForReplica( - mergedRegions.getSecond(), 1))); //replica of the merged region } private PairOfSameType mergeRegionsAndVerifyRegionNum(