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;
21
22 import java.io.BufferedInputStream;
23 import java.io.IOException;
24 import java.net.URL;
25
26 import org.apache.commons.logging.Log;
27 import org.apache.commons.logging.LogFactory;
28 import org.apache.hadoop.hbase.client.HTable;
29
30
31
32
33
34 public class TestInfoServers extends HBaseClusterTestCase {
35 static final Log LOG = LogFactory.getLog(TestInfoServers.class);
36
37 @Override
38 protected void preHBaseClusterSetup() {
39
40
41 conf.setInt("hbase.master.info.port", 0);
42 conf.setInt("hbase.regionserver.info.port", 0);
43 }
44
45
46
47
48 public void testInfoServersAreUp() throws Exception {
49
50 new HTable(conf, ".META.");
51 int port = cluster.getMaster().getInfoServer().getPort();
52 assertHasExpectedContent(new URL("http://localhost:" + port +
53 "/index.html"), "master");
54 port = cluster.getRegionServerThreads().get(0).getRegionServer().
55 getInfoServer().getPort();
56 assertHasExpectedContent(new URL("http://localhost:" + port +
57 "/index.html"), "regionserver");
58 }
59
60 private void assertHasExpectedContent(final URL u, final String expected)
61 throws IOException {
62 LOG.info("Testing " + u.toString() + " has " + expected);
63 java.net.URLConnection c = u.openConnection();
64 c.connect();
65 assertTrue(c.getContentLength() > 0);
66 StringBuilder sb = new StringBuilder(c.getContentLength());
67 BufferedInputStream bis = new BufferedInputStream(c.getInputStream());
68 byte [] bytes = new byte[1024];
69 for (int read = -1; (read = bis.read(bytes)) != -1;) {
70 sb.append(new String(bytes, 0, read));
71 }
72 bis.close();
73 String content = sb.toString();
74 assertTrue(content.contains(expected));
75 }
76 }