This is an automated email from the ASF dual-hosted git repository.

zhangduo pushed a commit to branch branch-2.2
in repository https://gitbox.apache.org/repos/asf/hbase.git


The following commit(s) were added to refs/heads/branch-2.2 by this push:
     new dbb6527  HBASE-23125 TestRSGroupsAdmin2 is flaky
dbb6527 is described below

commit dbb6527dc4464af0d9375bd29a832576f9ed919c
Author: Duo Zhang <[email protected]>
AuthorDate: Sun Oct 6 19:58:46 2019 +0800

    HBASE-23125 TestRSGroupsAdmin2 is flaky
---
 .../hadoop/hbase/rsgroup/TestRSGroupsBase.java     | 51 ++++++++--------------
 1 file changed, 19 insertions(+), 32 deletions(-)

diff --git 
a/hbase-rsgroup/src/test/java/org/apache/hadoop/hbase/rsgroup/TestRSGroupsBase.java
 
b/hbase-rsgroup/src/test/java/org/apache/hadoop/hbase/rsgroup/TestRSGroupsBase.java
index 4ebcb61..8d7a67f 100644
--- 
a/hbase-rsgroup/src/test/java/org/apache/hadoop/hbase/rsgroup/TestRSGroupsBase.java
+++ 
b/hbase-rsgroup/src/test/java/org/apache/hadoop/hbase/rsgroup/TestRSGroupsBase.java
@@ -20,6 +20,7 @@ package org.apache.hadoop.hbase.rsgroup;
 import static org.junit.Assert.assertTrue;
 
 import java.io.IOException;
+import java.util.ArrayList;
 import java.util.EnumSet;
 import java.util.HashSet;
 import java.util.LinkedList;
@@ -37,8 +38,6 @@ import org.apache.hadoop.hbase.HBaseTestingUtility;
 import org.apache.hadoop.hbase.HConstants;
 import org.apache.hadoop.hbase.MiniHBaseCluster;
 import org.apache.hadoop.hbase.NamespaceDescriptor;
-import org.apache.hadoop.hbase.RegionMetrics;
-import org.apache.hadoop.hbase.ServerMetrics;
 import org.apache.hadoop.hbase.ServerName;
 import org.apache.hadoop.hbase.TableName;
 import org.apache.hadoop.hbase.Waiter;
@@ -55,7 +54,6 @@ import org.apache.hadoop.hbase.master.MasterCoprocessorHost;
 import org.apache.hadoop.hbase.master.ServerManager;
 import org.apache.hadoop.hbase.master.snapshot.SnapshotManager;
 import org.apache.hadoop.hbase.net.Address;
-import org.apache.hadoop.hbase.util.Bytes;
 import org.junit.Rule;
 import org.junit.rules.TestName;
 import org.slf4j.Logger;
@@ -183,7 +181,7 @@ public abstract class TestRSGroupsBase {
     });
   }
 
