jetty-9 updated more test harness

This commit is contained in:
Greg Wilkins 2012-05-27 23:23:55 +02:00
parent a0dae20ac0
commit 571eb63bcd
8 changed files with 84 additions and 106 deletions

View File

@ -102,7 +102,7 @@ public class LocalAsyncContextTest
}
@Test
public void testSuspendOther() throws Exception
public void testSuspendComplete0() throws Exception
{
String response;
_handler.setRead(0);
@ -110,24 +110,53 @@ public class LocalAsyncContextTest
_handler.setResumeAfter(-1);
_handler.setCompleteAfter(0);
response=process(null);
check(response,"COMPLETED");
check(response,"STARTASYNC","COMPLETED");
}
@Test
public void testSuspendComplete200() throws Exception
{
String response;
_handler.setRead(0);
_handler.setSuspendFor(10000);
_handler.setResumeAfter(-1);
_handler.setCompleteAfter(200);
response=process(null);
check(response,"COMPLETED");
check(response,"STARTASYNC","COMPLETED");
}
@Test
public void testSuspendReadResume0() throws Exception
{
String response;
_handler.setSuspendFor(10000);
_handler.setRead(-1);
_handler.setResumeAfter(0);
_handler.setCompleteAfter(-1);
response=process("wibble");
check(response,"STARTASYNC","DISPATCHED");
}
@Test
public void testSuspendReadResume100() throws Exception
{
String response;
_handler.setSuspendFor(10000);
_handler.setRead(-1);
_handler.setResumeAfter(100);
_handler.setCompleteAfter(-1);
response=process("wibble");
check(response,"DISPATCHED");
_handler.setResumeAfter(100);
_handler.setCompleteAfter(-1);
check(response,"DISPATCHED");
}
@Test
public void testSuspendOther() throws Exception
{
String response;
_handler.setSuspendFor(10000);
_handler.setRead(-1);
_handler.setResumeAfter(-1);
_handler.setCompleteAfter(0);
response=process("wibble");
@ -205,9 +234,9 @@ public class LocalAsyncContextTest
else
request+="Content-Length: "+content.length()+"\r\n" +"\r\n" + content;
System.err.println("REQUEST: "+request);
//System.err.println("REQUEST: "+request);
String response=getResponse(request);
System.err.println("RESPONSE: "+response);
//System.err.println("RESPONSE: "+response);
return response;
}
@ -230,21 +259,21 @@ public class LocalAsyncContextTest
@Override
public void onComplete(AsyncEvent event) throws IOException
{
System.err.println("onComplete");
//System.err.println("onComplete");
__completed.incrementAndGet();
}
@Override
public void onError(AsyncEvent event) throws IOException
{
System.err.println("onError");
//System.err.println("onError");
__completed.incrementAndGet();
}
@Override
public void onStartAsync(AsyncEvent event) throws IOException
{
System.err.println("onStartAsync");
//System.err.println("onStartAsync");
event.getSuppliedResponse().getOutputStream().println("startasync");
event.getAsyncContext().addListener(this);
}
@ -252,7 +281,7 @@ public class LocalAsyncContextTest
@Override
public void onTimeout(AsyncEvent event) throws IOException
{
System.err.println("onTimeout - dispatch!");
//System.err.println("onTimeout - dispatch!");
event.getSuppliedRequest().setAttribute("TIMEOUT",Boolean.TRUE);
event.getAsyncContext().dispatch();
}

View File

