You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by zg...@apache.org on 2020/08/31 02:36:47 UTC
[hbase] branch branch-2.2 updated: HBASE-24913 Refactor
TestJMXConnectorServer (#2286)
This is an automated email from the ASF dual-hosted git repository.
zghao 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 39ebc3e HBASE-24913 Refactor TestJMXConnectorServer (#2286)
39ebc3e is described below
commit 39ebc3ec76cd18862c364b224d882979687d98de
Author: XinSun <dd...@gmail.com>
AuthorDate: Mon Aug 31 10:23:59 2020 +0800
HBASE-24913 Refactor TestJMXConnectorServer (#2286)
Signed-off-by: Guanghao Zhang <zg...@apache.org>
---
.../hadoop/hbase/TestJMXConnectorServer.java | 93 ++++++++--------------
1 file changed, 35 insertions(+), 58 deletions(-)
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/TestJMXConnectorServer.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/TestJMXConnectorServer.java
index 2b94b7f..3035401 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/TestJMXConnectorServer.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/TestJMXConnectorServer.java
@@ -32,8 +32,10 @@ import org.apache.hadoop.hbase.security.access.AccessController;
import org.apache.hadoop.hbase.testclassification.MediumTests;
import org.apache.hadoop.hbase.testclassification.MiscTests;
import org.junit.After;
+import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.Before;
+import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.experimental.categories.Category;
@@ -56,39 +58,47 @@ public class TestJMXConnectorServer {
private static Configuration conf = null;
private static Admin admin;
// RMI registry port
- private static int rmiRegistryPort = 61120;
+ private static int rmiRegistryPort;
// Switch for customized Accesscontroller to throw ACD exception while executing test case
- static boolean hasAccess;
+ private volatile static boolean hasAccess;
- @Before
- public void setUp() throws Exception {
- UTIL = new HBaseTestingUtility();
+ @BeforeClass
+ public static void setUpBeforeClass() throws Exception {
conf = UTIL.getConfiguration();
+ String cps = JMXListener.class.getName() + "," + MyAccessController.class.getName();
+ conf.set(CoprocessorHost.MASTER_COPROCESSOR_CONF_KEY, cps);
+ conf.set(CoprocessorHost.REGIONSERVER_COPROCESSOR_CONF_KEY, cps);
+ rmiRegistryPort = UTIL.randomFreePort();
+ conf.setInt("master.rmi.registry.port", rmiRegistryPort);
+ conf.setInt("regionserver.rmi.registry.port", rmiRegistryPort);
+ UTIL.startMiniCluster();
+ admin = UTIL.getConnection().getAdmin();
}
- @After
- public void tearDown() throws Exception {
- // Set to true while stopping cluster
- hasAccess = true;
+ @AfterClass
+ public static void tearDownAfterClass() throws Exception {
admin.close();
UTIL.shutdownMiniCluster();
}
+ @Before
+ public void setUp() {
+ hasAccess = false;
+ }
+
+ @After
+ public void tearDown() {
+ hasAccess = true;
+ }
+
/**
* This tests to validate the HMaster's ConnectorServer after unauthorised stopMaster call.
*/
@Test
public void testHMConnectorServerWhenStopMaster() throws Exception {
- conf.set(CoprocessorHost.MASTER_COPROCESSOR_CONF_KEY,
- JMXListener.class.getName() + "," + MyAccessController.class.getName());
- conf.setInt("master.rmi.registry.port", rmiRegistryPort);
- UTIL.startMiniCluster();
- admin = UTIL.getConnection().getAdmin();
-
// try to stop master
boolean accessDenied = false;
try {
- hasAccess = false;
LOG.info("Stopping HMaster...");
admin.stopMaster();
} catch (AccessDeniedException e) {
@@ -97,18 +107,7 @@ public class TestJMXConnectorServer {
}
Assert.assertTrue(accessDenied);
- // Check whether HMaster JMX Connector server can be connected
- JMXConnector connector = null;
- try {
- connector = JMXConnectorFactory
- .connect(JMXListener.buildJMXServiceURL(rmiRegistryPort, rmiRegistryPort));
- } catch (IOException e) {
- if (e.getCause() instanceof ServiceUnavailableException) {
- Assert.fail("Can't connect to HMaster ConnectorServer.");
- }
- }
- Assert.assertNotNull("JMXConnector should not be null.", connector);
- connector.close();
+ checkConnector();
}
/**
@@ -117,29 +116,11 @@ public class TestJMXConnectorServer {
*/
@Test
public void testRSConnectorServerWhenStopRegionServer() throws Exception {
- conf.set(CoprocessorHost.REGIONSERVER_COPROCESSOR_CONF_KEY,
- JMXListener.class.getName() + "," + MyAccessController.class.getName());
- conf.setInt("regionserver.rmi.registry.port", rmiRegistryPort);
- UTIL.startMiniCluster();
- admin = UTIL.getConnection().getAdmin();
-
- hasAccess = false;
ServerName serverName = UTIL.getHBaseCluster().getRegionServer(0).getServerName();
LOG.info("Stopping Region Server...");
admin.stopRegionServer(serverName.getHostname() + ":" + serverName.getPort());
- // Check whether Region Sever JMX Connector server can be connected
- JMXConnector connector = null;
- try {
- connector = JMXConnectorFactory
- .connect(JMXListener.buildJMXServiceURL(rmiRegistryPort, rmiRegistryPort));
- } catch (IOException e) {
- if (e.getCause() instanceof ServiceUnavailableException) {
- Assert.fail("Can't connect to Region Server ConnectorServer.");
- }
- }
- Assert.assertNotNull("JMXConnector should not be null.", connector);
- connector.close();
+ checkConnector();
}
/**
@@ -147,16 +128,8 @@ public class TestJMXConnectorServer {
*/
@Test
public void testHMConnectorServerWhenShutdownCluster() throws Exception {
- conf.set(CoprocessorHost.MASTER_COPROCESSOR_CONF_KEY,
- JMXListener.class.getName() + "," + MyAccessController.class.getName());
- conf.setInt("master.rmi.registry.port", rmiRegistryPort);
-
- UTIL.startMiniCluster();
- admin = UTIL.getConnection().getAdmin();
-
boolean accessDenied = false;
try {
- hasAccess = false;
LOG.info("Stopping HMaster...");
admin.shutdown();
} catch (AccessDeniedException e) {
@@ -165,14 +138,18 @@ public class TestJMXConnectorServer {
}
Assert.assertTrue(accessDenied);
+ checkConnector();
+ }
+
+ private void checkConnector() throws Exception {
// Check whether HMaster JMX Connector server can be connected
JMXConnector connector = null;
try {
connector = JMXConnectorFactory
- .connect(JMXListener.buildJMXServiceURL(rmiRegistryPort, rmiRegistryPort));
+ .connect(JMXListener.buildJMXServiceURL(rmiRegistryPort, rmiRegistryPort));
} catch (IOException e) {
if (e.getCause() instanceof ServiceUnavailableException) {
- Assert.fail("Can't connect to HMaster ConnectorServer.");
+ Assert.fail("Can't connect to ConnectorServer.");
}
}
Assert.assertNotNull("JMXConnector should not be null.", connector);
@@ -185,7 +162,7 @@ public class TestJMXConnectorServer {
*/
public static class MyAccessController extends AccessController {
@Override
- public void postStartMaster(ObserverContext<MasterCoprocessorEnvironment> ctx) throws IOException {
+ public void postStartMaster(ObserverContext<MasterCoprocessorEnvironment> ctx) {
// Do nothing. In particular, stop the creation of the hbase:acl table. It makes the
// shutdown take time.
}