HBASE-11404 TestLogLevel should stop the server at the end
This commit is contained in:
parent
3020842d5c
commit
54a5375710
|
@ -17,22 +17,27 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.hadoop.hbase.http.log;
|
package org.apache.hadoop.hbase.http.log;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.net.*;
|
import java.net.*;
|
||||||
|
|
||||||
|
import org.apache.hadoop.hbase.SmallTests;
|
||||||
import org.apache.hadoop.hbase.http.HttpServer;
|
import org.apache.hadoop.hbase.http.HttpServer;
|
||||||
import org.apache.hadoop.hbase.http.log.LogLevel;
|
import org.apache.hadoop.hbase.http.log.LogLevel;
|
||||||
import org.apache.hadoop.net.NetUtils;
|
import org.apache.hadoop.net.NetUtils;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
|
||||||
|
|
||||||
import org.apache.commons.logging.*;
|
import org.apache.commons.logging.*;
|
||||||
import org.apache.commons.logging.impl.*;
|
import org.apache.commons.logging.impl.*;
|
||||||
import org.apache.log4j.*;
|
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;
|
static final PrintStream out = System.out;
|
||||||
|
|
||||||
|
@Test (timeout=60000)
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
public void testDynamicLogLevel() throws Exception {
|
public void testDynamicLogLevel() throws Exception {
|
||||||
String logName = TestLogLevel.class.getName();
|
String logName = TestLogLevel.class.getName();
|
||||||
Log testlog = LogFactory.getLog(logName);
|
Log testlog = LogFactory.getLog(logName);
|
||||||
|
@ -45,7 +50,9 @@ public class TestLogLevel extends TestCase {
|
||||||
log.error("log.error1");
|
log.error("log.error1");
|
||||||
assertTrue(!Level.ERROR.equals(log.getEffectiveLevel()));
|
assertTrue(!Level.ERROR.equals(log.getEffectiveLevel()));
|
||||||
|
|
||||||
HttpServer server = new HttpServer.Builder().setName("..")
|
HttpServer server = null;
|
||||||
|
try {
|
||||||
|
server = new HttpServer.Builder().setName("..")
|
||||||
.addEndpoint(new URI("http://localhost:0")).setFindPort(true)
|
.addEndpoint(new URI("http://localhost:0")).setFindPort(true)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
|
@ -57,13 +64,14 @@ public class TestLogLevel extends TestCase {
|
||||||
URL url = new URL("http://" + authority + "/logLevel?log=" + logName
|
URL url = new URL("http://" + authority + "/logLevel?log=" + logName
|
||||||
+ "&level=" + Level.ERROR);
|
+ "&level=" + Level.ERROR);
|
||||||
out.println("*** Connecting to " + url);
|
out.println("*** Connecting to " + url);
|
||||||
URLConnection connection = url.openConnection();
|
HttpURLConnection connection = (HttpURLConnection)url.openConnection();
|
||||||
connection.connect();
|
connection.connect();
|
||||||
|
|
||||||
BufferedReader in = new BufferedReader(new InputStreamReader(
|
BufferedReader in = new BufferedReader(new InputStreamReader(
|
||||||
connection.getInputStream()));
|
connection.getInputStream()));
|
||||||
for(String line; (line = in.readLine()) != null; out.println(line));
|
for(String line; (line = in.readLine()) != null; out.println(line));
|
||||||
in.close();
|
in.close();
|
||||||
|
connection.disconnect();
|
||||||
|
|
||||||
log.debug("log.debug2");
|
log.debug("log.debug2");
|
||||||
log.info("log.info2");
|
log.info("log.info2");
|
||||||
|
@ -77,6 +85,11 @@ public class TestLogLevel extends TestCase {
|
||||||
log.info("log.info3");
|
log.info("log.info3");
|
||||||
log.error("log.error3");
|
log.error("log.error3");
|
||||||
assertTrue(Level.DEBUG.equals(log.getEffectiveLevel()));
|
assertTrue(Level.DEBUG.equals(log.getEffectiveLevel()));
|
||||||
|
} finally {
|
||||||
|
if (server != null) {
|
||||||
|
server.stop();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
out.println(testlog.getClass() + " not tested.");
|
out.println(testlog.getClass() + " not tested.");
|
||||||
|
|
Loading…
Reference in New Issue