From 93f3ec1731c8279584566ca02e5bdc2830c38dd6 Mon Sep 17 00:00:00 2001 From: Greg Wilkins Date: Mon, 18 Jul 2011 16:45:08 +1000 Subject: [PATCH] test harness cleanups after performance branch merge --- .../rewrite/handler/AbstractRuleTestCase.java | 3 +- .../eclipse/jetty/server/HttpConnection.java | 7 +-- .../eclipse/jetty/server/ResponseTest.java | 49 ++++++++++++++----- 3 files changed, 41 insertions(+), 18 deletions(-) diff --git a/jetty-rewrite/src/test/java/org/eclipse/jetty/rewrite/handler/AbstractRuleTestCase.java b/jetty-rewrite/src/test/java/org/eclipse/jetty/rewrite/handler/AbstractRuleTestCase.java index 7907fb04abf..955391dbe52 100644 --- a/jetty-rewrite/src/test/java/org/eclipse/jetty/rewrite/handler/AbstractRuleTestCase.java +++ b/jetty-rewrite/src/test/java/org/eclipse/jetty/rewrite/handler/AbstractRuleTestCase.java @@ -13,6 +13,7 @@ package org.eclipse.jetty.rewrite.handler; import org.eclipse.jetty.io.bio.StringEndPoint; +import org.eclipse.jetty.server.BlockingHttpConnection; import org.eclipse.jetty.server.Connector; import org.eclipse.jetty.server.HttpConnection; import org.eclipse.jetty.server.LocalConnector; @@ -61,7 +62,7 @@ public abstract class AbstractRuleTestCase protected void reset() { - _connection = new HttpConnection(_connector, _endpoint, _server); + _connection = new BlockingHttpConnection(_connector, _endpoint, _server); _request = new Request(_connection); _response = new Response(_connection); _request.setRequestURI("/test/"); diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/HttpConnection.java b/jetty-server/src/main/java/org/eclipse/jetty/server/HttpConnection.java index 34654605298..aa0e5c29870 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/HttpConnection.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/HttpConnection.java @@ -88,7 +88,7 @@ import org.eclipse.jetty.util.thread.Timeout; *

* */ -public class HttpConnection extends AbstractConnection +public abstract class HttpConnection extends AbstractConnection { private static final int UNKNOWN = -2; private static final ThreadLocal __currentConnection = new ThreadLocal(); @@ -528,10 +528,7 @@ public class HttpConnection extends AbstractConnection } /* ------------------------------------------------------------ */ - public Connection handle() throws IOException - { - return this; - } + public abstract Connection handle() throws IOException; /* ------------------------------------------------------------ */ public void commitResponse(boolean last) throws IOException diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/ResponseTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/ResponseTest.java index 9b80a044125..d9f57f06426 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/ResponseTest.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/ResponseTest.java @@ -33,10 +33,14 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSessionContext; +import org.eclipse.jetty.http.Generator; import org.eclipse.jetty.http.HttpHeaders; import org.eclipse.jetty.http.HttpURI; +import org.eclipse.jetty.http.Parser; import org.eclipse.jetty.io.ByteArrayBuffer; import org.eclipse.jetty.io.ByteArrayEndPoint; +import org.eclipse.jetty.io.Connection; +import org.eclipse.jetty.io.EndPoint; import org.eclipse.jetty.server.bio.SocketConnector; import org.eclipse.jetty.server.handler.AbstractHandler; import org.eclipse.jetty.server.handler.ContextHandler; @@ -55,7 +59,7 @@ public class ResponseTest { private Server server; private LocalConnector connector; - + @Before public void init() throws Exception { @@ -76,7 +80,7 @@ public class ResponseTest @Test public void testContentType() throws Exception { - HttpConnection connection = new HttpConnection(connector,new ByteArrayEndPoint(), connector.getServer()); + HttpConnection connection = new TestHttpConnection(connector,new ByteArrayEndPoint(), connector.getServer()); Response response = connection.getResponse(); assertEquals(null,response.getContentType()); @@ -121,7 +125,7 @@ public class ResponseTest public void testLocale() throws Exception { - HttpConnection connection = new HttpConnection(connector,new ByteArrayEndPoint(), connector.getServer()); + HttpConnection connection = new TestHttpConnection(connector,new ByteArrayEndPoint(), connector.getServer()); Request request = connection.getRequest(); Response response = connection.getResponse(); ContextHandler context = new ContextHandler(); @@ -145,7 +149,7 @@ public class ResponseTest @Test public void testContentTypeCharacterEncoding() throws Exception { - HttpConnection connection = new HttpConnection(connector,new ByteArrayEndPoint(), connector.getServer()); + HttpConnection connection = new TestHttpConnection(connector,new ByteArrayEndPoint(), connector.getServer()); Request request = connection.getRequest(); Response response = connection.getResponse(); @@ -178,7 +182,7 @@ public class ResponseTest @Test public void testCharacterEncodingContentType() throws Exception { - Response response = new Response(new HttpConnection(connector,new ByteArrayEndPoint(), connector.getServer())); + Response response = new Response(new TestHttpConnection(connector,new ByteArrayEndPoint(), connector.getServer())); response.setCharacterEncoding("utf-8"); response.setContentType("foo/bar"); @@ -207,7 +211,7 @@ public class ResponseTest @Test public void testContentTypeWithCharacterEncoding() throws Exception { - Response response = new Response(new HttpConnection(connector,new ByteArrayEndPoint(), connector.getServer())); + Response response = new Response(new TestHttpConnection(connector,new ByteArrayEndPoint(), connector.getServer())); response.setCharacterEncoding("utf16"); response.setContentType("foo/bar; charset=utf-8"); @@ -236,7 +240,7 @@ public class ResponseTest @Test public void testContentTypeWithOther() throws Exception { - Response response = new Response(new HttpConnection(connector,new ByteArrayEndPoint(), connector.getServer())); + Response response = new Response(new TestHttpConnection(connector,new ByteArrayEndPoint(), connector.getServer())); response.setContentType("foo/bar; other=xyz"); assertEquals("foo/bar; other=xyz",response.getContentType()); @@ -259,7 +263,7 @@ public class ResponseTest @Test public void testContentTypeWithCharacterEncodingAndOther() throws Exception { - Response response = new Response(new HttpConnection(connector,new ByteArrayEndPoint(), connector.getServer())); + Response response = new Response(new TestHttpConnection(connector,new ByteArrayEndPoint(), connector.getServer())); response.setCharacterEncoding("utf16"); response.setContentType("foo/bar; charset=utf-8 other=xyz"); @@ -319,7 +323,7 @@ public class ResponseTest public void testEncodeRedirect() throws Exception { - HttpConnection connection=new HttpConnection(connector,new ByteArrayEndPoint(), connector.getServer()); + HttpConnection connection=new TestHttpConnection(connector,new ByteArrayEndPoint(), connector.getServer()); Response response = new Response(connection); Request request = connection.getRequest(); request.setServerName("myhost"); @@ -369,7 +373,7 @@ public class ResponseTest throws Exception { ByteArrayEndPoint out=new ByteArrayEndPoint(new byte[]{},4096); - HttpConnection connection=new HttpConnection(connector,out, connector.getServer()); + HttpConnection connection=new TestHttpConnection(connector,out, connector.getServer()); Response response = new Response(connection); Request request = connection.getRequest(); request.setServerName("myhost"); @@ -398,7 +402,7 @@ public class ResponseTest @Test public void testSetBufferSize () throws Exception { - Response response = new Response(new HttpConnection(connector,new ByteArrayEndPoint(), connector.getServer())); + Response response = new Response(new TestHttpConnection(connector,new ByteArrayEndPoint(), connector.getServer())); response.setBufferSize(20*1024); response.getWriter().print("hello"); try @@ -464,7 +468,7 @@ public class ResponseTest ByteArrayEndPoint endPoint = new ByteArrayEndPoint(); endPoint.setOut(new ByteArrayBuffer(1024)); endPoint.setGrowOutput(true); - HttpConnection connection=new HttpConnection(connector, endPoint, connector.getServer()); + HttpConnection connection=new TestHttpConnection(connector, endPoint, connector.getServer()); connection.getGenerator().reset(false); HttpConnection.setCurrentConnection(connection); Response response = connection.getResponse(); @@ -565,4 +569,25 @@ public class ResponseTest return null; } } + + static class TestHttpConnection extends HttpConnection + { + + public TestHttpConnection(Connector connector, EndPoint endpoint, Server server) + { + super(connector,endpoint,server); + } + + public TestHttpConnection(Connector connector, EndPoint endpoint, Server server, Parser parser, Generator generator, Request request) + { + super(connector,endpoint,server,parser,generator,request); + } + + @Override + public Connection handle() throws IOException + { + return this; + } + + } }