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.junit.AfterClass;
32 import org.junit.Assert;
33 import org.junit.BeforeClass;
34 import org.junit.Rule;
35 import org.junit.Test;
36 import org.junit.experimental.categories.Category;
37 import org.junit.rules.ExpectedException;
38
39
40
41 @Category(MediumTests.class)
42 public class TestJMXListener {
43 private static final Log LOG = LogFactory.getLog(TestJMXListener.class);
44 private static HBaseTestingUtility UTIL = new HBaseTestingUtility();
45 private static int connectorPort = 61120;
46
47 @BeforeClass
48 public static void setupBeforeClass() throws Exception {
49 Configuration conf = UTIL.getConfiguration();
50
51 conf.set(CoprocessorHost.REGIONSERVER_COPROCESSOR_CONF_KEY,
52 JMXListener.class.getName());
53 conf.setInt("regionserver.rmi.registry.port", connectorPort);
54
55 UTIL.startMiniCluster();
56 }
57
58 @AfterClass
59 public static void tearDownAfterClass() throws Exception {
60 UTIL.shutdownMiniCluster();
61 }
62
63 @Test
64 public void testStart() throws Exception {
65 JMXConnector connector = JMXConnectorFactory.connect(
66 JMXListener.buildJMXServiceURL(connectorPort,connectorPort));
67
68 MBeanServerConnection mb = connector.getMBeanServerConnection();
69 String domain = mb.getDefaultDomain();
70 Assert.assertTrue("default domain is not correct",
71 !domain.isEmpty());
72 connector.close();
73
74 }
75
76
77 @Rule
78 public ExpectedException expectedEx = ExpectedException.none();
79 @Test
80 public void testStop() throws Exception {
81 MiniHBaseCluster cluster = UTIL.getHBaseCluster();
82 LOG.info("shutdown hbase cluster...");
83 cluster.shutdown();
84 LOG.info("wait for the hbase cluster shutdown...");
85 cluster.waitUntilShutDown();
86
87 JMXConnector connector = JMXConnectorFactory.newJMXConnector(
88 JMXListener.buildJMXServiceURL(connectorPort,connectorPort), null);
89 expectedEx.expect(IOException.class);
90 connector.connect();
91
92 }
93
94
95 }