1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.hadoop.hbase;
20
21 import java.io.IOException;
22
23 import javax.management.MBeanServerConnection;
24 import javax.management.remote.JMXConnector;
25 import javax.management.remote.JMXConnectorFactory;
26
27 import org.apache.commons.logging.Log;
28 import org.apache.commons.logging.LogFactory;
29 import org.apache.hadoop.conf.Configuration;
30 import org.apache.hadoop.hbase.coprocessor.CoprocessorHost;
31 import org.apache.hadoop.hbase.testclassification.MediumTests;
32 import org.junit.AfterClass;
33 import org.junit.Assert;
34 import org.junit.BeforeClass;
35 import org.junit.Rule;
36 import org.junit.Test;
37 import org.junit.experimental.categories.Category;
38 import org.junit.rules.ExpectedException;
39
40
41
42 @Category(MediumTests.class)
43 public class TestJMXListener {
44 private static final Log LOG = LogFactory.getLog(TestJMXListener.class);
45 private static HBaseTestingUtility UTIL = new HBaseTestingUtility();
46 private static int connectorPort = 61120;
47
48 @BeforeClass
49 public static void setupBeforeClass() throws Exception {
50 Configuration conf = UTIL.getConfiguration();
51
52 conf.set(CoprocessorHost.REGIONSERVER_COPROCESSOR_CONF_KEY,
53 JMXListener.class.getName());
54 conf.setInt("regionserver.rmi.registry.port", connectorPort);
55
56 UTIL.startMiniCluster();
57 }
58
59 @AfterClass
60 public static void tearDownAfterClass() throws Exception {
61 UTIL.shutdownMiniCluster();
62 }
63
64 @Test
65 public void testStart() throws Exception {
66 JMXConnector connector = JMXConnectorFactory.connect(
67 JMXListener.buildJMXServiceURL(connectorPort,connectorPort));
68
69 MBeanServerConnection mb = connector.getMBeanServerConnection();
70 String domain = mb.getDefaultDomain();
71 Assert.assertTrue("default domain is not correct",
72 !domain.isEmpty());
73 connector.close();
74
75 }
76
77
78 @Rule
79 public ExpectedException expectedEx = ExpectedException.none();
80 @Test
81 public void testStop() throws Exception {
82 MiniHBaseCluster cluster = UTIL.getHBaseCluster();
83 LOG.info("shutdown hbase cluster...");
84 cluster.shutdown();
85 LOG.info("wait for the hbase cluster shutdown...");
86 cluster.waitUntilShutDown();
87
88 JMXConnector connector = JMXConnectorFactory.newJMXConnector(
89 JMXListener.buildJMXServiceURL(connectorPort,connectorPort), null);
90 expectedEx.expect(IOException.class);
91 connector.connect();
92
93 }
94
95
96 }