@ -34,6 +34,8 @@ import javax.servlet.http.HttpServletResponse;
import org.eclipse.jetty.io.NetworkTrafficListener;
import org.eclipse.jetty.server.handler.AbstractHandler;
import org.eclipse.jetty.server.nio.NetworkTrafficSelectChannelConnector;
import org.eclipse.jetty.util.BufferUtil;
import org.eclipse.jetty.util.StringUtil;
import org.junit.After;
import org.junit.Test;
@ -121,14 +123,14 @@ public class NetworkTrafficListenerTest
@Override
public void incoming(Socket socket, ByteBuffer bytes)
{
incomingData.set(bytes.toString("UTF-8"));
incomingData.set(BufferUtil.toString(bytes,StringUtil.__UTF8_CHARSET));
incomingLatch.countDown();
}
@Override
public void outgoing(Socket socket, ByteBuffer bytes)
{
outgoingData.set(outgoingData.get() + bytes.toString("UTF-8"));
outgoingData.set(outgoingData.get() + BufferUtil.toString(bytes,StringUtil.__UTF8_CHARSET));
outgoingLatch.countDown();
}
});
@ -185,13 +187,13 @@ public class NetworkTrafficListenerTest
{
public void incoming(Socket socket, ByteBuffer bytes)
{
incomingData.set(bytes.toString("UTF-8"));
incomingData.set(BufferUtil.toString(bytes,StringUtil.__UTF8_CHARSET));
incomingLatch.countDown();
}
public void outgoing(Socket socket, ByteBuffer bytes)
{
outgoingData.set(outgoingData.get() + bytes.toString("UTF-8"));
outgoingData.set(outgoingData.get() + BufferUtil.toString(bytes,StringUtil.__UTF8_CHARSET));
outgoingLatch.countDown();
}
});
@ -252,13 +254,13 @@ public class NetworkTrafficListenerTest
{
public void incoming(Socket socket, ByteBuffer bytes)
{
incomingData.set(bytes.toString("UTF-8"));
incomingData.set(BufferUtil.toString(bytes,StringUtil.__UTF8_CHARSET));
incomingLatch.countDown();
}
public void outgoing(Socket socket, ByteBuffer bytes)
{
outgoingData.set(outgoingData.get() + bytes.toString("UTF-8"));
outgoingData.set(outgoingData.get() + BufferUtil.toString(bytes,StringUtil.__UTF8_CHARSET));
outgoingLatch.countDown();
}
});
@ -318,13 +320,13 @@ public class NetworkTrafficListenerTest
{
public void incoming(Socket socket, ByteBuffer bytes)
{
incomingData.set(bytes.toString("UTF-8"));
incomingData.set(BufferUtil.toString(bytes,StringUtil.__UTF8_CHARSET));
incomingLatch.countDown();
}
public void outgoing(Socket socket, ByteBuffer bytes)
{
outgoingData.set(outgoingData.get() + bytes.toString("UTF-8"));
outgoingData.set(outgoingData.get() + BufferUtil.toString(bytes,StringUtil.__UTF8_CHARSET));
outgoingLatch.countDown();
}
});
@ -391,12 +393,12 @@ public class NetworkTrafficListenerTest
{
public void incoming(Socket socket, ByteBuffer bytes)
{
incomingData.set(incomingData.get() + bytes.toString("UTF-8"));
incomingData.set(incomingData.get() + BufferUtil.toString(bytes,StringUtil.__UTF8_CHARSET));
}
public void outgoing(Socket socket, ByteBuffer bytes)
{
outgoingData.set(outgoingData.get() + bytes.toString("UTF-8"));
outgoingData.set(outgoingData.get() + BufferUtil.toString(bytes,StringUtil.__UTF8_CHARSET));
outgoingLatch.countDown();
}
});

View File

