summaryrefslogtreecommitdiffstatsabout
diff options
context:
space:
mode:
authorThomas Becker2012-01-11 10:53:39 (EST)
committer Simone Bordet2012-01-11 11:07:50 (EST)
commitf81a8a3d9cff7e77bca42091e2dd55caf27c86eb (patch)
tree42a9c66e5c98ce3d16d08ae8cdab847a2593887c
parentc5e3ed5afe529f52096c3da69d55f2202d607dbf (diff)
downloadorg.eclipse.jetty.project-f81a8a3d9cff7e77bca42091e2dd55caf27c86eb.zip
org.eclipse.jetty.project-f81a8a3d9cff7e77bca42091e2dd55caf27c86eb.tar.gz
org.eclipse.jetty.project-f81a8a3d9cff7e77bca42091e2dd55caf27c86eb.tar.bz2
367716: Enhance maxIdleTests for SelectChannelTimeout
Signed-off-by: Simone Bordet <simone.bordet@gmail.com>
-rw-r--r--jetty-server/src/main/java/org/eclipse/jetty/server/AsyncHttpConnection.java20
-rw-r--r--jetty-server/src/test/java/org/eclipse/jetty/server/SelectChannelTimeoutTest.java11
2 files changed, 15 insertions, 16 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 59e6662..cbd9b7e 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
@@ -45,6 +45,7 @@ public class AsyncHttpConnection extends AbstractHttpConnection implements Async
_asyncEndp=(AsyncEndPoint)endpoint;
}
+ @Override
public Connection handle() throws IOException
{
Connection connection = this;
@@ -54,10 +55,10 @@ public class AsyncHttpConnection extends AbstractHttpConnection implements Async
try
{
setCurrentConnection(this);
-
+
// don't check for idle while dispatched (unless blocking IO is done).
_asyncEndp.setCheckForIdle(false);
-
+
// While progress and the connection has not changed
while (progress && connection==this)
@@ -67,7 +68,7 @@ public class AsyncHttpConnection extends AbstractHttpConnection implements Async
{
// Handle resumed request
if (_request._async.isAsync())
- {
+ {
if (_request._async.isDispatchable())
handleRequest();
}
@@ -126,7 +127,7 @@ public class AsyncHttpConnection extends AbstractHttpConnection implements Async
}
else if (_request.getAsyncContinuation().isAsyncStarted())
{
- // The request is suspended, so even though progress has been made,
+ // The request is suspended, so even though progress has been made,
// exit the while loop by setting progress to false
LOG.debug("suspended {}",this);
progress=false;
@@ -137,21 +138,18 @@ public class AsyncHttpConnection extends AbstractHttpConnection implements Async
finally
{
setCurrentConnection(null);
-
+
// If we are not suspended
if (!_request.getAsyncContinuation().isAsyncStarted())
{
// return buffers
_parser.returnBuffers();
_generator.returnBuffers();
- }
-
- // reenable idle checking unless request is suspended
- if(!_request.getAsyncContinuation().isAsyncStarted())
- {
+
+ // reenable idle checking unless request is suspended
_asyncEndp.setCheckForIdle(true);
}
-
+
// Safety net to catch spinning
if (some_progress)
_total_no_progress=0;
diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/SelectChannelTimeoutTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/SelectChannelTimeoutTest.java
index b0b3af6..ed0ec70 100644
--- a/jetty-server/src/test/java/org/eclipse/jetty/server/SelectChannelTimeoutTest.java
+++ b/jetty-server/src/test/java/org/eclipse/jetty/server/SelectChannelTimeoutTest.java
@@ -13,7 +13,6 @@
package org.eclipse.jetty.server;
-import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.io.IOException;
@@ -50,7 +49,7 @@ public class SelectChannelTimeoutTest extends ConnectorTimeoutTest
_handler.setSuspendFor(100);
_handler.setResumeAfter(25);
- assertTrue(process(null).toUpperCase().contains("RESUMED"));
+ assertTrue(process(null).toUpperCase().contains("RESUMED"));
}
@Test
@@ -84,7 +83,7 @@ public class SelectChannelTimeoutTest extends ConnectorTimeoutTest
private synchronized String process(String content) throws UnsupportedEncodingException, IOException, InterruptedException
{
- String request = "GET / HTTP/1.1\r\n" + "Host: localhost\r\n" + "Connection: close\r\n";
+ String request = "GET / HTTP/1.1\r\n" + "Host: localhost\r\n";
if (content == null)
request += "\r\n";
@@ -97,11 +96,13 @@ public class SelectChannelTimeoutTest extends ConnectorTimeoutTest
{
SelectChannelConnector connector = (SelectChannelConnector)_connector;
Socket socket = new Socket((String)null,connector.getLocalPort());
+ socket.setSoTimeout(10 * MAX_IDLE_TIME);
socket.getOutputStream().write(request.getBytes("UTF-8"));
InputStream inputStream = socket.getInputStream();
+ long start = System.currentTimeMillis();
String response = IO.toString(inputStream);
- Thread.sleep(500);
- assertEquals("Socket should be closed and return -1 on reading",-1,socket.getInputStream().read());
+ long timeElapsed = System.currentTimeMillis() - start;
+ assertTrue("Time elapsed should be at least MAX_IDLE_TIME",timeElapsed > MAX_IDLE_TIME);
return response;
}