From 0ddbdda2800768bc637ce727cbf3ee16b9b99f84 Mon Sep 17 00:00:00 2001 From: Simone Bordet Date: Wed, 8 Aug 2012 15:02:11 +0200 Subject: [PATCH] Jetty9 - Test code cleanup. --- .../jetty/server/ConnectorTimeoutTest.java | 87 ++++++++++--------- .../test/resources/jetty-logging.properties | 2 + 2 files changed, 48 insertions(+), 41 deletions(-) create mode 100644 jetty-server/src/test/resources/jetty-logging.properties diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/ConnectorTimeoutTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/ConnectorTimeoutTest.java index f082e9162c9..18a7ee38a5a 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/ConnectorTimeoutTest.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/ConnectorTimeoutTest.java @@ -13,10 +13,6 @@ package org.eclipse.jetty.server; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.matchers.JUnitMatchers.containsString; - import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -24,7 +20,6 @@ import java.net.Socket; import java.net.SocketException; import java.util.concurrent.Exchanger; import java.util.concurrent.TimeUnit; - import javax.net.ssl.SSLException; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; @@ -37,6 +32,10 @@ import org.eclipse.jetty.util.IO; import org.junit.Assert; import org.junit.Test; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.matchers.JUnitMatchers.containsString; + public abstract class ConnectorTimeoutTest extends HttpServerTestFixture { protected static final int MAX_IDLE_TIME=500; @@ -114,8 +113,8 @@ public abstract class ConnectorTimeoutTest extends HttpServerTestFixture @Test public void testMaxIdleWithRequest10NoClientClose() throws Exception - { - final Exchanger endpoint = new Exchanger(); + { + final Exchanger exchanger = new Exchanger<>(); configureServer(new HelloWorldHandler() { @Override @@ -124,11 +123,13 @@ public abstract class ConnectorTimeoutTest extends HttpServerTestFixture { try { - endpoint.exchange(baseRequest.getHttpChannel().getConnection().getEndPoint()); + exchanger.exchange(baseRequest.getHttpChannel().getConnection().getEndPoint()); } - catch(Exception e) - {} - super.handle(target,baseRequest,request,response); + catch (Exception e) + { + e.printStackTrace(); + } + super.handle(target, baseRequest, request, response); } }); @@ -148,10 +149,10 @@ public abstract class ConnectorTimeoutTest extends HttpServerTestFixture os.flush(); // Get the server side endpoint - EndPoint endp = endpoint.exchange(null,10,TimeUnit.SECONDS); - if (endp instanceof SslConnection.DecryptedEndPoint) - endp=((SslConnection.DecryptedEndPoint)endp).getConnection().getEndPoint(); - + EndPoint endPoint = exchanger.exchange(null,10,TimeUnit.SECONDS); + if (endPoint instanceof SslConnection.DecryptedEndPoint) + endPoint=endPoint.getConnection().getEndPoint(); + // read the response String result=IO.toString(is); Assert.assertThat("OK",result,containsString("200 OK")); @@ -160,7 +161,7 @@ public abstract class ConnectorTimeoutTest extends HttpServerTestFixture assertEquals(-1, is.read()); // wait for idle timeout - TimeUnit.MILLISECONDS.sleep(3*MAX_IDLE_TIME); + TimeUnit.MILLISECONDS.sleep(3 * MAX_IDLE_TIME); // further writes will get broken pipe or similar @@ -182,13 +183,13 @@ public abstract class ConnectorTimeoutTest extends HttpServerTestFixture // expected } // check the server side is closed - Assert.assertFalse(endp.isOpen()); + Assert.assertFalse(endPoint.isOpen()); } @Test public void testMaxIdleWithRequest10ClientIgnoresClose() throws Exception - { - final Exchanger endpoint = new Exchanger(); + { + final Exchanger exchanger = new Exchanger<>(); configureServer(new HelloWorldHandler() { @Override @@ -197,11 +198,13 @@ public abstract class ConnectorTimeoutTest extends HttpServerTestFixture { try { - endpoint.exchange(baseRequest.getHttpChannel().getConnection().getEndPoint()); + exchanger.exchange(baseRequest.getHttpChannel().getConnection().getEndPoint()); } - catch(Exception e) - {} - super.handle(target,baseRequest,request,response); + catch (Exception e) + { + e.printStackTrace(); + } + super.handle(target, baseRequest, request, response); } }); @@ -221,10 +224,10 @@ public abstract class ConnectorTimeoutTest extends HttpServerTestFixture os.flush(); // Get the server side endpoint - EndPoint endp = endpoint.exchange(null,10,TimeUnit.SECONDS); - if (endp instanceof SslConnection.DecryptedEndPoint) - endp=((SslConnection.DecryptedEndPoint)endp).getConnection().getEndPoint(); - + EndPoint endPoint = exchanger.exchange(null,10,TimeUnit.SECONDS); + if (endPoint instanceof SslConnection.DecryptedEndPoint) + endPoint=endPoint.getConnection().getEndPoint(); + // read the response String result=IO.toString(is); Assert.assertThat("OK",result,containsString("200 OK")); @@ -251,13 +254,13 @@ public abstract class ConnectorTimeoutTest extends HttpServerTestFixture // expected } // check the server side is closed - Assert.assertFalse(endp.isOpen()); + Assert.assertFalse(endPoint.isOpen()); } @Test public void testMaxIdleWithRequest11NoClientClose() throws Exception { - final Exchanger endpoint = new Exchanger(); + final Exchanger exchanger = new Exchanger<>(); configureServer(new EchoHandler() { @Override @@ -266,11 +269,13 @@ public abstract class ConnectorTimeoutTest extends HttpServerTestFixture { try { - endpoint.exchange(baseRequest.getHttpChannel().getConnection().getEndPoint()); + exchanger.exchange(baseRequest.getHttpChannel().getConnection().getEndPoint()); } - catch(Exception e) - {} - super.handle(target,baseRequest,request,response); + catch (Exception e) + { + e.printStackTrace(); + } + super.handle(target, baseRequest, request, response); } }); @@ -285,17 +290,17 @@ public abstract class ConnectorTimeoutTest extends HttpServerTestFixture String content="Wibble"; byte[] contentB=content.getBytes("utf-8"); os.write(( - "POST /echo HTTP/1.1\r\n"+ - "host: "+HOST+":"+_connector.getLocalPort()+"\r\n"+ - "content-type: text/plain; charset=utf-8\r\n"+ - "content-length: "+contentB.length+"\r\n"+ - "connection: close\r\n"+ - "\r\n").getBytes("utf-8")); + "POST /echo HTTP/1.1\r\n" + + "host: " + HOST + ":" + _connector.getLocalPort() + "\r\n" + + "content-type: text/plain; charset=utf-8\r\n" + + "content-length: " + contentB.length + "\r\n" + + "connection: close\r\n" + + "\r\n").getBytes("utf-8")); os.write(contentB); os.flush(); // Get the server side endpoint - EndPoint endp = endpoint.exchange(null,10,TimeUnit.SECONDS); + EndPoint endPoint = exchanger.exchange(null,10,TimeUnit.SECONDS); // read the response IO.toString(is); @@ -326,7 +331,7 @@ public abstract class ConnectorTimeoutTest extends HttpServerTestFixture } // check the server side is closed - Assert.assertFalse(endp.isOpen()); + Assert.assertFalse(endPoint.isOpen()); } diff --git a/jetty-server/src/test/resources/jetty-logging.properties b/jetty-server/src/test/resources/jetty-logging.properties new file mode 100644 index 00000000000..9e08d435daa --- /dev/null +++ b/jetty-server/src/test/resources/jetty-logging.properties @@ -0,0 +1,2 @@ +org.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.StdErrLog +#org.eclipse.jetty.LEVEL=WARN