From b4e297f3f689a6468cf4fd9a4712dccad7b75dbf Mon Sep 17 00:00:00 2001 From: zhangduo Date: Thu, 8 Mar 2018 18:03:04 +0800 Subject: [PATCH] HBASE-20160 TestRestartCluster.testRetainAssignmentOnRestart uses the wrong condition to decide whether the assignment is finished --- .../hbase/master/TestRestartCluster.java | 32 ++++++++----------- 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestRestartCluster.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestRestartCluster.java index 56976b36ae6..088dff51dbe 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestRestartCluster.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestRestartCluster.java @@ -32,7 +32,6 @@ import org.apache.hadoop.hbase.ServerName; import org.apache.hadoop.hbase.TableExistsException; import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.client.RegionInfo; -import org.apache.hadoop.hbase.master.assignment.RegionStates; import org.apache.hadoop.hbase.testclassification.LargeTests; import org.apache.hadoop.hbase.testclassification.MasterTests; import org.apache.hadoop.hbase.util.Bytes; @@ -45,7 +44,7 @@ import org.junit.experimental.categories.Category; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -@Category({MasterTests.class, LargeTests.class}) +@Category({ MasterTests.class, LargeTests.class }) public class TestRestartCluster { @ClassRule @@ -60,7 +59,7 @@ public class TestRestartCluster { TableName.valueOf("restartTableTwo"), TableName.valueOf("restartTableThree") }; - private static final byte [] FAMILY = Bytes.toBytes("family"); + private static final byte[] FAMILY = Bytes.toBytes("family"); @After public void tearDown() throws Exception { UTIL.shutdownMiniCluster(); @@ -115,17 +114,13 @@ public class TestRestartCluster { @Test public void testRetainAssignmentOnRestart() throws Exception { UTIL.startMiniCluster(2); - while (!UTIL.getMiniHBaseCluster().getMaster().isInitialized()) { - Threads.sleep(1); - } // Turn off balancer - UTIL.getMiniHBaseCluster().getMaster(). - getMasterRpcServices().synchronousBalanceSwitch(false); + UTIL.getMiniHBaseCluster().getMaster().getMasterRpcServices().synchronousBalanceSwitch(false); LOG.info("\n\nCreating tables"); - for(TableName TABLE : TABLES) { + for (TableName TABLE : TABLES) { UTIL.createTable(TABLE, FAMILY); } - for(TableName TABLE : TABLES) { + for (TableName TABLE : TABLES) { UTIL.waitTableEnabled(TABLE); } @@ -157,6 +152,7 @@ public class TestRestartCluster { } LOG.info("\n\nShutting down HBase cluster"); + cluster.stopMaster(0); cluster.shutdown(); cluster.waitUntilShutDown(); @@ -194,11 +190,8 @@ public class TestRestartCluster { } // Wait till master is initialized and all regions are assigned - RegionStates regionStates = master.getAssignmentManager().getRegionStates(); - int expectedRegions = regionToRegionServerMap.size() + 1; - while (!master.isInitialized() - || regionStates.getRegionAssignments().size() != expectedRegions) { - Threads.sleep(100); + for (TableName TABLE : TABLES) { + UTIL.waitTableAvailable(TABLE); } snapshot = new SnapshotOfRegionAssignmentFromMeta(master.getConnection()); @@ -206,11 +199,14 @@ public class TestRestartCluster { Map newRegionToRegionServerMap = snapshot.getRegionToRegionServerMap(); assertEquals(regionToRegionServerMap.size(), newRegionToRegionServerMap.size()); - for (Map.Entry entry: newRegionToRegionServerMap.entrySet()) { - if (TableName.NAMESPACE_TABLE_NAME.equals(entry.getKey().getTable())) continue; + for (Map.Entry entry : newRegionToRegionServerMap.entrySet()) { + if (TableName.NAMESPACE_TABLE_NAME.equals(entry.getKey().getTable())) { + continue; + } ServerName oldServer = regionToRegionServerMap.get(entry.getKey()); ServerName currentServer = entry.getValue(); - LOG.info("Key=" + entry.getKey() + " oldServer=" + oldServer + ", currentServer=" + currentServer); + LOG.info( + "Key=" + entry.getKey() + " oldServer=" + oldServer + ", currentServer=" + currentServer); assertEquals(entry.getKey().toString(), oldServer.getAddress(), currentServer.getAddress()); assertNotEquals(oldServer.getStartcode(), currentServer.getStartcode()); }