HBASE-22051 Expect values are hard-coded in the verifications of TestRSGroupsBasics

Signed-off-by: Xu Cang <xucang@apache.org>
This commit is contained in:
Xiang LI 2019-03-22 09:11:31 +08:00 committed by Xu Cang
parent d6f23388f5
commit 5aaa0f59c7
No known key found for this signature in database
GPG Key ID: 8E6C8FEDCA866394
1 changed files with 44 additions and 18 deletions

View File

@ -85,10 +85,10 @@ public class TestRSGroupsBasics extends TestRSGroupsBase {
@Test
public void testBasicStartUp() throws IOException {
RSGroupInfo defaultInfo = rsGroupAdmin.getRSGroupInfo(RSGroupInfo.DEFAULT_GROUP);
assertEquals(4, defaultInfo.getServers().size());
// Assignment of root and meta regions.
assertEquals(NUM_SLAVES_BASE, defaultInfo.getServers().size());
// Assignment of meta, namespace and rsgroup regions.
int count = master.getAssignmentManager().getRegionStates().getRegionAssignments().size();
//3 meta,namespace, group
// 3 (meta, namespace and rsgroup)
assertEquals(3, count);
}
@ -212,18 +212,26 @@ public class TestRSGroupsBasics extends TestRSGroupsBase {
@Test
public void testClearDeadServers() throws Exception {
LOG.info("testClearDeadServers");
final RSGroupInfo newGroup = addGroup(getGroupName(name.getMethodName()), 3);
// move region servers from default group to new group
final int serverCountToMoveToNewGroup = 3;
final RSGroupInfo newGroup =
addGroup(getGroupName(name.getMethodName()), serverCountToMoveToNewGroup);
// get the existing dead servers
NUM_DEAD_SERVERS = cluster.getClusterMetrics().getDeadServerNames().size();
ServerName targetServer = getServerName(newGroup.getServers().iterator().next());
// stop 1 region server in new group
ServerName serverToStop = getServerName(newGroup.getServers().iterator().next());
try {
// stopping may cause an exception
// due to the connection loss
admin.stopRegionServer(targetServer.getAddress().toString());
admin.stopRegionServer(serverToStop.getAddress().toString());
NUM_DEAD_SERVERS++;
} catch (Exception e) {
}
// wait for stopped regionserver to dead server list
// wait for the stopped region server to show up in the dead server list
TEST_UTIL.waitFor(WAIT_TIMEOUT, new Waiter.Predicate<Exception>() {
@Override
public boolean evaluate() throws Exception {
@ -231,29 +239,40 @@ public class TestRSGroupsBasics extends TestRSGroupsBase {
!master.getServerManager().areDeadServersInProgress();
}
});
assertFalse(cluster.getClusterMetrics().getLiveServerMetrics().containsKey(targetServer));
assertTrue(cluster.getClusterMetrics().getDeadServerNames().contains(targetServer));
assertTrue(newGroup.getServers().contains(targetServer.getAddress()));
// verify
assertFalse(cluster.getClusterMetrics().getLiveServerMetrics().containsKey(serverToStop));
assertTrue(cluster.getClusterMetrics().getDeadServerNames().contains(serverToStop));
assertTrue(newGroup.getServers().contains(serverToStop.getAddress()));
// clear dead servers list
List<ServerName> notClearedServers = admin.clearDeadServers(Lists.newArrayList(targetServer));
List<ServerName> notClearedServers = admin.clearDeadServers(Lists.newArrayList(serverToStop));
assertEquals(0, notClearedServers.size());
// verify if the stopped region server gets cleared and removed from the group
Set<Address> newGroupServers = rsGroupAdmin.getRSGroupInfo(newGroup.getName()).getServers();
assertFalse(newGroupServers.contains(targetServer.getAddress()));
assertEquals(2, newGroupServers.size());
assertFalse(newGroupServers.contains(serverToStop.getAddress()));
assertEquals(serverCountToMoveToNewGroup - 1 /* 1 stopped */, newGroupServers.size());
}
@Test
public void testClearNotProcessedDeadServer() throws Exception {
LOG.info("testClearNotProcessedDeadServer");
// get the existing dead servers
NUM_DEAD_SERVERS = cluster.getClusterMetrics().getDeadServerNames().size();
RSGroupInfo appInfo = addGroup("deadServerGroup", 1);
ServerName targetServer = getServerName(appInfo.getServers().iterator().next());
// move region servers from default group to "dead server" group
final int serverCountToMoveToDeadServerGroup = 1;
RSGroupInfo deadServerGroup =
addGroup("deadServerGroup", serverCountToMoveToDeadServerGroup);
// stop 1 region server in "dead server" group
ServerName serverToStop = getServerName(deadServerGroup.getServers().iterator().next());
try {
// stopping may cause an exception
// due to the connection loss
admin.stopRegionServer(targetServer.getAddress().toString());
admin.stopRegionServer(serverToStop.getAddress().toString());
NUM_DEAD_SERVERS++;
} catch (Exception e) {
}
@ -263,8 +282,15 @@ public class TestRSGroupsBasics extends TestRSGroupsBase {
return cluster.getClusterMetrics().getDeadServerNames().size() == NUM_DEAD_SERVERS;
}
});
List<ServerName> notClearedServers = admin.clearDeadServers(Lists.newArrayList(targetServer));
assertEquals(1, notClearedServers.size());
// the one and only region server in the group does not get cleared, even though it is stopped
List<ServerName> notClearedServers = admin.clearDeadServers(Lists.newArrayList(serverToStop));
assertEquals(serverCountToMoveToDeadServerGroup, notClearedServers.size());
Set<Address> ServersInDeadServerGroup =
rsGroupAdmin.getRSGroupInfo(deadServerGroup.getName()).getServers();
assertEquals(serverCountToMoveToDeadServerGroup, ServersInDeadServerGroup.size());
assertTrue(ServersInDeadServerGroup.contains(serverToStop.getAddress()));
}
@Test