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