367048 test harness for guard on suspended requests

This commit is contained in:
Greg Wilkins 2011-12-20 11:13:45 +11:00
parent b7d8bd4f28
commit 569e930185
2 changed files with 56 additions and 2 deletions

View File

@ -64,7 +64,7 @@ public class AsyncHttpConnection extends AbstractHttpConnection implements Async
// Handle resumed request // Handle resumed request
if (_request._async.isAsync()) if (_request._async.isAsync())
{ {
if ( _request._async.isDispatchable()) if (_request._async.isDispatchable())
handleRequest(); handleRequest();
} }
// else Parse more input // else Parse more input

View File

@ -1,17 +1,33 @@
package org.eclipse.jetty.server; package org.eclipse.jetty.server;
import java.io.IOException;
import java.net.Socket; import java.net.Socket;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import org.eclipse.jetty.io.EndPoint;
import org.eclipse.jetty.io.nio.SelectChannelEndPoint;
import org.eclipse.jetty.server.nio.SelectChannelConnector; import org.eclipse.jetty.server.nio.SelectChannelConnector;
import org.eclipse.jetty.util.IO; import org.eclipse.jetty.util.IO;
import org.junit.Test;
public class SelectChannelAsyncContextTest extends LocalAsyncContextTest public class SelectChannelAsyncContextTest extends LocalAsyncContextTest
{ {
volatile SelectChannelEndPoint _endp;
@Override @Override
protected Connector initConnector() protected Connector initConnector()
{ {
return new SelectChannelConnector(); return new SelectChannelConnector(){
@Override
public void customize(EndPoint endpoint, Request request) throws IOException
{
super.customize(endpoint,request);
_endp=(SelectChannelEndPoint)endpoint;
}
};
} }
@Override @Override
@ -23,4 +39,42 @@ public class SelectChannelAsyncContextTest extends LocalAsyncContextTest
return IO.toString(socket.getInputStream()); 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);
SelectChannelEndPoint endp=_endp;
if (endp!=null && endp.isOpen())
endp.asyncDispatch();
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
};
try
{
thread.start();
testSuspendResume();
}
finally
{
running.set(false);
thread.join();
}
}
} }