HBASE-23125 TestRSGroupsAdmin2 is flaky

This commit is contained in:
Duo Zhang 2019-10-06 19:58:46 +08:00
parent 12852d30a3
commit 45cbe8b038
2 changed files with 19 additions and 35 deletions

View File

@ -20,7 +20,6 @@ package org.apache.hadoop.hbase.rsgroup;
import static org.apache.hadoop.hbase.util.Threads.sleep;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
@ -30,7 +29,6 @@ import java.util.EnumSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.Set;
import java.util.concurrent.atomic.AtomicBoolean;
import org.apache.hadoop.hbase.ClusterMetrics.Option;
@ -56,7 +54,6 @@ import org.junit.experimental.categories.Category;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.apache.hbase.thirdparty.com.google.common.base.Preconditions;
import org.apache.hbase.thirdparty.com.google.common.collect.Sets;
@Category({ LargeTests.class })

View File

@ -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);
}