@ -1,32 +1,15 @@
package org.eclipse.jetty.server;
import java.io.IOException;
import java.net.Socket;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import org.eclipse.jetty.io.AsyncEndPoint;
import org.eclipse.jetty.io.EndPoint;
import org.eclipse.jetty.util.IO;
import org.junit.Test;
public class SelectChannelAsyncContextTest extends LocalAsyncContextTest
{
volatile AsyncEndPoint _endp;
@Override
protected Connector initConnector()
{
return new SelectChannelConnector(){
@Override
public void customize(EndPoint endpoint, Request request) throws IOException
{
super.customize(endpoint,request);
_endp=(AsyncEndPoint)endpoint;
}
};
return new SelectChannelConnector();
}
@Override
@ -37,43 +20,4 @@ public class SelectChannelAsyncContextTest extends LocalAsyncContextTest
socket.getOutputStream().write(request.getBytes("UTF-8"));
return IO.toString(socket.getInputStream());
}
@Test
public void testSuspendResumeWithAsyncDispatch() throws Exception
{
// Test that suspend/resume works in the face of spurious asyncDispatch call that may be
// produced by the SslConnection
final AtomicBoolean running = new AtomicBoolean(true);
Thread thread = new Thread()
{
public void run()
{
while (running.get())
{
try
{
TimeUnit.MILLISECONDS.sleep(200);
AsyncEndPoint endp=_endp;
if (endp!=null && endp.isOpen())
endp.asyncDispatch();
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
};
try
{
thread.start();
testSuspendResume();
}
finally
{
running.set(false);
thread.join();
}
}
}

View File

@ -149,7 +149,7 @@ class SuspendHandler extends HandlerWrapper
final AsyncContext asyncContext = baseRequest.startAsync();
System.err.println("STARTASYNC");
// System.err.println("STARTASYNC");
response.getOutputStream().println("STARTASYNC");
asyncContext.addListener(LocalAsyncContextTest.__asyncListener);
asyncContext.addListener(LocalAsyncContextTest.__asyncListener1);
@ -166,7 +166,7 @@ class SuspendHandler extends HandlerWrapper
try
{
Thread.sleep(_completeAfter);
System.err.println("COMPLETED");
//System.err.println("COMPLETED");
response.getOutputStream().println("COMPLETED");
response.setStatus(200);
baseRequest.setHandled(true);
@ -181,7 +181,7 @@ class SuspendHandler extends HandlerWrapper
}
else if (_completeAfter==0)
{
System.err.println("COMPLETED0");
//System.err.println("COMPLETED0");
response.getOutputStream().println("COMPLETED");
response.setStatus(200);
baseRequest.setHandled(true);
@ -216,19 +216,19 @@ class SuspendHandler extends HandlerWrapper
{
if (request.getAttribute("TIMEOUT")!=null)
{
System.err.println("TIMEOUT");
//System.err.println("TIMEOUT");
response.getOutputStream().println("TIMEOUT");
}
else
{
System.err.println("DISPATCHED");
//System.err.println("DISPATCHED");
response.getOutputStream().println("DISPATCHED");
}
if (_suspendFor2>=0)
{
final AsyncContext asyncContext = baseRequest.startAsync();
System.err.println("STARTASYNC2");
//System.err.println("STARTASYNC2");
response.getOutputStream().println("STARTASYNC2");
if (_suspendFor2>0)
asyncContext.setTimeout(_suspendFor2);
@ -243,7 +243,7 @@ class SuspendHandler extends HandlerWrapper
try
{
Thread.sleep(_completeAfter2);
System.err.println("COMPLETED2");
//System.err.println("COMPLETED2");
response.getOutputStream().println("COMPLETED2");
response.setStatus(200);
baseRequest.setHandled(true);
@ -258,7 +258,7 @@ class SuspendHandler extends HandlerWrapper
}
else if (_completeAfter2==0)
{
System.err.println("COMPLETED2==0");
//System.err.println("COMPLETED2==0");
response.getOutputStream().println("COMPLETED2");
response.setStatus(200);
baseRequest.setHandled(true);

View File

@ -136,7 +136,7 @@ public abstract class AbstractConnectHandlerTest
protected Socket newSocket() throws IOException
{
Socket socket = new Socket("localhost", proxyConnector.getLocalPort());
Socket socket = new Socket("localhost", ((Connector.NetConnector)proxyConnector).getLocalPort());
socket.setSoTimeout(10000);
return socket;
}

View File

@ -24,6 +24,7 @@ import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.eclipse.jetty.server.Connector;
import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.server.ssl.SslSelectChannelConnector;
import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
@ -55,7 +56,7 @@ public class ConnectHandlerSSLTest extends AbstractConnectHandlerTest
@Test
public void testGETRequest() throws Exception
{
String hostPort = "localhost:" + serverConnector.getLocalPort();
String hostPort = "localhost:" + ((Connector.NetConnector)serverConnector).getLocalPort();
String request = "" +
"CONNECT " + hostPort + " HTTP/1.1\r\n" +
"Host: " + hostPort + "\r\n" +
@ -110,7 +111,7 @@ public class ConnectHandlerSSLTest extends AbstractConnectHandlerTest
@Test
public void testPOSTRequests() throws Exception
{
String hostPort = "localhost:" + serverConnector.getLocalPort();
String hostPort = "localhost:" + ((Connector.NetConnector)serverConnector).getLocalPort();
String request = "" +
"CONNECT " + hostPort + " HTTP/1.1\r\n" +
"Host: " + hostPort + "\r\n" +

View File

@ -20,6 +20,7 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.eclipse.jetty.io.EndPoint;
import org.eclipse.jetty.server.Connector;
import org.eclipse.jetty.server.SelectChannelConnector;
import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.toolchain.test.OS;
@ -41,7 +42,7 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
@Test
public void testCONNECT() throws Exception
{
String hostPort = "localhost:" + serverConnector.getLocalPort();
String hostPort = "localhost:" + ((Connector.NetConnector)serverConnector).getLocalPort();
String request = "" +
"CONNECT " + hostPort + " HTTP/1.1\r\n" +
"Host: " + hostPort + "\r\n" +
@ -68,7 +69,7 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
@Test
public void testCONNECTAndGET() throws Exception
{
String hostPort = "localhost:" + serverConnector.getLocalPort();
String hostPort = "localhost:" + ((Connector.NetConnector)serverConnector).getLocalPort();
String request = "" +
"CONNECT " + hostPort + " HTTP/1.1\r\n" +
"Host: " + hostPort + "\r\n" +
@ -107,7 +108,7 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
@Test
public void testCONNECT10AndGET() throws Exception
{
String hostPort = "localhost:" + serverConnector.getLocalPort();
String hostPort = "localhost:" + ((Connector.NetConnector)serverConnector).getLocalPort();
String request = "" +
"CONNECT " + hostPort + " HTTP/1.0\r\n" +
"Host: " + hostPort + "\r\n" +
@ -145,7 +146,7 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
@Test
public void testCONNECTAndGETPipelined() throws Exception
{
String hostPort = "localhost:" + serverConnector.getLocalPort();
String hostPort = "localhost:" + ((Connector.NetConnector)serverConnector).getLocalPort();
String request = "" +
"CONNECT " + hostPort + " HTTP/1.1\r\n" +
"Host: " + hostPort + "\r\n" +
@ -180,7 +181,7 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
@Test
public void testCONNECTAndMultipleGETs() throws Exception
{
String hostPort = "localhost:" + serverConnector.getLocalPort();
String hostPort = "localhost:" + ((Connector.NetConnector)serverConnector).getLocalPort();
String request = "" +
"CONNECT " + hostPort + " HTTP/1.1\r\n" +
"Host: " + hostPort + "\r\n" +
@ -221,7 +222,7 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
@Test
public void testCONNECTAndGETServerStop() throws Exception
{
String hostPort = "localhost:" + serverConnector.getLocalPort();
String hostPort = "localhost:" + ((Connector.NetConnector)serverConnector).getLocalPort();
String request = "" +
"CONNECT " + hostPort + " HTTP/1.1\r\n" +
"Host: " + hostPort + "\r\n" +
@ -267,7 +268,7 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
@Test
public void testCONNECTAndGETAndServerSideClose() throws Exception
{
String hostPort = "localhost:" + serverConnector.getLocalPort();
String hostPort = "localhost:" + ((Connector.NetConnector)serverConnector).getLocalPort();
String request = "" +
"CONNECT " + hostPort + " HTTP/1.1\r\n" +
"Host: " + hostPort + "\r\n" +
@ -304,7 +305,7 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
@Test
public void testCONNECTAndPOSTAndGET() throws Exception
{
String hostPort = "localhost:" + serverConnector.getLocalPort();
String hostPort = "localhost:" + ((Connector.NetConnector)serverConnector).getLocalPort();
String request = "" +
"CONNECT " + hostPort + " HTTP/1.1\r\n" +
"Host: " + hostPort + "\r\n" +
@ -355,7 +356,7 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
@Test
public void testCONNECTAndPOSTWithBigBody() throws Exception
{
String hostPort = "localhost:" + serverConnector.getLocalPort();
String hostPort = "localhost:" + ((Connector.NetConnector)serverConnector).getLocalPort();
String request = "" +
"CONNECT " + hostPort + " HTTP/1.1\r\n" +
"Host: " + hostPort + "\r\n" +
@ -445,7 +446,7 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
});
proxy.start();
String hostPort = "localhost:" + serverConnector.getLocalPort();
String hostPort = "localhost:" + ((Connector.NetConnector)serverConnector).getLocalPort();
String request = "" +
"CONNECT " + hostPort + " HTTP/1.1\r\n" +
"Host: " + hostPort + "\r\n" +
@ -489,7 +490,7 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
// TODO needs to be further investigated
assumeTrue(!OS.IS_OSX);
String hostPort = "localhost:" + serverConnector.getLocalPort();
String hostPort = "localhost:" + ((Connector.NetConnector)serverConnector).getLocalPort();
String request = "" +
"CONNECT " + hostPort + " HTTP/1.1\r\n" +
"Host: " + hostPort + "\r\n" +
@ -528,7 +529,7 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
// TODO needs to be further investigated
assumeTrue(!OS.IS_OSX);
String hostPort = "localhost:" + serverConnector.getLocalPort();
String hostPort = "localhost:" + ((Connector.NetConnector)serverConnector).getLocalPort();
String request = "" +
"CONNECT " + hostPort + " HTTP/1.1\r\n" +
"Host: " + hostPort + "\r\n" +
@ -592,7 +593,7 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
}
else if ("/close".equals(uri))
{
request.getHttpChannel().getEndPoint().close();
request.getHttpChannel().getConnection().getEndPoint().close();
}
else
{

View File

@ -18,6 +18,7 @@ import junit.framework.Assert;
import junit.framework.TestCase;
import org.eclipse.jetty.server.Connector;
import org.eclipse.jetty.server.SelectChannelConnector;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
import org.eclipse.jetty.toolchain.test.SimpleRequest;
@ -33,7 +34,7 @@ import org.junit.Test;
public class ResourceHandlerTest extends TestCase
{
private static Server _server;
private static Connector _connector;
private static SelectChannelConnector _connector;
private static ContextHandler _contextHandler;
private static ResourceHandler _resourceHandler;
@ -42,7 +43,7 @@ public class ResourceHandlerTest extends TestCase
public void setUp() throws Exception
{
_server = new Server();
_connector = new SocketConnector();
_connector = new SelectChannelConnector();
_server.setConnectors(new Connector[] { _connector });
_resourceHandler = new ResourceHandler();