1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.hadoop.hbase.master;
21
22 import static org.junit.Assert.fail;
23
24 import java.io.IOException;
25 import java.net.SocketTimeoutException;
26
27 import org.apache.hadoop.conf.Configuration;
28 import org.apache.hadoop.hbase.*;
29 import org.apache.hadoop.hbase.CoordinatedStateManager;
30 import org.apache.hadoop.hbase.CoordinatedStateManagerFactory;
31 import org.apache.hadoop.hbase.ipc.RpcClient;
32 import org.apache.hadoop.hbase.ipc.RpcClientFactory;
33 import org.apache.hadoop.hbase.protobuf.ProtobufUtil;
34 import org.apache.hadoop.hbase.protobuf.generated.MasterProtos;
35 import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.IsMasterRunningRequest;
36 import org.apache.hadoop.hbase.security.User;
37 import org.apache.hadoop.hbase.testclassification.MediumTests;
38 import org.junit.Test;
39 import org.junit.experimental.categories.Category;
40
41 import com.google.protobuf.BlockingRpcChannel;
42 import com.google.protobuf.ServiceException;
43
44 @Category(MediumTests.class)
45 public class TestHMasterRPCException {
46
47 @Test
48 public void testRPCException() throws Exception {
49 HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
50 TEST_UTIL.startMiniZKCluster();
51 Configuration conf = TEST_UTIL.getConfiguration();
52 conf.set(HConstants.MASTER_PORT, "0");
53 CoordinatedStateManager cp = CoordinatedStateManagerFactory.getCoordinatedStateManager(conf);
54 HMaster hm = new HMaster(conf, cp);
55 ServerName sm = hm.getServerName();
56 RpcClient rpcClient = RpcClientFactory.createClient(conf, HConstants.CLUSTER_ID_DEFAULT);
57 try {
58 int i = 0;
59
60
61 while (i < 20) {
62 try {
63 BlockingRpcChannel channel =
64 rpcClient.createBlockingRpcChannel(sm, User.getCurrent(), 0);
65 MasterProtos.MasterService.BlockingInterface stub =
66 MasterProtos.MasterService.newBlockingStub(channel);
67 stub.isMasterRunning(null, IsMasterRunningRequest.getDefaultInstance());
68 fail();
69 } catch (ServiceException ex) {
70 IOException ie = ProtobufUtil.getRemoteException(ex);
71 if (!(ie instanceof SocketTimeoutException)) {
72 if (ie.getMessage().startsWith("org.apache.hadoop.hbase.ipc." +
73 "ServerNotRunningYetException: Server is not running yet")) {
74
75 System.out.println("Expected exception: " + ie.getMessage());
76 return;
77 } else {
78 throw ex;
79 }
80 } else {
81 System.err.println("Got SocketTimeoutException. Will retry. ");
82 }
83 } catch (Throwable t) {
84 fail("Unexpected throwable: " + t);
85 }
86 Thread.sleep(100);
87 i++;
88 }
89 fail();
90 } finally {
91 rpcClient.close();
92 }
93 }
94 }