HBASE-24399 [Flakey Tests] Some UTs about RSGroup should wait RSGroupInfoManager to be online (#1738)

Signed-off-by: Guanghao Zhang <zghao@apache.org>
This commit is contained in:
XinSun 2020-05-20 15:10:21 +08:00 committed by Guanghao Zhang
parent 6f5e5e4828
commit 69d8d4b894
4 changed files with 62 additions and 37 deletions

View File

@ -20,7 +20,9 @@ package org.apache.hadoop.hbase.master.procedure;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.Waiter.Predicate;
import org.apache.hadoop.hbase.coprocessor.CoprocessorHost;
import org.apache.hadoop.hbase.master.HMaster;
import org.apache.hadoop.hbase.master.LoadBalancer;
import org.apache.hadoop.hbase.rsgroup.RSGroupAdminEndpoint;
import org.apache.hadoop.hbase.rsgroup.RSGroupBasedLoadBalancer;
@ -55,6 +57,9 @@ public class TestSCPWithReplicasWithRSGroup extends TestSCPBase {
@Test
public void testCrashTargetRs() throws Exception {
HMaster master = util.getHBaseCluster().getMaster();
util.waitFor(60000, (Predicate<Exception>) () ->
master.isInitialized() && ((RSGroupBasedLoadBalancer) master.getLoadBalancer()).isOnline());
testRecoveryAndDoubleExecution(false, false);
}
}

View File

@ -18,27 +18,28 @@
package org.apache.hadoop.hbase.rsgroup;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.anyString;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import java.io.IOException;
import java.util.Collections;
import java.util.List;
import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.NamespaceDescriptor;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.Waiter.Predicate;
import org.apache.hadoop.hbase.client.Admin;
import org.apache.hadoop.hbase.coprocessor.CoprocessorHost;
import org.apache.hadoop.hbase.master.HMaster;
import org.apache.hadoop.hbase.regionserver.HRegionServer;
import org.apache.hadoop.hbase.rsgroup.RSGroupInfoManagerImpl.RSGroupMappingScript;
import org.apache.hadoop.hbase.testclassification.MediumTests;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.Test;
@ -87,6 +88,14 @@ public class TestDetermineRSGroupInfoForTable {
admin = UTIL.getAdmin();
rsGroupAdminClient = new RSGroupAdminClient(UTIL.getConnection());
UTIL.waitFor(60000, (Predicate<Exception>) () ->
master.isInitialized() && ((RSGroupBasedLoadBalancer) master.getLoadBalancer()).isOnline());
List<RSGroupAdminEndpoint> cps =
master.getMasterCoprocessorHost().findCoprocessors(RSGroupAdminEndpoint.class);
assertTrue(cps.size() > 0);
rsGroupInfoManager = cps.get(0).getGroupInfoManager();
HRegionServer rs = UTIL.getHBaseCluster().getRegionServer(0);
rsGroupAdminClient.addRSGroup(GROUP_NAME);
rsGroupAdminClient.moveServers(
@ -98,23 +107,12 @@ public class TestDetermineRSGroupInfoForTable {
}
@AfterClass
public static void tearDown() throws IOException {
public static void tearDown() throws Exception {
admin.deleteNamespace(NAMESPACE_NAME);
UTIL.shutdownMiniCluster();
}
@Before
public void setUpBeforeMethod() throws IOException {
rsGroupInfoManager = RSGroupInfoManagerImpl.getInstance(master);
rsGroupInfoManager.start();
}
@After
public void tearDownAfterMethod() throws IOException {
rsGroupInfoManager = RSGroupInfoManagerImpl.getInstance(master);
}
@Test
public void testByDefault() throws IOException {
RSGroupInfo group =
@ -139,10 +137,13 @@ public class TestDetermineRSGroupInfoForTable {
public void testDetermineByScript() throws IOException {
RSGroupMappingScript script = mock(RSGroupMappingScript.class);
when(script.getRSGroup(anyString(), anyString())).thenReturn(GROUP_NAME);
RSGroupMappingScript oldScript = ((RSGroupInfoManagerImpl) rsGroupInfoManager).script;
((RSGroupInfoManagerImpl) rsGroupInfoManager).script = script;
RSGroupInfo group = rsGroupInfoManager.determineRSGroupInfoForTable(TABLE_NAME);
assertEquals(group.getName(), GROUP_NAME);
// reset script to avoid affecting other tests
((RSGroupInfoManagerImpl) rsGroupInfoManager).script = oldScript;
}
}

View File

@ -17,26 +17,39 @@
*/
package org.apache.hadoop.hbase.rsgroup;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import java.io.IOException;
import java.util.Collections;
import java.util.List;
import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.NamespaceDescriptor;
import org.apache.hadoop.hbase.client.Admin;
import org.apache.hadoop.hbase.Waiter.Predicate;
import org.apache.hadoop.hbase.coprocessor.CoprocessorHost;
import org.apache.hadoop.hbase.master.HMaster;
import org.apache.hadoop.hbase.regionserver.HRegionServer;
import org.apache.hadoop.hbase.testclassification.MediumTests;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Category({MediumTests.class})
public class TestRSGroupUtil {
private static final HBaseTestingUtility UTIL = new HBaseTestingUtility();
@ClassRule
public static final HBaseClassTestRule CLASS_RULE =
HBaseClassTestRule.forClass(TestRSGroupUtil.class);
private static Admin admin;
private static final Logger LOG = LoggerFactory.getLogger(TestRSGroupUtil.class);
private static final HBaseTestingUtility UTIL = new HBaseTestingUtility();
private static HMaster master;
@ -44,8 +57,6 @@ public class TestRSGroupUtil {
private static final String GROUP_NAME = "rsg";
private static final String NAMESPACE_NAME = "ns";
private static RSGroupInfoManager rsGroupInfoManager;
@BeforeClass
@ -57,24 +68,20 @@ public class TestRSGroupUtil {
RSGroupAdminEndpoint.class.getName());
UTIL.startMiniCluster(5);
master = UTIL.getMiniHBaseCluster().getMaster();
admin = UTIL.getAdmin();
UTIL.waitFor(60000, (Predicate<Exception>) () ->
master.isInitialized() && ((RSGroupBasedLoadBalancer) master.getLoadBalancer()).isOnline());
rsGroupAdminClient = new RSGroupAdminClient(UTIL.getConnection());
HRegionServer rs = UTIL.getHBaseCluster().getRegionServer(0);
rsGroupAdminClient.addRSGroup(GROUP_NAME);
rsGroupAdminClient.moveServers(Collections.singleton(rs.getServerName().getAddress()), GROUP_NAME);
admin.createNamespace(NamespaceDescriptor.create(NAMESPACE_NAME)
.addConfiguration(RSGroupInfo.NAMESPACE_DESC_PROP_GROUP, GROUP_NAME)
.build());
rsGroupInfoManager = RSGroupInfoManagerImpl.getInstance(master);
rsGroupInfoManager.start();
List<RSGroupAdminEndpoint> cps =
master.getMasterCoprocessorHost().findCoprocessors(RSGroupAdminEndpoint.class);
assertTrue(cps.size() > 0);
rsGroupInfoManager = cps.get(0).getGroupInfoManager();
}
@AfterClass
public static void tearDown() throws IOException {
admin.deleteNamespace(NAMESPACE_NAME);
public static void tearDown() throws Exception {
UTIL.shutdownMiniCluster();
}
@ -82,14 +89,19 @@ public class TestRSGroupUtil {
public void rsGroupHasOnlineServer() throws IOException {
rsGroupInfoManager.refresh();
RSGroupInfo defaultGroup = rsGroupInfoManager.getRSGroup(RSGroupInfo.DEFAULT_GROUP);
Assert.assertTrue(RSGroupUtil.rsGroupHasOnlineServer(master, defaultGroup));
assertTrue(RSGroupUtil.rsGroupHasOnlineServer(master, defaultGroup));
HRegionServer rs = UTIL.getHBaseCluster().getRegionServer(0);
rsGroupAdminClient.addRSGroup(GROUP_NAME);
rsGroupAdminClient.moveServers(Collections.singleton(rs.getServerName().getAddress()), GROUP_NAME);
rsGroupInfoManager.refresh();
RSGroupInfo rsGroup = rsGroupInfoManager.getRSGroup(GROUP_NAME);
Assert.assertTrue(RSGroupUtil.rsGroupHasOnlineServer(master, rsGroup));
assertTrue(RSGroupUtil.rsGroupHasOnlineServer(master, rsGroup));
rsGroupAdminClient.addRSGroup("empty");
rsGroupInfoManager.refresh();
RSGroupInfo emptyGroup = rsGroupInfoManager.getRSGroup("empty");
Assert.assertFalse(RSGroupUtil.rsGroupHasOnlineServer(master, emptyGroup));
assertFalse(RSGroupUtil.rsGroupHasOnlineServer(master, emptyGroup));
}
}

View File

@ -27,10 +27,12 @@ import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.TableNotFoundException;
import org.apache.hadoop.hbase.Waiter.Predicate;
import org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder;
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.TableDescriptorBuilder;
import org.apache.hadoop.hbase.coprocessor.CoprocessorHost;
import org.apache.hadoop.hbase.master.HMaster;
import org.apache.hadoop.hbase.security.User;
import org.apache.hadoop.hbase.security.access.AccessControlClient;
import org.apache.hadoop.hbase.security.access.Permission;
@ -108,6 +110,11 @@ public class TestRSGroupsWithACL extends SecureTestUtil{
configureRSGroupAdminEndpoint(conf);
TEST_UTIL.startMiniCluster();
HMaster master = TEST_UTIL.getHBaseCluster().getMaster();
TEST_UTIL.waitFor(60000, (Predicate<Exception>) () ->
master.isInitialized() && ((RSGroupBasedLoadBalancer) master.getLoadBalancer()).isOnline());
rsGroupAdminEndpoint = (RSGroupAdminEndpoint) TEST_UTIL.getMiniHBaseCluster().getMaster().
getMasterCoprocessorHost().findCoprocessor(RSGroupAdminEndpoint.class.getName());
// Wait for the ACL table to become available