hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jxi...@apache.org
Subject git commit: HBASE-11404 TestLogLevel should stop the server at the end
Date Mon, 23 Jun 2014 18:44:20 GMT
Repository: hbase
Updated Branches:
  refs/heads/master 3020842d5 -> 54a537571


HBASE-11404 TestLogLevel should stop the server at the end


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

Branch: refs/heads/master
Commit: 54a5375710960257cce67783eadcc8b5740b99a4
Parents: 3020842
Author: Jimmy Xiang <jxiang@cloudera.com>
Authored: Mon Jun 23 09:25:22 2014 -0700
Committer: Jimmy Xiang <jxiang@cloudera.com>
Committed: Mon Jun 23 09:51:04 2014 -0700

----------------------------------------------------------------------
 .../hadoop/hbase/http/log/TestLogLevel.java     | 77 ++++++++++++--------
 1 file changed, 45 insertions(+), 32 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hbase/blob/54a53757/hbase-server/src/test/java/org/apache/hadoop/hbase/http/log/TestLogLevel.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/http/log/TestLogLevel.java
b/hbase-server/src/test/java/org/apache/hadoop/hbase/http/log/TestLogLevel.java
index 3ca23d0..a60437c 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/http/log/TestLogLevel.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/http/log/TestLogLevel.java
@@ -17,22 +17,27 @@
 */
 package org.apache.hadoop.hbase.http.log;
 
+import static org.junit.Assert.assertTrue;
+
 import java.io.*;
 import java.net.*;
 
+import org.apache.hadoop.hbase.SmallTests;
 import org.apache.hadoop.hbase.http.HttpServer;
 import org.apache.hadoop.hbase.http.log.LogLevel;
 import org.apache.hadoop.net.NetUtils;
-
-import junit.framework.TestCase;
-
 import org.apache.commons.logging.*;
 import org.apache.commons.logging.impl.*;
 import org.apache.log4j.*;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
 
-public class TestLogLevel extends TestCase {
+@Category(SmallTests.class)
+public class TestLogLevel {
   static final PrintStream out = System.out;
 
+  @Test (timeout=60000)
+  @SuppressWarnings("deprecation")
   public void testDynamicLogLevel() throws Exception {
     String logName = TestLogLevel.class.getName();
     Log testlog = LogFactory.getLog(logName);
@@ -45,38 +50,46 @@ public class TestLogLevel extends TestCase {
       log.error("log.error1");
       assertTrue(!Level.ERROR.equals(log.getEffectiveLevel()));
 
-      HttpServer server = new HttpServer.Builder().setName("..")
-          .addEndpoint(new URI("http://localhost:0")).setFindPort(true)
-          .build();
-      
-      server.start();
-      String authority = NetUtils.getHostPortString(server
-          .getConnectorAddress(0));
+      HttpServer server = null;
+      try {
+        server = new HttpServer.Builder().setName("..")
+            .addEndpoint(new URI("http://localhost:0")).setFindPort(true)
+            .build();
+
+        server.start();
+        String authority = NetUtils.getHostPortString(server
+            .getConnectorAddress(0));
 
-      //servlet
-      URL url = new URL("http://" + authority + "/logLevel?log=" + logName
-          + "&level=" + Level.ERROR);
-      out.println("*** Connecting to " + url);
-      URLConnection connection = url.openConnection();
-      connection.connect();
+        //servlet
+        URL url = new URL("http://" + authority + "/logLevel?log=" + logName
+            + "&level=" + Level.ERROR);
+        out.println("*** Connecting to " + url);
+        HttpURLConnection connection = (HttpURLConnection)url.openConnection();
+        connection.connect();
 
-      BufferedReader in = new BufferedReader(new InputStreamReader(
-          connection.getInputStream()));
-      for(String line; (line = in.readLine()) != null; out.println(line));
-      in.close();
+        BufferedReader in = new BufferedReader(new InputStreamReader(
+            connection.getInputStream()));
+        for(String line; (line = in.readLine()) != null; out.println(line));
+        in.close();
+        connection.disconnect();
 
-      log.debug("log.debug2");
-      log.info("log.info2");
-      log.error("log.error2");
-      assertTrue(Level.ERROR.equals(log.getEffectiveLevel()));
+        log.debug("log.debug2");
+        log.info("log.info2");
+        log.error("log.error2");
+        assertTrue(Level.ERROR.equals(log.getEffectiveLevel()));
 
-      //command line
-      String[] args = {"-setlevel", authority, logName, Level.DEBUG.toString()};
-      LogLevel.main(args);
-      log.debug("log.debug3");
-      log.info("log.info3");
-      log.error("log.error3");
-      assertTrue(Level.DEBUG.equals(log.getEffectiveLevel()));
+        //command line
+        String[] args = {"-setlevel", authority, logName, Level.DEBUG.toString()};
+        LogLevel.main(args);
+        log.debug("log.debug3");
+        log.info("log.info3");
+        log.error("log.error3");
+        assertTrue(Level.DEBUG.equals(log.getEffectiveLevel()));
+      } finally {
+        if (server != null) {
+          server.stop();
+        }
+      }
     }
     else {
       out.println(testlog.getClass() + " not tested.");


Mime
View raw message