1   /*
2    * Copyright 2010 The Apache Software Foundation
3    *
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *     http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing, software
15   * distributed under the License is distributed on an "AS IS" BASIS,
16   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17   * See the License for the specific language governing permissions and
18   * limitations under the License.
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