HBASE-20016 
TestCatalogJanitorInMemoryStates#testInMemoryForReplicaParentCleanup is flaky

(cherry picked from commit 08b993997404aad7ec8f66b8c2b2083062c9ef1a)


Project: http://git-wip-us.apache.org/repos/asf/hbase/repo
Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/41cd37cf
Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/41cd37cf
Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/41cd37cf

Branch: refs/heads/branch-1.2
Commit: 41cd37cffc690d056edf1ca10d5cbc07d02373c5
Parents: 4b79555
Author: Chia-Ping Tsai <chia7...@gmail.com>
Authored: Sun Feb 18 21:22:58 2018 +0800
Committer: Sean Busbey <bus...@apache.org>
Committed: Mon Feb 26 10:46:57 2018 -0600

----------------------------------------------------------------------
 .../TestCatalogJanitorInMemoryStates.java       | 52 +++++++++-----------
 1 file changed, 22 insertions(+), 30 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hbase/blob/41cd37cf/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestCatalogJanitorInMemoryStates.java
----------------------------------------------------------------------
diff --git 
a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestCatalogJanitorInMemoryStates.java
 
b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestCatalogJanitorInMemoryStates.java
index 6ea7e2f..40396ba 100644
--- 
a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestCatalogJanitorInMemoryStates.java
+++ 
b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestCatalogJanitorInMemoryStates.java
@@ -124,7 +124,7 @@ public class TestCatalogJanitorInMemoryStates {
    * AM's serverHoldings and
    */
   @Test(timeout = 180000)
-  public void testInMemoryForReplicaParentCleanup() throws IOException, 
InterruptedException {
+  public void testInMemoryForReplicaParentCleanup() throws Exception {
     final AssignmentManager am = 
TEST_UTIL.getHBaseCluster().getMaster().getAssignmentManager();
     final CatalogJanitor janitor = 
TEST_UTIL.getHBaseCluster().getMaster().catalogJanitorChore;
 
@@ -139,35 +139,27 @@ public class TestCatalogJanitorInMemoryStates {
     // There are two regions, one for primary, one for the replica.
     assertTrue(allRegionLocations.size() == 2);
 
-    HRegionLocation replicaParentRegion, primaryParentRegion;
-    if (RegionReplicaUtil.isDefaultReplica(
-        allRegionLocations.get(0).getRegionInfo().getReplicaId())) {
-      primaryParentRegion = allRegionLocations.get(0);
-      replicaParentRegion = allRegionLocations.get(1);
-    } else {
-      primaryParentRegion = allRegionLocations.get(1);
-      replicaParentRegion = allRegionLocations.get(0);
-    }
-
-    List<HRegionLocation> primaryDaughters = 
splitRegion(primaryParentRegion.getRegionInfo(),
-        Bytes.toBytes("a"));
-
-    // Wait until the replica parent region is offline.
-    while 
(am.getRegionStates().isRegionOnline(replicaParentRegion.getRegionInfo())) {
-      Thread.sleep(100);
-    }
-
-    assertNotNull("Should have found daughter regions for " + 
primaryDaughters, primaryDaughters);
-
-    // check that primary parent region is not in AM's serverHoldings
-    assertFalse("Primary Parent region should have been removed from 
RegionState's serverHoldings",
-        
am.getRegionStates().existsInServerHoldings(primaryParentRegion.getServerName(),
-            primaryParentRegion.getRegionInfo()));
-
-    // check that primary parent region is not in AM's serverHoldings
-    assertFalse("Primary Parent region should have been removed from 
RegionState's serverHoldings",
-        
am.getRegionStates().existsInServerHoldings(replicaParentRegion.getServerName(),
-            replicaParentRegion.getRegionInfo()));
+    final HRegionLocation primaryParentRegion
+      = RegionReplicaUtil.isDefaultReplica(
+      allRegionLocations.get(0).getRegionInfo().getReplicaId()) ? 
allRegionLocations.get(0)
+        : allRegionLocations.get(1);
+    final HRegionLocation replicaParentRegion
+      = RegionReplicaUtil.isDefaultReplica(
+      allRegionLocations.get(0).getRegionInfo().getReplicaId()) ? 
allRegionLocations.get(1)
+      : allRegionLocations.get(0);
+
+    assertNotNull("Should have found daughter regions for " + 
primaryParentRegion,
+      splitRegion(primaryParentRegion.getRegionInfo(), Bytes.toBytes("a")));
+
+    TEST_UTIL.waitFor(60 * 1000, new Waiter.Predicate<Exception>() {
+      @Override
+      public boolean evaluate() throws Exception {
+        return 
!am.getRegionStates().existsInServerHoldings(primaryParentRegion.getServerName(),
+          primaryParentRegion.getRegionInfo()) &&
+          
!am.getRegionStates().existsInServerHoldings(replicaParentRegion.getServerName(),
+            replicaParentRegion.getRegionInfo());
+      }
+    });
   }
 
   /*

Reply via email to