aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Becker2013-07-11 09:13:01 (EDT)
committerThomas Becker2013-07-11 09:13:01 (EDT)
commitaf02334ff7a8beebbc700a63d1116cb3bbc7b68a (patch)
tree7bc55af3c74ba5fb35d404d763cb20596a0d7a81
parent8eb664970994f3ec7e4b7a39e88db8dac651c3f3 (diff)
downloadorg.eclipse.jetty.project-af02334ff7a8beebbc700a63d1116cb3bbc7b68a.zip
org.eclipse.jetty.project-af02334ff7a8beebbc700a63d1116cb3bbc7b68a.tar.gz
org.eclipse.jetty.project-af02334ff7a8beebbc700a63d1116cb3bbc7b68a.tar.bz2
412750 HttpClient close expired connections fix
-rw-r--r--jetty-client/src/main/java/org/eclipse/jetty/client/HttpExchange.java2
-rw-r--r--jetty-client/src/test/java/org/eclipse/jetty/client/IdleTimeoutTest.java67
2 files changed, 68 insertions, 1 deletions
diff --git a/jetty-client/src/main/java/org/eclipse/jetty/client/HttpExchange.java b/jetty-client/src/main/java/org/eclipse/jetty/client/HttpExchange.java
index 6fe6104..0877dd8 100644
--- a/jetty-client/src/main/java/org/eclipse/jetty/client/HttpExchange.java
+++ b/jetty-client/src/main/java/org/eclipse/jetty/client/HttpExchange.java
@@ -125,10 +125,10 @@ public class HttpExchange
protected void expire(HttpDestination destination)
{
+ AbstractHttpConnection connection = _connection;
if (getStatus() < HttpExchange.STATUS_COMPLETED)
setStatus(HttpExchange.STATUS_EXPIRED);
destination.exchangeExpired(this);
- AbstractHttpConnection connection = _connection;
if (connection != null)
connection.exchangeExpired(this);
}
diff --git a/jetty-client/src/test/java/org/eclipse/jetty/client/IdleTimeoutTest.java b/jetty-client/src/test/java/org/eclipse/jetty/client/IdleTimeoutTest.java
index 930a378..ed2b294 100644
--- a/jetty-client/src/test/java/org/eclipse/jetty/client/IdleTimeoutTest.java
+++ b/jetty-client/src/test/java/org/eclipse/jetty/client/IdleTimeoutTest.java
@@ -18,13 +18,28 @@
package org.eclipse.jetty.client;
+import java.io.IOException;
+import java.net.URI;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.eclipse.jetty.http.HttpMethods;
+import org.eclipse.jetty.server.Connector;
+import org.eclipse.jetty.server.Request;
+import org.eclipse.jetty.server.Server;
+import org.eclipse.jetty.server.handler.AbstractHandler;
+import org.eclipse.jetty.server.nio.SelectChannelConnector;
import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+
/**
* IdleTimeoutTest
*
@@ -77,4 +92,56 @@ public class IdleTimeoutTest
Assert.fail("Test did not complete in time");
}
+
+ @Test
+ public void testConnectionsAreReleasedWhenExpired() throws Exception
+ {
+ // we need a server that times out and a client with shorter timeout settings, so we need to create new ones
+ Server server = new Server();
+ Connector connector = new SelectChannelConnector();
+ server.addConnector(connector);
+ server.setHandler(new AbstractHandler()
+ {
+ public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
+ {
+ if (request.getParameter("timeout") != null)
+ {
+ try
+ {
+ Thread.sleep(1000);
+ }
+ catch (InterruptedException e)
+ {
+ e.printStackTrace();
+ }
+ }
+ baseRequest.setHandled(true);
+ response.getWriter().write("Hello world");
+ }
+ });
+ server.start();
+
+ HttpClient httpClient = new HttpClient();
+ httpClient.setMaxConnectionsPerAddress(1);
+ httpClient.setConnectTimeout(200);
+ httpClient.setTimeout(200);
+ httpClient.setIdleTimeout(200);
+ httpClient.start();
+
+ String uriString = "http://localhost:" + connector.getLocalPort() + "/";
+
+ HttpExchange httpExchange = new HttpExchange();
+ httpExchange.setURI(URI.create(uriString).resolve("?timeout=true"));
+ httpExchange.setMethod(HttpMethods.GET);
+ httpClient.send(httpExchange);
+ int status = httpExchange.waitForDone();
+ assertThat("First request expired", status, is(8));
+
+ httpExchange = new HttpExchange();
+ httpExchange.setURI(URI.create(uriString));
+ httpExchange.setMethod(HttpMethods.GET);
+ httpClient.send(httpExchange);
+ status = httpExchange.waitForDone();
+ assertThat("Second request was successful as timeout is not set", status, is(7));
+ }
}