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.ipc.RpcClient;
30 import org.apache.hadoop.hbase.protobuf.ProtobufUtil;
31 import org.apache.hadoop.hbase.protobuf.generated.MasterProtos;
32 import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.IsMasterRunningRequest;
33 import org.apache.hadoop.hbase.security.User;
34 import org.junit.Test;
35 import org.junit.experimental.categories.Category;
36
37 import com.google.protobuf.BlockingRpcChannel;
38 import com.google.protobuf.ServiceException;
39
40 @Category(MediumTests.class)
41 public class TestHMasterRPCException {
42
43 @Test
44 public void testRPCException() throws Exception {
45 HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
46 TEST_UTIL.startMiniZKCluster();
47 Configuration conf = TEST_UTIL.getConfiguration();
48 conf.set(HConstants.MASTER_PORT, "0");
49 HMaster hm = new HMaster(conf);
50 ServerName sm = hm.getServerName();
51 RpcClient rpcClient = new RpcClient(conf, HConstants.CLUSTER_ID_DEFAULT);
52 try {
53 int i = 0;
54
55
56 while (i < 20) {
57 try {
58 BlockingRpcChannel channel =
59 rpcClient.createBlockingRpcChannel(sm, User.getCurrent(), 0);
60 MasterProtos.MasterService.BlockingInterface stub =
61 MasterProtos.MasterService.newBlockingStub(channel);
62 stub.isMasterRunning(null, IsMasterRunningRequest.getDefaultInstance());
63 fail();
64 } catch (ServiceException ex) {
65 IOException ie = ProtobufUtil.getRemoteException(ex);
66 if (!(ie instanceof SocketTimeoutException)) {
67 if (ie.getMessage().startsWith("org.apache.hadoop.hbase.ipc." +
68 "ServerNotRunningYetException: Server is not running yet")) {
69
70 System.out.println("Expected exception: " + ie.getMessage());
71 return;
72 } else {
73 throw ex;
74 }
75 } else {
76 System.err.println("Got SocketTimeoutException. Will retry. ");
77 }
78 } catch (Throwable t) {
79 fail("Unexpected throwable: " + t);
80 }
81 Thread.sleep(100);
82 i++;
83 }
84 fail();
85 } finally {
86 rpcClient.stop();
87 }
88 }
89 }