add test parameters to SimpleHttp1Test

This commit is contained in:
Jörg Prante 2018-03-08 16:09:16 +01:00
parent 8593996f2b
commit 6c8b33913a

View file

@ -24,7 +24,6 @@ import org.junit.Test;
import java.io.IOException; import java.io.IOException;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
@ -32,8 +31,12 @@ import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException; import java.util.concurrent.TimeoutException;
import java.util.logging.ConsoleHandler;
import java.util.logging.Handler;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.LogManager;
import java.util.logging.Logger; import java.util.logging.Logger;
import java.util.logging.SimpleFormatter;
/** /**
* *
@ -42,6 +45,24 @@ public class SimpleHttp1Test {
private static final Logger logger = Logger.getLogger(SimpleHttp1Test.class.getName()); private static final Logger logger = Logger.getLogger(SimpleHttp1Test.class.getName());
static {
System.setProperty("io.netty.leakDetection.level", "advanced");
System.setProperty("io.netty.noKeySetOptimization", Boolean.toString(true));
System.setProperty("java.util.logging.SimpleFormatter.format",
"%1$tY-%1$tm-%1$td %1$tH:%1$tM:%1$tS.%1$tL %4$-7s [%3$s] %2$s %5$s %6$s%n");
LogManager.getLogManager().reset();
Logger rootLogger = LogManager.getLogManager().getLogger("");
Handler handler = new ConsoleHandler();
handler.setFormatter(new SimpleFormatter());
rootLogger.addHandler(handler);
rootLogger.setLevel(Level.ALL);
for (Handler h : rootLogger.getHandlers()) {
handler.setFormatter(new SimpleFormatter());
h.setLevel(Level.ALL);
}
}
@After @After
public void checkThreads() { public void checkThreads() {
Set<Thread> threadSet = Thread.getAllStackTraces().keySet(); Set<Thread> threadSet = Thread.getAllStackTraces().keySet();
@ -58,7 +79,8 @@ public class SimpleHttp1Test {
Client client = new Client(); Client client = new Client();
try { try {
HttpTransport transport = client.newTransport("xbib.org", 80); HttpTransport transport = client.newTransport("xbib.org", 80);
transport.onResponse(string -> logger.log(Level.INFO, "got messsage: " + string)); transport.onResponse(msg -> logger.log(Level.INFO,
"got response: " + msg.status().code() + " headers=" + msg.headers().entries()));
transport.connect(); transport.connect();
sendRequest(transport); sendRequest(transport);
transport.awaitResponse(); transport.awaitResponse();
@ -89,7 +111,7 @@ public class SimpleHttp1Test {
private AttributeKey<HttpTransport> TRANSPORT_ATTRIBUTE_KEY = AttributeKey.valueOf("transport"); private AttributeKey<HttpTransport> TRANSPORT_ATTRIBUTE_KEY = AttributeKey.valueOf("transport");
interface ResponseWriter { interface ResponseWriter {
void write(String string); void write(FullHttpResponse msg);
} }
class Client { class Client {
@ -179,7 +201,7 @@ public class SimpleHttp1Test {
void responseReceived(FullHttpResponse msg) { void responseReceived(FullHttpResponse msg) {
if (responseWriter != null) { if (responseWriter != null) {
responseWriter.write(msg.content().toString(StandardCharsets.UTF_8)); responseWriter.write(msg);
} }
} }