HBASE-24033 Add ut for loading the corrupt recovered hfiles (#1322)
[hbase.git] / hbase-server / src / test / java / org / apache / hadoop / hbase / client / TestCIBadHostname.java
blob6fdd4624ca79bd19b84556e71d14f47cca8efae6
1 /**
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 package org.apache.hadoop.hbase.client;
20 import static org.junit.Assert.fail;
22 import java.net.UnknownHostException;
23 import org.apache.hadoop.hbase.HBaseClassTestRule;
24 import org.apache.hadoop.hbase.HBaseTestingUtility;
25 import org.apache.hadoop.hbase.HConstants;
26 import org.apache.hadoop.hbase.ServerName;
27 import org.apache.hadoop.hbase.testclassification.ClientTests;
28 import org.apache.hadoop.hbase.testclassification.MediumTests;
29 import org.junit.AfterClass;
30 import org.junit.BeforeClass;
31 import org.junit.ClassRule;
32 import org.junit.Test;
33 import org.junit.experimental.categories.Category;
35 /**
36 * Tests that we fail fast when hostname resolution is not working and do not cache unresolved
37 * InetSocketAddresses.
39 @Category({ MediumTests.class, ClientTests.class })
40 public class TestCIBadHostname {
42 @ClassRule
43 public static final HBaseClassTestRule CLASS_RULE =
44 HBaseClassTestRule.forClass(TestCIBadHostname.class);
46 private static HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
47 private static AsyncConnectionImpl CONN;
49 @BeforeClass
50 public static void setupBeforeClass() throws Exception {
51 TEST_UTIL.startMiniCluster();
52 CONN = (AsyncConnectionImpl) ConnectionFactory
53 .createAsyncConnection(TEST_UTIL.getConfiguration()).get();
56 @AfterClass
57 public static void teardownAfterClass() throws Exception {
58 CONN.close();
59 TEST_UTIL.shutdownMiniCluster();
62 @Test(expected = UnknownHostException.class)
63 public void testGetAdminBadHostname() throws Exception {
64 // verify that we can get an instance with the cluster hostname
65 ServerName master = TEST_UTIL.getHBaseCluster().getMaster().getServerName();
66 try {
67 CONN.getAdminStub(master);
68 } catch (UnknownHostException uhe) {
69 fail("Obtaining admin to the cluster master should have succeeded");
72 // test that we fail to get a client to an unresolvable hostname, which
73 // means it won't be cached
74 ServerName badHost = ServerName.valueOf("unknownhost.invalid:" + HConstants.DEFAULT_MASTER_PORT,
75 System.currentTimeMillis());
76 CONN.getAdminStub(badHost);
77 fail("Obtaining admin to unresolvable hostname should have failed");
80 @Test(expected = UnknownHostException.class)
81 public void testGetClientBadHostname() throws Exception {
82 // verify that we can get an instance with the cluster hostname
83 ServerName rs = TEST_UTIL.getHBaseCluster().getRegionServer(0).getServerName();
84 try {
85 CONN.getRegionServerStub(rs);
86 } catch (UnknownHostException uhe) {
87 fail("Obtaining client to the cluster regionserver should have succeeded");
90 // test that we fail to get a client to an unresolvable hostname, which
91 // means it won't be cached
92 ServerName badHost = ServerName.valueOf(
93 "unknownhost.invalid:" + HConstants.DEFAULT_REGIONSERVER_PORT, System.currentTimeMillis());
94 CONN.getRegionServerStub(badHost);
95 fail("Obtaining client to unresolvable hostname should have failed");