Repository: hbase
Updated Branches:
  refs/heads/branch-2 74ab10c35 -> 2487b4603


HBASE-20363 TestNamespaceAuditor.testRegionMerge is flaky


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

Branch: refs/heads/branch-2
Commit: 2487b4603cbcd3b634966401ceb7bd40315ccaec
Parents: 74ab10c
Author: zhangduo <zhang...@apache.org>
Authored: Sun Apr 8 16:29:01 2018 +0800
Committer: zhangduo <zhang...@apache.org>
Committed: Mon Apr 9 21:02:42 2018 +0800

----------------------------------------------------------------------
 .../hbase/namespace/TestNamespaceAuditor.java   | 32 ++++++++++++--------
 1 file changed, 19 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hbase/blob/2487b460/hbase-server/src/test/java/org/apache/hadoop/hbase/namespace/TestNamespaceAuditor.java
----------------------------------------------------------------------
diff --git 
a/hbase-server/src/test/java/org/apache/hadoop/hbase/namespace/TestNamespaceAuditor.java
 
b/hbase-server/src/test/java/org/apache/hadoop/hbase/namespace/TestNamespaceAuditor.java
index 89687eb..1b4957a 100644
--- 
a/hbase-server/src/test/java/org/apache/hadoop/hbase/namespace/TestNamespaceAuditor.java
+++ 
b/hbase-server/src/test/java/org/apache/hadoop/hbase/namespace/TestNamespaceAuditor.java
@@ -72,6 +72,7 @@ import org.apache.hadoop.hbase.master.TableNamespaceManager;
 import org.apache.hadoop.hbase.quotas.MasterQuotaManager;
 import org.apache.hadoop.hbase.quotas.QuotaExceededException;
 import org.apache.hadoop.hbase.quotas.QuotaUtil;
+import org.apache.hadoop.hbase.regionserver.HRegion;
 import org.apache.hadoop.hbase.regionserver.Store;
 import org.apache.hadoop.hbase.regionserver.StoreFile;
 import 
org.apache.hadoop.hbase.regionserver.compactions.CompactionLifeCycleTracker;
@@ -348,24 +349,30 @@ public class TestNamespaceAuditor {
       UTIL.loadNumericRows(table, Bytes.toBytes("info"), 1000, 1999);
     }
     ADMIN.flush(tableTwo);
-    List<HRegionInfo> hris = ADMIN.getTableRegions(tableTwo);
+    List<RegionInfo> hris = ADMIN.getRegions(tableTwo);
     assertEquals(initialRegions, hris.size());
-    Collections.sort(hris);
+    Collections.sort(hris, RegionInfo.COMPARATOR);
     Future<?> f = ADMIN.mergeRegionsAsync(
       hris.get(0).getEncodedNameAsBytes(),
       hris.get(1).getEncodedNameAsBytes(),
       false);
     f.get(10, TimeUnit.SECONDS);
 
-    hris = ADMIN.getTableRegions(tableTwo);
+    hris = ADMIN.getRegions(tableTwo);
     assertEquals(initialRegions - 1, hris.size());
-    Collections.sort(hris);
-    ADMIN.split(tableTwo, Bytes.toBytes("3"));
-    // Not much we can do here until we have split return a Future.
-    Threads.sleep(5000);
-    hris = ADMIN.getTableRegions(tableTwo);
+    Collections.sort(hris, RegionInfo.COMPARATOR);
+    byte[] splitKey = Bytes.toBytes("3");
+    HRegion regionToSplit = 
UTIL.getMiniHBaseCluster().getRegions(tableTwo).stream()
+      .filter(r -> r.getRegionInfo().containsRow(splitKey)).findFirst().get();
+    regionToSplit.compact(true);
+    // the above compact may quit immediately if there is a compaction 
ongoing, so here we need to
+    // wait a while to let the ongoing compaction finish.
+    UTIL.waitFor(10000, regionToSplit::isSplittable);
+    ADMIN.splitRegionAsync(regionToSplit.getRegionInfo().getRegionName(), 
splitKey).get(10,
+      TimeUnit.SECONDS);
+    hris = ADMIN.getRegions(tableTwo);
     assertEquals(initialRegions, hris.size());
-    Collections.sort(hris);
+    Collections.sort(hris, RegionInfo.COMPARATOR);
 
     // Fail region merge through Coprocessor hook
     MiniHBaseCluster cluster = UTIL.getHBaseCluster();
@@ -384,11 +391,10 @@ public class TestNamespaceAuditor {
     } catch (ExecutionException ee) {
       // Expected.
     }
-    hris = ADMIN.getTableRegions(tableTwo);
+    hris = ADMIN.getRegions(tableTwo);
     assertEquals(initialRegions, hris.size());
-    Collections.sort(hris);
+    Collections.sort(hris, RegionInfo.COMPARATOR);
     // verify that we cannot split
-    HRegionInfo hriToSplit2 = hris.get(1);
     try {
       ADMIN.split(tableTwo, Bytes.toBytes("6"));
       fail();
@@ -396,7 +402,7 @@ public class TestNamespaceAuditor {
       // Expected
     }
     Thread.sleep(2000);
-    assertEquals(initialRegions, ADMIN.getTableRegions(tableTwo).size());
+    assertEquals(initialRegions, ADMIN.getRegions(tableTwo).size());
   }
 
   /*

Reply via email to