You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by te...@apache.org on 2017/02/22 05:17:21 UTC

hbase git commit: HBASE-17657 TestZKAsyncRegistry is flaky

Repository: hbase
Updated Branches:
  refs/heads/master a0da66dc3 -> c579cf67b


HBASE-17657 TestZKAsyncRegistry is flaky


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

Branch: refs/heads/master
Commit: c579cf67b0eeb1eadff3188773988824c5c3f2a2
Parents: a0da66d
Author: tedyu <yu...@gmail.com>
Authored: Tue Feb 21 21:17:15 2017 -0800
Committer: tedyu <yu...@gmail.com>
Committed: Tue Feb 21 21:17:15 2017 -0800

----------------------------------------------------------------------
 .../hbase/client/TestZKAsyncRegistry.java       | 39 ++++++++++++++++++--
 1 file changed, 36 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hbase/blob/c579cf67/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestZKAsyncRegistry.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestZKAsyncRegistry.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestZKAsyncRegistry.java
index a94df61..11b9fd4 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestZKAsyncRegistry.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestZKAsyncRegistry.java
@@ -18,10 +18,13 @@
 package org.apache.hadoop.hbase.client;
 
 import static org.apache.hadoop.hbase.HConstants.META_REPLICAS_NUM;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
 
 import java.io.IOException;
 import java.util.concurrent.ExecutionException;
+import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.stream.IntStream;
 
 import org.apache.commons.io.IOUtils;
@@ -29,6 +32,7 @@ import org.apache.hadoop.hbase.HBaseTestingUtility;
 import org.apache.hadoop.hbase.HRegionLocation;
 import org.apache.hadoop.hbase.RegionLocations;
 import org.apache.hadoop.hbase.TableName;
+import org.apache.hadoop.hbase.Waiter.ExplainingPredicate;
 import org.apache.hadoop.hbase.testclassification.ClientTests;
 import org.apache.hadoop.hbase.testclassification.MediumTests;
 import org.junit.AfterClass;
@@ -43,11 +47,39 @@ public class TestZKAsyncRegistry {
 
   private static ZKAsyncRegistry REGISTRY;
 
+  // waits for all replicas to have region location
+  static void waitUntilAllReplicasHavingRegionLocation(TableName tbl) throws IOException {
+    TEST_UTIL.waitFor(TEST_UTIL.getConfiguration()
+        .getLong("hbase.client.sync.wait.timeout.msec", 60000),
+        200, true, new ExplainingPredicate<IOException>() {
+      @Override
+      public String explainFailure() throws IOException {
+        return TEST_UTIL.explainTableAvailability(tbl);
+      }
+
+      @Override
+      public boolean evaluate() throws IOException {
+        AtomicBoolean ready = new AtomicBoolean(true);
+        try {
+          RegionLocations locs = REGISTRY.getMetaRegionLocation().get();
+          assertEquals(3, locs.getRegionLocations().length);
+          IntStream.range(0, 3).forEach(i -> {
+            HRegionLocation loc = locs.getRegionLocation(i);
+            if (loc == null) {
+              ready.set(false);
+            }
+          });
+        } catch (Exception e) {
+          ready.set(false);
+        }
+        return ready.get();
+      }
+    });
+  }
   @BeforeClass
   public static void setUp() throws Exception {
     TEST_UTIL.getConfiguration().setInt(META_REPLICAS_NUM, 3);
     TEST_UTIL.startMiniCluster(3);
-    TEST_UTIL.waitUntilAllRegionsAssigned(TableName.META_TABLE_NAME);
     REGISTRY = new ZKAsyncRegistry(TEST_UTIL.getConfiguration());
   }
 
@@ -66,11 +98,12 @@ public class TestZKAsyncRegistry {
     assertEquals(TEST_UTIL.getHBaseCluster().getMaster().getServerName(),
       REGISTRY.getMasterAddress().get());
     assertEquals(-1, REGISTRY.getMasterInfoPort().get().intValue());
+    waitUntilAllReplicasHavingRegionLocation(TableName.META_TABLE_NAME);
     RegionLocations locs = REGISTRY.getMetaRegionLocation().get();
     assertEquals(3, locs.getRegionLocations().length);
     IntStream.range(0, 3).forEach(i -> {
       HRegionLocation loc = locs.getRegionLocation(i);
-      assertNotNull(loc);
+      assertNotNull("Replica " + i + " doesn't have location", loc);
       assertTrue(loc.getRegionInfo().getTable().equals(TableName.META_TABLE_NAME));
       assertEquals(i, loc.getRegionInfo().getReplicaId());
     });