From 569e9301857ac8ad8715d5cf1204bd120c426486 Mon Sep 17 00:00:00 2001 From: Greg Wilkins Date: Tue, 20 Dec 2011 11:13:45 +1100 Subject: [PATCH] 367048 test harness for guard on suspended requests --- .../jetty/server/AsyncHttpConnection.java | 2 +- .../server/SelectChannelAsyncContextTest.java | 56 ++++++++++++++++++- 2 files changed, 56 insertions(+), 2 deletions(-) diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/AsyncHttpConnection.java b/jetty-server/src/main/java/org/eclipse/jetty/server/AsyncHttpConnection.java index 7546302e697..8ec0737e5a7 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/AsyncHttpConnection.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/AsyncHttpConnection.java @@ -64,7 +64,7 @@ public class AsyncHttpConnection extends AbstractHttpConnection implements Async // Handle resumed request if (_request._async.isAsync()) { - if ( _request._async.isDispatchable()) + if (_request._async.isDispatchable()) handleRequest(); } // else Parse more input diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/SelectChannelAsyncContextTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/SelectChannelAsyncContextTest.java index 35383e345cf..3bd3cf3920e 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/SelectChannelAsyncContextTest.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/SelectChannelAsyncContextTest.java @@ -1,17 +1,33 @@ 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.EndPoint; +import org.eclipse.jetty.io.nio.SelectChannelEndPoint; import org.eclipse.jetty.server.nio.SelectChannelConnector; import org.eclipse.jetty.util.IO; +import org.junit.Test; public class SelectChannelAsyncContextTest extends LocalAsyncContextTest { + volatile SelectChannelEndPoint _endp; @Override 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 @@ -23,4 +39,42 @@ public class SelectChannelAsyncContextTest extends LocalAsyncContextTest 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(); + } + } }