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.apache.hadoop.hbase.testclassification.MediumTests;
35 import org.junit.Test;
36 import org.junit.experimental.categories.Category;
37
38 import com.google.protobuf.BlockingRpcChannel;
39 import com.google.protobuf.ServiceException;
40
41 @Category(MediumTests.class)
42 public class TestHMasterRPCException {
43
44 @Test
45 public void testRPCException() throws Exception {
46 HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
47 TEST_UTIL.startMiniZKCluster();
48 Configuration conf = TEST_UTIL.getConfiguration();
49 conf.set(HConstants.MASTER_PORT, "0");
50 HMaster hm = new HMaster(conf);
51 ServerName sm = hm.getServerName();
52 RpcClient rpcClient = new RpcClient(conf, HConstants.CLUSTER_ID_DEFAULT);
53 try {
54 int i = 0;
55
56
57 while (i < 20) {
58 try {
59 BlockingRpcChannel channel =
60 rpcClient.createBlockingRpcChannel(sm, User.getCurrent(), 0);
61 MasterProtos.MasterService.BlockingInterface stub =
62 MasterProtos.MasterService.newBlockingStub(channel);
63 stub.isMasterRunning(null, IsMasterRunningRequest.getDefaultInstance());
64 fail();
65 } catch (ServiceException ex) {
66 IOException ie = ProtobufUtil.getRemoteException(ex);
67 if (!(ie instanceof SocketTimeoutException)) {
68 if (ie.getMessage().startsWith("org.apache.hadoop.hbase.ipc." +
69 "ServerNotRunningYetException: Server is not running yet")) {
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 }