-  public RSGroupInfo addGroup(String groupName, int serverCount)
+  protected RSGroupInfo addGroup(String groupName, int serverCount)
       throws IOException, InterruptedException {
     RSGroupInfo defaultInfo = 
rsGroupAdmin.getRSGroupInfo(RSGroupInfo.DEFAULT_GROUP);
     rsGroupAdmin.addRSGroup(groupName);
@@ -199,21 +197,21 @@ public abstract class TestRSGroupsBase {
     return result;
   }
 
-  public void removeGroup(String groupName) throws IOException {
+  protected void removeGroup(String groupName) throws IOException {
     RSGroupInfo groupInfo = rsGroupAdmin.getRSGroupInfo(groupName);
     rsGroupAdmin.moveTables(groupInfo.getTables(), RSGroupInfo.DEFAULT_GROUP);
     rsGroupAdmin.moveServers(groupInfo.getServers(), 
RSGroupInfo.DEFAULT_GROUP);
     rsGroupAdmin.removeRSGroup(groupName);
   }
 
-  public void deleteTableIfNecessary() throws IOException {
+  protected void deleteTableIfNecessary() throws IOException {
     for (TableDescriptor desc : TEST_UTIL.getAdmin()
       .listTableDescriptors(Pattern.compile(tablePrefix + ".*"))) {
       TEST_UTIL.deleteTable(desc.getTableName());
     }
   }
 
-  public void deleteNamespaceIfNecessary() throws IOException {
+  protected void deleteNamespaceIfNecessary() throws IOException {
     for (NamespaceDescriptor desc : 
TEST_UTIL.getAdmin().listNamespaceDescriptors()) {
       if(desc.getName().startsWith(tablePrefix)) {
         admin.deleteNamespace(desc.getName());
@@ -221,7 +219,7 @@ public abstract class TestRSGroupsBase {
     }
   }
 
-  public void deleteGroups() throws IOException {
+  protected void deleteGroups() throws IOException {
     RSGroupAdmin groupAdmin = new 
RSGroupAdminClient(TEST_UTIL.getConnection());
     for(RSGroupInfo group: groupAdmin.listRSGroups()) {
       if(!group.getName().equals(RSGroupInfo.DEFAULT_GROUP)) {
@@ -232,7 +230,7 @@ public abstract class TestRSGroupsBase {
     }
   }
 
-  public Map<TableName, List<String>> getTableRegionMap() throws IOException {
+  protected Map<TableName, List<String>> getTableRegionMap() throws 
IOException {
     Map<TableName, List<String>> map = Maps.newTreeMap();
     Map<TableName, Map<ServerName, List<String>>> tableServerRegionMap
         = getTableServerRegionMap();
@@ -247,35 +245,24 @@ public abstract class TestRSGroupsBase {
     return map;
   }
 
-  public Map<TableName, Map<ServerName, List<String>>> 
getTableServerRegionMap()
-      throws IOException {
+  protected Map<TableName, Map<ServerName, List<String>>> 
getTableServerRegionMap()
+    throws IOException {
     Map<TableName, Map<ServerName, List<String>>> map = Maps.newTreeMap();
-    ClusterMetrics status = 
TEST_UTIL.getHBaseClusterInterface().getClusterMetrics();
-    for (Map.Entry<ServerName, ServerMetrics> entry : 
status.getLiveServerMetrics().entrySet()) {
-      ServerName serverName = entry.getKey();
-      for(RegionMetrics rl : entry.getValue().getRegionMetrics().values()) {
-        TableName tableName = null;
-        try {
-          tableName = RegionInfo.getTable(rl.getRegionName());
-        } catch (IllegalArgumentException e) {
-          LOG.warn("Failed parse a table name from regionname=" +
-            Bytes.toStringBinary(rl.getRegionName()));
-          continue;
-        }
-        if(!map.containsKey(tableName)) {
-          map.put(tableName, new TreeMap<>());
-        }
-        if(!map.get(tableName).containsKey(serverName)) {
-          map.get(tableName).put(serverName, new LinkedList<>());
-        }
-        map.get(tableName).get(serverName).add(rl.getNameAsString());
+    Admin admin = TEST_UTIL.getAdmin();
+    ClusterMetrics metrics =
+      admin.getClusterMetrics(EnumSet.of(ClusterMetrics.Option.SERVERS_NAME));
+    for (ServerName serverName : metrics.getServersName()) {
+      for (RegionInfo region : admin.getRegions(serverName)) {
+        TableName tableName = region.getTable();
+        map.computeIfAbsent(tableName, k -> new TreeMap<>())
+          .computeIfAbsent(serverName, k -> new 
ArrayList<>()).add(region.getRegionNameAsString());
       }
     }
     return map;
   }
 
   // return the real number of region servers, excluding the master embedded 
region server in 2.0+
-  public int getNumServers() throws IOException {
+  protected int getNumServers() throws IOException {
     ClusterMetrics status =
         admin.getClusterMetrics(EnumSet.of(Option.MASTER, 
Option.LIVE_SERVERS));
     ServerName masterName = status.getMasterName();
@@ -288,7 +275,7 @@ public abstract class TestRSGroupsBase {
     return count;
   }
 
-  public String getGroupName(String baseName) {
+  protected String getGroupName(String baseName) {
     return groupPrefix + "_" + baseName + "_" + 
rand.nextInt(Integer.MAX_VALUE);
   }
 

Reply via email to