Repository: hbase
Updated Branches:
  refs/heads/branch-1 9d6aa4a8d -> e8059b0dc


HBASE-13295 TestInfoServers hung

Conflicts:
        hbase-server/src/test/java/org/apache/hadoop/hbase/TestInfoServers.java


Project: http://git-wip-us.apache.org/repos/asf/hbase/repo
Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/e8059b0d
Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/e8059b0d
Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/e8059b0d

Branch: refs/heads/branch-1
Commit: e8059b0dc570e4a7ec8915510e5b4405cfebef59
Parents: 9d6aa4a
Author: zhangduo <zhang...@wandoujia.com>
Authored: Fri Mar 20 09:32:16 2015 +0800
Committer: zhangduo <zhang...@wandoujia.com>
Committed: Fri Mar 27 11:57:19 2015 +0800

----------------------------------------------------------------------
 .../apache/hadoop/hbase/TestInfoServers.java    | 70 ++++++++------------
 1 file changed, 28 insertions(+), 42 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hbase/blob/e8059b0d/hbase-server/src/test/java/org/apache/hadoop/hbase/TestInfoServers.java
----------------------------------------------------------------------
diff --git 
a/hbase-server/src/test/java/org/apache/hadoop/hbase/TestInfoServers.java 
b/hbase-server/src/test/java/org/apache/hadoop/hbase/TestInfoServers.java
index bcac3de..9eeb277 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/TestInfoServers.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/TestInfoServers.java
@@ -18,15 +18,16 @@
  */
 package org.apache.hadoop.hbase;
 
+import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
 
-import java.io.BufferedInputStream;
 import java.io.IOException;
+import java.io.InputStream;
 import java.net.URL;
 
+import org.apache.commons.io.IOUtils;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.apache.hadoop.hbase.client.HTable;
 import org.apache.hadoop.hbase.testclassification.MediumTests;
 import org.apache.hadoop.hbase.util.Bytes;
 import org.junit.AfterClass;
@@ -53,6 +54,9 @@ public class TestInfoServers {
     //We need to make sure that the server can be started as read only.
     UTIL.getConfiguration().setBoolean("hbase.master.ui.readonly", true);
     UTIL.startMiniCluster();
+    if (!UTIL.getHBaseCluster().waitForActiveAndReadyMaster(30000)) {
+      throw new RuntimeException("Active master not ready");
+    }
   }
 
   @AfterClass
@@ -65,15 +69,11 @@ public class TestInfoServers {
    */
   @Test
   public void testInfoServersRedirect() throws Exception {
-    // give the cluster time to start up
-    new HTable(UTIL.getConfiguration(), TableName.META_TABLE_NAME).close();
     int port = UTIL.getHBaseCluster().getMaster().getInfoServer().getPort();
-    assertContainsContent(new URL("http://localhost:"; + port +
-        "/index.html"), "master-status");
-    port = 
UTIL.getHBaseCluster().getRegionServerThreads().get(0).getRegionServer().
-      getInfoServer().getPort();
-    assertContainsContent(new URL("http://localhost:"; + port +
-        "/index.html"), "rs-status");
+    assertContainsContent(new URL("http://localhost:"; + port + "/index.html"), 
"master-status");
+    port = 
UTIL.getHBaseCluster().getRegionServerThreads().get(0).getRegionServer()
+        .getInfoServer().getPort();
+    assertContainsContent(new URL("http://localhost:"; + port + "/index.html"), 
"rs-status");
   }
 
   /**
@@ -85,15 +85,11 @@ public class TestInfoServers {
    */
   @Test
   public void testInfoServersStatusPages() throws Exception {
-    // give the cluster time to start up
-    new HTable(UTIL.getConfiguration(), TableName.META_TABLE_NAME).close();
     int port = UTIL.getHBaseCluster().getMaster().getInfoServer().getPort();
-    assertContainsContent(new URL("http://localhost:"; + port +
-        "/master-status"), "meta");
-    port = 
UTIL.getHBaseCluster().getRegionServerThreads().get(0).getRegionServer().
-      getInfoServer().getPort();
-    assertContainsContent(new URL("http://localhost:"; + port +
-        "/rs-status"), "meta");
+    assertContainsContent(new URL("http://localhost:"; + port + 
"/master-status"), "meta");
+    port = 
UTIL.getHBaseCluster().getRegionServerThreads().get(0).getRegionServer()
+        .getInfoServer().getPort();
+    assertContainsContent(new URL("http://localhost:"; + port + "/rs-status"), 
"meta");
   }
 
   @Test
@@ -101,44 +97,34 @@ public class TestInfoServers {
     TableName tableName = TableName.valueOf("testMasterServerReadOnly");
     byte[] cf = Bytes.toBytes("d");
     UTIL.createTable(tableName, cf);
-    new HTable(UTIL.getConfiguration(), tableName).close();
+    UTIL.waitTableAvailable(tableName);
     int port = UTIL.getHBaseCluster().getMaster().getInfoServer().getPort();
+    assertDoesNotContainContent(new URL("http://localhost:"; + port + 
"/table.jsp?name=" + tableName
+        + "&action=split&key="), "Table action request accepted");
     assertDoesNotContainContent(
-      new URL("http://localhost:"; + port + "/table.jsp?name=" + tableName + 
"&action=split&key="),
-      "Table action request accepted");
-    assertDoesNotContainContent(
-      new URL("http://localhost:"; + port + "/table.jsp?name=" + tableName),
-      "Actions:");
+      new URL("http://localhost:"; + port + "/table.jsp?name=" + tableName), 
"Actions:");
   }
 
-  private void assertContainsContent(final URL u, final String expected)
-  throws IOException {
+  private void assertContainsContent(final URL u, final String expected) 
throws IOException {
     LOG.info("Testing " + u.toString() + " has " + expected);
     String content = getUrlContent(u);
-    assertTrue("expected=" + expected + ", content=" + content,
-      content.contains(expected));
+    assertTrue("expected=" + expected + ", content=" + content, 
content.contains(expected));
   }
 
-
-
-  private void assertDoesNotContainContent(final URL u, final String expected)
-      throws IOException {
-    LOG.info("Testing " + u.toString() + " has " + expected);
+  private void assertDoesNotContainContent(final URL u, final String expected) 
throws IOException {
+    LOG.info("Testing " + u.toString() + " does not have " + expected);
     String content = getUrlContent(u);
-    assertTrue("Does Not Contain =" + expected + ", content=" + content,
-        !content.contains(expected));
+    assertFalse("Does Not Contain =" + expected + ", content=" + content,
+      content.contains(expected));
   }
 
   private String getUrlContent(URL u) throws IOException {
     java.net.URLConnection c = u.openConnection();
+    c.setConnectTimeout(2000);
+    c.setReadTimeout(2000);
     c.connect();
-    StringBuilder sb = new StringBuilder();
-    BufferedInputStream bis = new BufferedInputStream(c.getInputStream());
-    byte [] bytes = new byte[1024];
-    for (int read = -1; (read = bis.read(bytes)) != -1;) {
-      sb.append(new String(bytes, 0, read));
+    try (InputStream in = c.getInputStream()) {
+      return IOUtils.toString(in);
     }
-    bis.close();
-    return sb.toString();
   }
 }

Reply via email to