1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.apache.hadoop.hbase.master;
22
23 import static org.junit.Assert.assertNotNull;
24 import static org.junit.Assert.assertTrue;
25 import static org.junit.Assert.fail;
26
27 import java.net.InetSocketAddress;
28
29 import org.apache.hadoop.conf.Configuration;
30 import org.apache.hadoop.hbase.*;
31 import org.apache.hadoop.hbase.ipc.HBaseRPC;
32 import org.apache.hadoop.hbase.ipc.HMasterInterface;
33 import org.apache.hadoop.hbase.ipc.RpcEngine;
34 import org.apache.hadoop.ipc.RemoteException;
35 import org.junit.Test;
36 import org.junit.experimental.categories.Category;
37
38 @Category(MediumTests.class)
39 public class TestHMasterRPCException {
40
41 @Test
42 public void testRPCException() throws Exception {
43 HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
44 TEST_UTIL.startMiniZKCluster();
45 Configuration conf = TEST_UTIL.getConfiguration();
46 conf.set(HConstants.MASTER_PORT, "0");
47
48 HMaster hm = new HMaster(conf);
49
50 ServerName sm = hm.getServerName();
51 InetSocketAddress isa = new InetSocketAddress(sm.getHostname(), sm.getPort());
52 RpcEngine rpcEngine = null;
53 try {
54 rpcEngine = HBaseRPC.getProtocolEngine(conf);
55 HMasterInterface inf = rpcEngine.getProxy(
56 HMasterInterface.class, HMasterInterface.VERSION, isa, conf, 100 * 10);
57 inf.isMasterRunning();
58 fail();
59 } catch (RemoteException ex) {
60 assertTrue(ex.getMessage().startsWith(
61 "org.apache.hadoop.hbase.ipc.ServerNotRunningYetException: Server is not running yet"));
62 } catch (Throwable t) {
63 fail("Unexpected throwable: " + t);
64 } finally {
65 if (rpcEngine != null) {
66 rpcEngine.close();
67 }
68 }
69 }
70
71 @org.junit.Rule
72 public org.apache.hadoop.hbase.ResourceCheckerJUnitRule cu =
73 new org.apache.hadoop.hbase.ResourceCheckerJUnitRule();
74 }
75