test harness cleanups after performance branch merge

This commit is contained in:
Greg Wilkins 2011-07-18 16:45:08 +10:00
parent d091003cfc
commit 93f3ec1731
3 changed files with 41 additions and 18 deletions

View File

@ -13,6 +13,7 @@
package org.eclipse.jetty.rewrite.handler; package org.eclipse.jetty.rewrite.handler;
import org.eclipse.jetty.io.bio.StringEndPoint; import org.eclipse.jetty.io.bio.StringEndPoint;
import org.eclipse.jetty.server.BlockingHttpConnection;
import org.eclipse.jetty.server.Connector; import org.eclipse.jetty.server.Connector;
import org.eclipse.jetty.server.HttpConnection; import org.eclipse.jetty.server.HttpConnection;
import org.eclipse.jetty.server.LocalConnector; import org.eclipse.jetty.server.LocalConnector;
@ -61,7 +62,7 @@ public abstract class AbstractRuleTestCase
protected void reset() protected void reset()
{ {
_connection = new HttpConnection(_connector, _endpoint, _server); _connection = new BlockingHttpConnection(_connector, _endpoint, _server);
_request = new Request(_connection); _request = new Request(_connection);
_response = new Response(_connection); _response = new Response(_connection);
_request.setRequestURI("/test/"); _request.setRequestURI("/test/");

View File

@ -88,7 +88,7 @@ import org.eclipse.jetty.util.thread.Timeout;
* </p> * </p>
* *
*/ */
public class HttpConnection extends AbstractConnection public abstract class HttpConnection extends AbstractConnection
{ {
private static final int UNKNOWN = -2; private static final int UNKNOWN = -2;
private static final ThreadLocal<HttpConnection> __currentConnection = new ThreadLocal<HttpConnection>(); private static final ThreadLocal<HttpConnection> __currentConnection = new ThreadLocal<HttpConnection>();
@ -528,10 +528,7 @@ public class HttpConnection extends AbstractConnection
} }
/* ------------------------------------------------------------ */ /* ------------------------------------------------------------ */
public Connection handle() throws IOException public abstract Connection handle() throws IOException;
{
return this;
}
/* ------------------------------------------------------------ */ /* ------------------------------------------------------------ */
public void commitResponse(boolean last) throws IOException public void commitResponse(boolean last) throws IOException

View File

@ -33,10 +33,14 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSessionContext; import javax.servlet.http.HttpSessionContext;
import org.eclipse.jetty.http.Generator;
import org.eclipse.jetty.http.HttpHeaders; import org.eclipse.jetty.http.HttpHeaders;
import org.eclipse.jetty.http.HttpURI; import org.eclipse.jetty.http.HttpURI;
import org.eclipse.jetty.http.Parser;
import org.eclipse.jetty.io.ByteArrayBuffer; import org.eclipse.jetty.io.ByteArrayBuffer;
import org.eclipse.jetty.io.ByteArrayEndPoint; 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.bio.SocketConnector;
import org.eclipse.jetty.server.handler.AbstractHandler; import org.eclipse.jetty.server.handler.AbstractHandler;
import org.eclipse.jetty.server.handler.ContextHandler; import org.eclipse.jetty.server.handler.ContextHandler;
@ -55,7 +59,7 @@ public class ResponseTest
{ {
private Server server; private Server server;
private LocalConnector connector; private LocalConnector connector;
@Before @Before
public void init() throws Exception public void init() throws Exception
{ {
@ -76,7 +80,7 @@ public class ResponseTest
@Test @Test
public void testContentType() throws Exception 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(); Response response = connection.getResponse();
assertEquals(null,response.getContentType()); assertEquals(null,response.getContentType());
@ -121,7 +125,7 @@ public class ResponseTest
public void testLocale() throws Exception 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(); Request request = connection.getRequest();
Response response = connection.getResponse(); Response response = connection.getResponse();
ContextHandler context = new ContextHandler(); ContextHandler context = new ContextHandler();
@ -145,7 +149,7 @@ public class ResponseTest
@Test @Test
public void testContentTypeCharacterEncoding() throws Exception 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(); Request request = connection.getRequest();
Response response = connection.getResponse(); Response response = connection.getResponse();
@ -178,7 +182,7 @@ public class ResponseTest
@Test @Test
public void testCharacterEncodingContentType() throws Exception 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.setCharacterEncoding("utf-8");
response.setContentType("foo/bar"); response.setContentType("foo/bar");
@ -207,7 +211,7 @@ public class ResponseTest
@Test @Test
public void testContentTypeWithCharacterEncoding() throws Exception 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.setCharacterEncoding("utf16");
response.setContentType("foo/bar; charset=utf-8"); response.setContentType("foo/bar; charset=utf-8");
@ -236,7 +240,7 @@ public class ResponseTest
@Test @Test
public void testContentTypeWithOther() throws Exception 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"); response.setContentType("foo/bar; other=xyz");
assertEquals("foo/bar; other=xyz",response.getContentType()); assertEquals("foo/bar; other=xyz",response.getContentType());
@ -259,7 +263,7 @@ public class ResponseTest
@Test @Test
public void testContentTypeWithCharacterEncodingAndOther() throws Exception 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.setCharacterEncoding("utf16");
response.setContentType("foo/bar; charset=utf-8 other=xyz"); response.setContentType("foo/bar; charset=utf-8 other=xyz");
@ -319,7 +323,7 @@ public class ResponseTest
public void testEncodeRedirect() public void testEncodeRedirect()
throws Exception 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); Response response = new Response(connection);
Request request = connection.getRequest(); Request request = connection.getRequest();
request.setServerName("myhost"); request.setServerName("myhost");
@ -369,7 +373,7 @@ public class ResponseTest
throws Exception throws Exception
{ {
ByteArrayEndPoint out=new ByteArrayEndPoint(new byte[]{},4096); 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); Response response = new Response(connection);
Request request = connection.getRequest(); Request request = connection.getRequest();
request.setServerName("myhost"); request.setServerName("myhost");
@ -398,7 +402,7 @@ public class ResponseTest
@Test @Test
public void testSetBufferSize () throws Exception 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.setBufferSize(20*1024);
response.getWriter().print("hello"); response.getWriter().print("hello");
try try
@ -464,7 +468,7 @@ public class ResponseTest
ByteArrayEndPoint endPoint = new ByteArrayEndPoint(); ByteArrayEndPoint endPoint = new ByteArrayEndPoint();
endPoint.setOut(new ByteArrayBuffer(1024)); endPoint.setOut(new ByteArrayBuffer(1024));
endPoint.setGrowOutput(true); endPoint.setGrowOutput(true);
HttpConnection connection=new HttpConnection(connector, endPoint, connector.getServer()); HttpConnection connection=new TestHttpConnection(connector, endPoint, connector.getServer());
connection.getGenerator().reset(false); connection.getGenerator().reset(false);
HttpConnection.setCurrentConnection(connection); HttpConnection.setCurrentConnection(connection);
Response response = connection.getResponse(); Response response = connection.getResponse();
@ -565,4 +569,25 @@ public class ResponseTest
return null; 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;
}
}
} }