1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.hadoop.hbase.client;
20
21 import static org.junit.Assert.fail;
22
23 import org.apache.hadoop.hbase.HBaseTestingUtility;
24 import org.apache.hadoop.hbase.HConstants;
25 import org.apache.hadoop.hbase.ServerName;
26 import org.apache.hadoop.hbase.testclassification.ClientTests;
27 import org.apache.hadoop.hbase.testclassification.MediumTests;
28 import org.junit.AfterClass;
29 import org.junit.BeforeClass;
30 import org.junit.Test;
31 import org.junit.experimental.categories.Category;
32
33 import java.net.UnknownHostException;
34
35
36
37
38
39 @Category({MediumTests.class, ClientTests.class})
40 public class TestConnectionImplementation {
41 private static HBaseTestingUtility testUtil;
42 private static ConnectionManager.HConnectionImplementation conn;
43
44 @BeforeClass
45 public static void setupBeforeClass() throws Exception {
46 testUtil = HBaseTestingUtility.createLocalHTU();
47 testUtil.startMiniCluster();
48 conn = (ConnectionManager.HConnectionImplementation) testUtil.getConnection();
49 }
50
51 @AfterClass
52 public static void teardownAfterClass() throws Exception {
53 conn.close();
54 testUtil.shutdownMiniCluster();
55 }
56
57 @Test(expected = UnknownHostException.class)
58 public void testGetAdminBadHostname() throws Exception {
59
60 ServerName master = testUtil.getHBaseCluster().getMaster().getServerName();
61 try {
62 conn.getAdmin(master);
63 } catch (UnknownHostException uhe) {
64 fail("Obtaining admin to the cluster master should have succeeded");
65 }
66
67
68
69 ServerName badHost =
70 ServerName.valueOf("unknownhost.example.com:" + HConstants.DEFAULT_MASTER_PORT,
71 System.currentTimeMillis());
72 conn.getAdmin(badHost);
73 fail("Obtaining admin to unresolvable hostname should have failed");
74 }
75
76 @Test(expected = UnknownHostException.class)
77 public void testGetClientBadHostname() throws Exception {
78
79 ServerName rs = testUtil.getHBaseCluster().getRegionServer(0).getServerName();
80 try {
81 conn.getClient(rs);
82 } catch (UnknownHostException uhe) {
83 fail("Obtaining client to the cluster regionserver should have succeeded");
84 }
85
86
87
88 ServerName badHost =
89 ServerName.valueOf("unknownhost.example.com:" + HConstants.DEFAULT_REGIONSERVER_PORT,
90 System.currentTimeMillis());
91 conn.getAdmin(badHost);
92 fail("Obtaining client to unresolvable hostname should have failed");
93 }
94 }