hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1603443 [2/3] - in /httpcomponents/httpclient/trunk: fluent-hc/src/test/java/org/apache/http/client/fluent/ httpclient-cache/src/test/java/org/apache/http/impl/client/cache/ httpclient/src/test/java/org/apache/http/conn/ssl/ httpclient/src...
Date Wed, 18 Jun 2014 13:06:44 GMT
Modified: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestClientRequestExecution.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestClientRequestExecution.java?rev=1603443&r1=1603442&r2=1603443&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestClientRequestExecution.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestClientRequestExecution.java Wed Jun 18 13:06:43 2014
@@ -49,25 +49,19 @@ import org.apache.http.client.utils.URIB
 import org.apache.http.client.utils.URIUtils;
 import org.apache.http.entity.InputStreamEntity;
 import org.apache.http.entity.StringEntity;
-import org.apache.http.impl.client.HttpClients;
+import org.apache.http.localserver.LocalServerTestBase;
 import org.apache.http.message.BasicHttpRequest;
 import org.apache.http.protocol.HttpContext;
 import org.apache.http.protocol.HttpRequestExecutor;
 import org.apache.http.protocol.HttpRequestHandler;
 import org.apache.http.util.EntityUtils;
 import org.junit.Assert;
-import org.junit.Before;
 import org.junit.Test;
 
 /**
  * Client protocol handling tests.
  */
-public class TestClientRequestExecution extends IntegrationTestBase {
-
-    @Before
-    public void setUp() throws Exception {
-        startServer();
-    }
+public class TestClientRequestExecution extends LocalServerTestBase {
 
     private static class SimpleService implements HttpRequestHandler {
 
@@ -115,8 +109,7 @@ public class TestClientRequestExecution 
 
     @Test
     public void testAutoGeneratedHeaders() throws Exception {
-        final int port = this.localServer.getServiceAddress().getPort();
-        this.localServer.register("*", new SimpleService());
+        this.serverBootstrap.registerHandler("*", new SimpleService());
 
         final HttpRequestInterceptor interceptor = new HttpRequestInterceptor() {
 
@@ -141,18 +134,19 @@ public class TestClientRequestExecution 
 
         };
 
-        this.httpclient = HttpClients.custom()
+        this.httpclient = this.clientBuilder
             .addInterceptorFirst(interceptor)
             .setRequestExecutor(new FaultyHttpRequestExecutor("Oppsie"))
             .setRetryHandler(requestRetryHandler)
             .build();
 
+        final HttpHost target = start();
+
         final HttpClientContext context = HttpClientContext.create();
 
-        final String s = "http://localhost:" + port;
-        final HttpGet httpget = new HttpGet(s);
+        final HttpGet httpget = new HttpGet("/");
 
-        final HttpResponse response = this.httpclient.execute(getServerHttp(), httpget, context);
+        final HttpResponse response = this.httpclient.execute(target, httpget, context);
         EntityUtils.consume(response.getEntity());
 
         final HttpRequest reqWrapper = context.getRequest();
@@ -166,8 +160,7 @@ public class TestClientRequestExecution 
 
     @Test(expected=ClientProtocolException.class)
     public void testNonRepeatableEntity() throws Exception {
-        final int port = this.localServer.getServiceAddress().getPort();
-        this.localServer.register("*", new SimpleService());
+        this.serverBootstrap.registerHandler("*", new SimpleService());
 
         final HttpRequestRetryHandler requestRetryHandler = new HttpRequestRetryHandler() {
 
@@ -181,22 +174,23 @@ public class TestClientRequestExecution 
 
         };
 
-        this.httpclient = HttpClients.custom()
+        this.httpclient = this.clientBuilder
             .setRequestExecutor(new FaultyHttpRequestExecutor("a message showing that this failed"))
             .setRetryHandler(requestRetryHandler)
             .build();
 
+        final HttpHost target = start();
+
         final HttpClientContext context = HttpClientContext.create();
 
-        final String s = "http://localhost:" + port;
-        final HttpPost httppost = new HttpPost(s);
+        final HttpPost httppost = new HttpPost("/");
         httppost.setEntity(new InputStreamEntity(
                 new ByteArrayInputStream(
                         new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 } ),
                         -1));
 
         try {
-            this.httpclient.execute(getServerHttp(), httppost, context);
+            this.httpclient.execute(target, httppost, context);
         } catch (final ClientProtocolException ex) {
             Assert.assertTrue(ex.getCause() instanceof NonRepeatableRequestException);
             final NonRepeatableRequestException nonRepeat = (NonRepeatableRequestException)ex.getCause();
@@ -208,12 +202,13 @@ public class TestClientRequestExecution 
 
     @Test
     public void testNonCompliantURI() throws Exception {
-        this.localServer.register("*", new SimpleService());
-        this.httpclient = HttpClients.createDefault();
+        this.serverBootstrap.registerHandler("*", new SimpleService());
+
+        final HttpHost target = start();
 
         final HttpClientContext context = HttpClientContext.create();
         final BasicHttpRequest request = new BasicHttpRequest("GET", "blah.:.blah.:.");
-        final HttpResponse response = this.httpclient.execute(getServerHttp(), request, context);
+        final HttpResponse response = this.httpclient.execute(target, request, context);
         EntityUtils.consume(response.getEntity());
 
         Assert.assertEquals(HttpStatus.SC_OK, response.getStatusLine().getStatusCode());
@@ -225,9 +220,9 @@ public class TestClientRequestExecution 
 
     @Test
     public void testRelativeRequestURIWithFragment() throws Exception {
-        this.localServer.register("*", new SimpleService());
-        this.httpclient = HttpClients.createDefault();
-        final HttpHost target = getServerHttp();
+        this.serverBootstrap.registerHandler("*", new SimpleService());
+
+        final HttpHost target = start();
 
         final HttpGet httpget = new HttpGet("/stuff#blahblah");
         final HttpClientContext context = HttpClientContext.create();
@@ -242,9 +237,9 @@ public class TestClientRequestExecution 
 
     @Test
     public void testAbsoluteRequestURIWithFragment() throws Exception {
-        this.localServer.register("*", new SimpleService());
-        this.httpclient = HttpClients.createDefault();
-        final HttpHost target = getServerHttp();
+        this.serverBootstrap.registerHandler("*", new SimpleService());
+
+        final HttpHost target = start();
 
         final URI uri = new URIBuilder()
             .setHost(target.getHostName())

Modified: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestConnectionAutoRelease.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestConnectionAutoRelease.java?rev=1603443&r1=1603442&r2=1603443&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestConnectionAutoRelease.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestConnectionAutoRelease.java Wed Jun 18 13:06:43 2014
@@ -45,44 +45,32 @@ import org.apache.http.conn.ConnectionRe
 import org.apache.http.conn.routing.HttpRoute;
 import org.apache.http.entity.BasicHttpEntity;
 import org.apache.http.impl.DefaultBHttpServerConnection;
-import org.apache.http.impl.client.HttpClients;
-import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
+import org.apache.http.localserver.LocalServerTestBase;
 import org.apache.http.pool.PoolStats;
 import org.apache.http.protocol.HttpContext;
 import org.apache.http.protocol.HttpCoreContext;
 import org.apache.http.protocol.HttpRequestHandler;
 import org.apache.http.util.EntityUtils;
 import org.junit.Assert;
-import org.junit.Before;
 import org.junit.Test;
 
-public class TestConnectionAutoRelease extends IntegrationTestBase {
-
-    private PoolingHttpClientConnectionManager mgr;
-
-    @Before
-    public void setUp() throws Exception {
-        startServer();
-        this.mgr = new PoolingHttpClientConnectionManager();
-        this.httpclient = HttpClients.custom().setConnectionManager(this.mgr).build();
-    }
+public class TestConnectionAutoRelease extends LocalServerTestBase {
 
     @Test
     public void testReleaseOnEntityConsumeContent() throws Exception {
-        this.mgr.setDefaultMaxPerRoute(1);
-        this.mgr.setMaxTotal(1);
+        this.connManager.setDefaultMaxPerRoute(1);
+        this.connManager.setMaxTotal(1);
 
         // Zero connections in the pool
-        PoolStats stats = this.mgr.getTotalStats();
+        PoolStats stats = this.connManager.getTotalStats();
         Assert.assertEquals(0, stats.getAvailable());
 
+        final HttpHost target = start();
         // Get some random data
         final HttpGet httpget = new HttpGet("/random/20000");
-        final HttpHost target = getServerHttp();
-
         final HttpResponse response = this.httpclient.execute(target, httpget);
 
-        ConnectionRequest connreq = this.mgr.requestConnection(new HttpRoute(target), null);
+        ConnectionRequest connreq = this.connManager.requestConnection(new HttpRoute(target), null);
         try {
             connreq.get(250, TimeUnit.MILLISECONDS);
             Assert.fail("ConnectionPoolTimeoutException should have been thrown");
@@ -94,32 +82,31 @@ public class TestConnectionAutoRelease e
         EntityUtils.consume(e);
 
         // Expect one connection in the pool
-        stats = this.mgr.getTotalStats();
+        stats = this.connManager.getTotalStats();
         Assert.assertEquals(1, stats.getAvailable());
 
         // Make sure one connection is available
-        connreq = this.mgr.requestConnection(new HttpRoute(target), null);
+        connreq = this.connManager.requestConnection(new HttpRoute(target), null);
         final HttpClientConnection conn = connreq.get(250, TimeUnit.MILLISECONDS);
 
-        this.mgr.releaseConnection(conn, null, -1, null);
+        this.connManager.releaseConnection(conn, null, -1, null);
     }
 
     @Test
     public void testReleaseOnEntityWriteTo() throws Exception {
-        this.mgr.setDefaultMaxPerRoute(1);
-        this.mgr.setMaxTotal(1);
+        this.connManager.setDefaultMaxPerRoute(1);
+        this.connManager.setMaxTotal(1);
 
         // Zero connections in the pool
-        PoolStats stats = this.mgr.getTotalStats();
+        PoolStats stats = this.connManager.getTotalStats();
         Assert.assertEquals(0, stats.getAvailable());
 
+        final HttpHost target = start();
         // Get some random data
         final HttpGet httpget = new HttpGet("/random/20000");
-        final HttpHost target = getServerHttp();
-
         final HttpResponse response = this.httpclient.execute(target, httpget);
 
-        ConnectionRequest connreq = this.mgr.requestConnection(new HttpRoute(target), null);
+        ConnectionRequest connreq = this.connManager.requestConnection(new HttpRoute(target), null);
         try {
             connreq.get(250, TimeUnit.MILLISECONDS);
             Assert.fail("ConnectionPoolTimeoutException should have been thrown");
@@ -132,32 +119,32 @@ public class TestConnectionAutoRelease e
         e.writeTo(outsteam);
 
         // Expect one connection in the pool
-        stats = this.mgr.getTotalStats();
+        stats = this.connManager.getTotalStats();
         Assert.assertEquals(1, stats.getAvailable());
 
         // Make sure one connection is available
-        connreq = this.mgr.requestConnection(new HttpRoute(target), null);
+        connreq = this.connManager.requestConnection(new HttpRoute(target), null);
         final HttpClientConnection conn = connreq.get(250, TimeUnit.MILLISECONDS);
 
-        this.mgr.releaseConnection(conn, null, -1, null);
+        this.connManager.releaseConnection(conn, null, -1, null);
     }
 
     @Test
     public void testReleaseOnAbort() throws Exception {
-        this.mgr.setDefaultMaxPerRoute(1);
-        this.mgr.setMaxTotal(1);
+        this.connManager.setDefaultMaxPerRoute(1);
+        this.connManager.setMaxTotal(1);
 
         // Zero connections in the pool
-        final PoolStats stats = this.mgr.getTotalStats();
+        final PoolStats stats = this.connManager.getTotalStats();
         Assert.assertEquals(0, stats.getAvailable());
 
+        final HttpHost target = start();
+
         // Get some random data
         final HttpGet httpget = new HttpGet("/random/20000");
-        final HttpHost target = getServerHttp();
-
         final HttpResponse response = this.httpclient.execute(target, httpget);
 
-        ConnectionRequest connreq = this.mgr.requestConnection(new HttpRoute(target), null);
+        ConnectionRequest connreq = this.connManager.requestConnection(new HttpRoute(target), null);
         try {
             connreq.get(250, TimeUnit.MILLISECONDS);
             Assert.fail("ConnectionPoolTimeoutException should have been thrown");
@@ -169,18 +156,18 @@ public class TestConnectionAutoRelease e
         httpget.abort();
 
         // Expect zero connections in the pool
-        Assert.assertEquals(0, this.mgr.getTotalStats().getAvailable());
+        Assert.assertEquals(0, this.connManager.getTotalStats().getAvailable());
 
         // Make sure one connection is available
-        connreq = this.mgr.requestConnection(new HttpRoute(target), null);
+        connreq = this.connManager.requestConnection(new HttpRoute(target), null);
         final HttpClientConnection conn = connreq.get(250, TimeUnit.MILLISECONDS);
 
-        this.mgr.releaseConnection(conn, null, -1, null);
+        this.connManager.releaseConnection(conn, null, -1, null);
     }
 
     @Test
     public void testReleaseOnIOException() throws Exception {
-        this.localServer.register("/dropdead", new HttpRequestHandler() {
+        this.serverBootstrap.registerHandler("/dropdead", new HttpRequestHandler() {
 
             @Override
             public void handle(
@@ -199,33 +186,33 @@ public class TestConnectionAutoRelease e
                         // do something comletely ugly in order to trigger
                         // MalformedChunkCodingException
                         final DefaultBHttpServerConnection conn = (DefaultBHttpServerConnection)
-                            context.getAttribute(HttpCoreContext.HTTP_CONNECTION);
+                                context.getAttribute(HttpCoreContext.HTTP_CONNECTION);
                         try {
                             conn.sendResponseHeader(response);
                         } catch (final HttpException ignore) {
                         }
                     }
 
-                } ;
+                };
                 entity.setChunked(true);
                 response.setEntity(entity);
             }
 
         });
 
-        this.mgr.setDefaultMaxPerRoute(1);
-        this.mgr.setMaxTotal(1);
+        this.connManager.setDefaultMaxPerRoute(1);
+        this.connManager.setMaxTotal(1);
 
         // Zero connections in the pool
-        Assert.assertEquals(0, this.mgr.getTotalStats().getAvailable());
+        Assert.assertEquals(0, this.connManager.getTotalStats().getAvailable());
+
+        final HttpHost target = start();
 
         // Get some random data
         final HttpGet httpget = new HttpGet("/dropdead");
-        final HttpHost target = getServerHttp();
-
         final HttpResponse response = this.httpclient.execute(target, httpget);
 
-        ConnectionRequest connreq = this.mgr.requestConnection(new HttpRoute(target), null);
+        ConnectionRequest connreq = this.connManager.requestConnection(new HttpRoute(target), null);
         try {
             connreq.get(250, TimeUnit.MILLISECONDS);
             Assert.fail("ConnectionPoolTimeoutException should have been thrown");
@@ -243,13 +230,13 @@ public class TestConnectionAutoRelease e
         }
 
         // Expect zero connections in the pool
-        Assert.assertEquals(0, this.mgr.getTotalStats().getAvailable());
+        Assert.assertEquals(0, this.connManager.getTotalStats().getAvailable());
 
         // Make sure one connection is available
-        connreq = this.mgr.requestConnection(new HttpRoute(target), null);
+        connreq = this.connManager.requestConnection(new HttpRoute(target), null);
         final HttpClientConnection conn = connreq.get(250, TimeUnit.MILLISECONDS);
 
-        this.mgr.releaseConnection(conn, null, -1, null);
+        this.connManager.releaseConnection(conn, null, -1, null);
     }
 
 }

Modified: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestConnectionManagement.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestConnectionManagement.java?rev=1603443&r1=1603442&r2=1603443&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestConnectionManagement.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestConnectionManagement.java Wed Jun 18 13:06:43 2014
@@ -65,7 +65,6 @@ import org.apache.http.protocol.RequestC
 import org.apache.http.protocol.RequestContent;
 import org.apache.http.util.EntityUtils;
 import org.junit.Assert;
-import org.junit.Before;
 import org.junit.Test;
 
 /**
@@ -74,11 +73,6 @@ import org.junit.Test;
  */
 public class TestConnectionManagement extends LocalServerTestBase {
 
-    @Before
-    public void setup() throws Exception {
-        startServer();
-    }
-
     private static HttpClientConnection getConnection(
             final HttpClientConnectionManager mgr,
             final HttpRoute route,
@@ -101,10 +95,9 @@ public class TestConnectionManagement ex
     @Test
     public void testReleaseConnection() throws Exception {
 
-        final PoolingHttpClientConnectionManager mgr = new PoolingHttpClientConnectionManager();
-        mgr.setMaxTotal(1);
+        this.connManager.setMaxTotal(1);
 
-        final HttpHost target = getServerHttp();
+        final HttpHost target = start();
         final HttpRoute route = new HttpRoute(target, null, false);
         final int      rsplen = 8;
         final String      uri = "/random/" + rsplen;
@@ -112,9 +105,9 @@ public class TestConnectionManagement ex
         final HttpRequest request = new BasicHttpRequest("GET", uri, HttpVersion.HTTP_1_1);
         final HttpContext context = new BasicHttpContext();
 
-        HttpClientConnection conn = getConnection(mgr, route);
-        mgr.connect(conn, route, 0, context);
-        mgr.routeComplete(conn, route, context);
+        HttpClientConnection conn = getConnection(this.connManager, route);
+        this.connManager.connect(conn, route, 0, context);
+        this.connManager.routeComplete(conn, route, context);
 
         context.setAttribute(HttpCoreContext.HTTP_CONNECTION, conn);
         context.setAttribute(HttpCoreContext.HTTP_TARGET_HOST, target);
@@ -137,19 +130,19 @@ public class TestConnectionManagement ex
         // check that there is no auto-release by default
         try {
             // this should fail quickly, connection has not been released
-            getConnection(mgr, route, 10L, TimeUnit.MILLISECONDS);
+            getConnection(this.connManager, route, 10L, TimeUnit.MILLISECONDS);
             Assert.fail("ConnectionPoolTimeoutException should have been thrown");
         } catch (final ConnectionPoolTimeoutException e) {
             // expected
         }
 
         conn.close();
-        mgr.releaseConnection(conn, null, -1, null);
-        conn = getConnection(mgr, route);
+        this.connManager.releaseConnection(conn, null, -1, null);
+        conn = getConnection(this.connManager, route);
         Assert.assertFalse("connection should have been closed", conn.isOpen());
 
-        mgr.connect(conn, route, 0, context);
-        mgr.routeComplete(conn, route, context);
+        this.connManager.connect(conn, route, 0, context);
+        this.connManager.routeComplete(conn, route, context);
 
         // repeat the communication, no need to prepare the request again
         context.setAttribute(HttpCoreContext.HTTP_CONNECTION, conn);
@@ -165,8 +158,8 @@ public class TestConnectionManagement ex
 
         // release connection after marking it for re-use
         // expect the next connection obtained to be open
-        mgr.releaseConnection(conn, null, -1, null);
-        conn = getConnection(mgr, route);
+        this.connManager.releaseConnection(conn, null, -1, null);
+        conn = getConnection(this.connManager, route);
         Assert.assertTrue("connection should have been open", conn.isOpen());
 
         // repeat the communication, no need to prepare the request again
@@ -181,8 +174,8 @@ public class TestConnectionManagement ex
                      rsplen, data.length);
         // ignore data, but it must be read
 
-        mgr.releaseConnection(conn, null, -1, null);
-        mgr.shutdown();
+        this.connManager.releaseConnection(conn, null, -1, null);
+        this.connManager.shutdown();
     }
 
     /**
@@ -191,10 +184,9 @@ public class TestConnectionManagement ex
     @Test
     public void testReleaseConnectionWithTimeLimits() throws Exception {
 
-        final PoolingHttpClientConnectionManager mgr = new PoolingHttpClientConnectionManager();
-        mgr.setMaxTotal(1);
+        this.connManager.setMaxTotal(1);
 
-        final HttpHost target = getServerHttp();
+        final HttpHost target = start();
         final HttpRoute route = new HttpRoute(target, null, false);
         final int      rsplen = 8;
         final String      uri = "/random/" + rsplen;
@@ -202,9 +194,9 @@ public class TestConnectionManagement ex
         final HttpRequest request = new BasicHttpRequest("GET", uri, HttpVersion.HTTP_1_1);
         final HttpContext context = new BasicHttpContext();
 
-        HttpClientConnection conn = getConnection(mgr, route);
-        mgr.connect(conn, route, 0, context);
-        mgr.routeComplete(conn, route, context);
+        HttpClientConnection conn = getConnection(this.connManager, route);
+        this.connManager.connect(conn, route, 0, context);
+        this.connManager.routeComplete(conn, route, context);
 
         context.setAttribute(HttpCoreContext.HTTP_CONNECTION, conn);
         context.setAttribute(HttpCoreContext.HTTP_TARGET_HOST, target);
@@ -227,20 +219,20 @@ public class TestConnectionManagement ex
         // check that there is no auto-release by default
         try {
             // this should fail quickly, connection has not been released
-            getConnection(mgr, route, 10L, TimeUnit.MILLISECONDS);
+            getConnection(this.connManager, route, 10L, TimeUnit.MILLISECONDS);
             Assert.fail("ConnectionPoolTimeoutException should have been thrown");
         } catch (final ConnectionPoolTimeoutException e) {
             // expected
         }
 
         conn.close();
-        mgr.releaseConnection(conn, null, 100, TimeUnit.MILLISECONDS);
-        conn = getConnection(mgr, route);
+        this.connManager.releaseConnection(conn, null, 100, TimeUnit.MILLISECONDS);
+        conn = getConnection(this.connManager, route);
         Assert.assertFalse("connection should have been closed", conn.isOpen());
 
         // repeat the communication, no need to prepare the request again
-        mgr.connect(conn, route, 0, context);
-        mgr.routeComplete(conn, route, context);
+        this.connManager.connect(conn, route, 0, context);
+        this.connManager.routeComplete(conn, route, context);
 
         context.setAttribute(HttpCoreContext.HTTP_CONNECTION, conn);
         response = exec.execute(request, conn, context);
@@ -253,8 +245,8 @@ public class TestConnectionManagement ex
                      rsplen, data.length);
         // ignore data, but it must be read
 
-        mgr.releaseConnection(conn, null, 100, TimeUnit.MILLISECONDS);
-        conn = getConnection(mgr, route);
+        this.connManager.releaseConnection(conn, null, 100, TimeUnit.MILLISECONDS);
+        conn = getConnection(this.connManager, route);
         Assert.assertTrue("connection should have been open", conn.isOpen());
 
         // repeat the communication, no need to prepare the request again
@@ -269,14 +261,14 @@ public class TestConnectionManagement ex
                      rsplen, data.length);
         // ignore data, but it must be read
 
-        mgr.releaseConnection(conn, null, 100, TimeUnit.MILLISECONDS);
+        this.connManager.releaseConnection(conn, null, 100, TimeUnit.MILLISECONDS);
         Thread.sleep(150);
-        conn = getConnection(mgr, route);
+        conn = getConnection(this.connManager, route);
         Assert.assertTrue("connection should have been closed", !conn.isOpen());
 
         // repeat the communication, no need to prepare the request again
-        mgr.connect(conn, route, 0, context);
-        mgr.routeComplete(conn, route, context);
+        this.connManager.connect(conn, route, 0, context);
+        this.connManager.routeComplete(conn, route, context);
 
         context.setAttribute(HttpCoreContext.HTTP_CONNECTION, conn);
         response = exec.execute(request, conn, context);
@@ -289,88 +281,89 @@ public class TestConnectionManagement ex
                      rsplen, data.length);
         // ignore data, but it must be read
 
-        mgr.shutdown();
+        this.connManager.shutdown();
     }
 
     @Test
     public void testCloseExpiredIdleConnections() throws Exception {
 
-        final PoolingHttpClientConnectionManager mgr = new PoolingHttpClientConnectionManager();
-        mgr.setMaxTotal(1);
+        this.connManager.setMaxTotal(1);
 
-        final HttpHost target = getServerHttp();
+        final HttpHost target = start();
         final HttpRoute route = new HttpRoute(target, null, false);
         final HttpContext context = new BasicHttpContext();
 
-        final HttpClientConnection conn = getConnection(mgr, route);
-        mgr.connect(conn, route, 0, context);
-        mgr.routeComplete(conn, route, context);
+        final HttpClientConnection conn = getConnection(this.connManager, route);
+        this.connManager.connect(conn, route, 0, context);
+        this.connManager.routeComplete(conn, route, context);
 
-        Assert.assertEquals(1, mgr.getTotalStats().getLeased());
-        Assert.assertEquals(1, mgr.getStats(route).getLeased());
+        Assert.assertEquals(1, this.connManager.getTotalStats().getLeased());
+        Assert.assertEquals(1, this.connManager.getStats(route).getLeased());
 
-        mgr.releaseConnection(conn, null, 100, TimeUnit.MILLISECONDS);
+        this.connManager.releaseConnection(conn, null, 100, TimeUnit.MILLISECONDS);
 
         // Released, still active.
-        Assert.assertEquals(1, mgr.getTotalStats().getAvailable());
-        Assert.assertEquals(1, mgr.getStats(route).getAvailable());
+        Assert.assertEquals(1, this.connManager.getTotalStats().getAvailable());
+        Assert.assertEquals(1, this.connManager.getStats(route).getAvailable());
 
-        mgr.closeExpiredConnections();
+        this.connManager.closeExpiredConnections();
 
         // Time has not expired yet.
-        Assert.assertEquals(1, mgr.getTotalStats().getAvailable());
-        Assert.assertEquals(1, mgr.getStats(route).getAvailable());
+        Assert.assertEquals(1, this.connManager.getTotalStats().getAvailable());
+        Assert.assertEquals(1, this.connManager.getStats(route).getAvailable());
 
         Thread.sleep(150);
 
-        mgr.closeExpiredConnections();
+        this.connManager.closeExpiredConnections();
 
         // Time expired now, connections are destroyed.
-        Assert.assertEquals(0, mgr.getTotalStats().getAvailable());
-        Assert.assertEquals(0, mgr.getStats(route).getAvailable());
+        Assert.assertEquals(0, this.connManager.getTotalStats().getAvailable());
+        Assert.assertEquals(0, this.connManager.getStats(route).getAvailable());
 
-        mgr.shutdown();
+        this.connManager.shutdown();
     }
 
     @Test
     public void testCloseExpiredTTLConnections() throws Exception {
 
-        final PoolingHttpClientConnectionManager mgr = new PoolingHttpClientConnectionManager(
+        this.connManager = new PoolingHttpClientConnectionManager(
                 100, TimeUnit.MILLISECONDS);
-        mgr.setMaxTotal(1);
+        this.clientBuilder.setConnectionManager(this.connManager);
 
-        final HttpHost target = getServerHttp();
+        this.connManager.setMaxTotal(1);
+
+        final HttpHost target = start();
         final HttpRoute route = new HttpRoute(target, null, false);
         final HttpContext context = new BasicHttpContext();
 
-        final HttpClientConnection conn = getConnection(mgr, route);
-        mgr.connect(conn, route, 0, context);
-        mgr.routeComplete(conn, route, context);
+        final HttpClientConnection conn = getConnection(this.connManager, route);
+        this.connManager.connect(conn, route, 0, context);
+        this.connManager.routeComplete(conn, route, context);
 
-        Assert.assertEquals(1, mgr.getTotalStats().getLeased());
-        Assert.assertEquals(1, mgr.getStats(route).getLeased());
+        Assert.assertEquals(1, this.connManager.getTotalStats().getLeased());
+        Assert.assertEquals(1, this.connManager.getStats(route).getLeased());
         // Release, let remain idle for forever
-        mgr.releaseConnection(conn, null, -1, TimeUnit.MILLISECONDS);
+        this.connManager.releaseConnection(conn, null, -1, TimeUnit.MILLISECONDS);
 
         // Released, still active.
-        Assert.assertEquals(1, mgr.getTotalStats().getAvailable());
-        Assert.assertEquals(1, mgr.getStats(route).getAvailable());
+        Assert.assertEquals(1, this.connManager.getTotalStats().getAvailable());
+        Assert.assertEquals(1, this.connManager.getStats(route).getAvailable());
 
-        mgr.closeExpiredConnections();
+        this.connManager.closeExpiredConnections();
 
         // Time has not expired yet.
-        Assert.assertEquals(1, mgr.getTotalStats().getAvailable());
-        Assert.assertEquals(1, mgr.getStats(route).getAvailable());
+        Assert.assertEquals(1, this.connManager.getTotalStats().getAvailable());
+        Assert.assertEquals(1, this.connManager.getStats(route).getAvailable());
 
         Thread.sleep(150);
 
-        mgr.closeExpiredConnections();
+        this.connManager.closeExpiredConnections();
 
         // TTL expired now, connections are destroyed.
-        Assert.assertEquals(0, mgr.getTotalStats().getAvailable());
-        Assert.assertEquals(0, mgr.getStats(route).getAvailable());
+        Assert.assertEquals(0, this.connManager.getTotalStats().getAvailable());
+        Assert.assertEquals(0, this.connManager.getStats(route).getAvailable());
 
-        mgr.shutdown();
+        this.connManager.shutdown();
     }
 
     /**
@@ -380,10 +373,9 @@ public class TestConnectionManagement ex
     @Test
     public void testReleaseConnectionOnAbort() throws Exception {
 
-        final PoolingHttpClientConnectionManager mgr = new PoolingHttpClientConnectionManager();
-        mgr.setMaxTotal(1);
+        this.connManager.setMaxTotal(1);
 
-        final HttpHost target = getServerHttp();
+        final HttpHost target = start();
         final HttpRoute route = new HttpRoute(target, null, false);
         final int      rsplen = 8;
         final String      uri = "/random/" + rsplen;
@@ -392,9 +384,9 @@ public class TestConnectionManagement ex
         final HttpRequest request =
             new BasicHttpRequest("GET", uri, HttpVersion.HTTP_1_1);
 
-        HttpClientConnection conn = getConnection(mgr, route);
-        mgr.connect(conn, route, 0, context);
-        mgr.routeComplete(conn, route, context);
+        HttpClientConnection conn = getConnection(this.connManager, route);
+        this.connManager.connect(conn, route, 0, context);
+        this.connManager.routeComplete(conn, route, context);
 
         context.setAttribute(HttpCoreContext.HTTP_CONNECTION, conn);
         context.setAttribute(HttpCoreContext.HTTP_TARGET_HOST, target);
@@ -413,7 +405,7 @@ public class TestConnectionManagement ex
         // check that there are no connections available
         try {
             // this should fail quickly, connection has not been released
-            getConnection(mgr, route, 100L, TimeUnit.MILLISECONDS);
+            getConnection(this.connManager, route, 100L, TimeUnit.MILLISECONDS);
             Assert.fail("ConnectionPoolTimeoutException should have been thrown");
         } catch (final ConnectionPoolTimeoutException e) {
             // expected
@@ -422,14 +414,14 @@ public class TestConnectionManagement ex
         // abort the connection
         Assert.assertTrue(conn instanceof HttpClientConnection);
         conn.shutdown();
-        mgr.releaseConnection(conn, null, -1, null);
+        this.connManager.releaseConnection(conn, null, -1, null);
 
         // the connection is expected to be released back to the manager
-        conn = getConnection(mgr, route, 5L, TimeUnit.SECONDS);
+        conn = getConnection(this.connManager, route, 5L, TimeUnit.SECONDS);
         Assert.assertFalse("connection should have been closed", conn.isOpen());
 
-        mgr.releaseConnection(conn, null, -1, null);
-        mgr.shutdown();
+        this.connManager.releaseConnection(conn, null, -1, null);
+        this.connManager.shutdown();
     }
 
     @Test
@@ -441,14 +433,16 @@ public class TestConnectionManagement ex
             .register("http", stallingSocketFactory)
             .build();
 
-        final PoolingHttpClientConnectionManager mgr = new PoolingHttpClientConnectionManager(registry);
-        mgr.setMaxTotal(1);
+        this.connManager = new PoolingHttpClientConnectionManager(registry);
+        this.clientBuilder.setConnectionManager(this.connManager);
+
+        this.connManager.setMaxTotal(1);
 
-        final HttpHost target = getServerHttp();
+        final HttpHost target = start();
         final HttpRoute route = new HttpRoute(target, null, false);
         final HttpContext context = new BasicHttpContext();
 
-        final HttpClientConnection conn = getConnection(mgr, route);
+        final HttpClientConnection conn = getConnection(this.connManager, route);
 
         final AtomicReference<Throwable> throwRef = new AtomicReference<Throwable>();
         final Thread abortingThread = new Thread(new Runnable() {
@@ -457,7 +451,7 @@ public class TestConnectionManagement ex
                 try {
                     stallingSocketFactory.waitForState();
                     conn.shutdown();
-                    mgr.releaseConnection(conn, null, -1, null);
+                    connManager.releaseConnection(conn, null, -1, null);
                     connectLatch.countDown();
                 } catch (final Throwable e) {
                     throwRef.set(e);
@@ -467,8 +461,8 @@ public class TestConnectionManagement ex
         abortingThread.start();
 
         try {
-            mgr.connect(conn, route, 0, context);
-            mgr.routeComplete(conn, route, context);
+            this.connManager.connect(conn, route, 0, context);
+            this.connManager.routeComplete(conn, route, context);
             Assert.fail("expected SocketException");
         } catch(final SocketException expected) {}
 
@@ -478,14 +472,13 @@ public class TestConnectionManagement ex
         }
 
         Assert.assertFalse(conn.isOpen());
-        Assert.assertEquals(0, localServer.getAcceptedConnectionCount());
 
         // the connection is expected to be released back to the manager
-        final HttpClientConnection conn2 = getConnection(mgr, route, 5L, TimeUnit.SECONDS);
+        final HttpClientConnection conn2 = getConnection(this.connManager, route, 5L, TimeUnit.SECONDS);
         Assert.assertFalse("connection should have been closed", conn2.isOpen());
 
-        mgr.releaseConnection(conn2, null, -1, null);
-        mgr.shutdown();
+        this.connManager.releaseConnection(conn2, null, -1, null);
+        this.connManager.shutdown();
     }
 
     @Test
@@ -497,14 +490,16 @@ public class TestConnectionManagement ex
             .register("http", stallingSocketFactory)
             .build();
 
-        final PoolingHttpClientConnectionManager mgr = new PoolingHttpClientConnectionManager(registry);
-        mgr.setMaxTotal(1);
+        this.connManager = new PoolingHttpClientConnectionManager(registry);
+        this.clientBuilder.setConnectionManager(this.connManager);
 
-        final HttpHost target = getServerHttp();
+        this.connManager.setMaxTotal(1);
+
+        final HttpHost target = start();
         final HttpRoute route = new HttpRoute(target, null, false);
         final HttpContext context = new BasicHttpContext();
 
-        final HttpClientConnection conn = getConnection(mgr, route);
+        final HttpClientConnection conn = getConnection(this.connManager, route);
 
         final AtomicReference<Throwable> throwRef = new AtomicReference<Throwable>();
         final Thread abortingThread = new Thread(new Runnable() {
@@ -513,7 +508,7 @@ public class TestConnectionManagement ex
                 try {
                     stallingSocketFactory.waitForState();
                     conn.shutdown();
-                    mgr.releaseConnection(conn, null, -1, null);
+                    connManager.releaseConnection(conn, null, -1, null);
                     connectLatch.countDown();
                 } catch (final Throwable e) {
                     throwRef.set(e);
@@ -523,8 +518,8 @@ public class TestConnectionManagement ex
         abortingThread.start();
 
         try {
-            mgr.connect(conn, route, 0, context);
-            mgr.routeComplete(conn, route, context);
+            this.connManager.connect(conn, route, 0, context);
+            this.connManager.routeComplete(conn, route, context);
             Assert.fail("IOException expected");
         } catch(final IOException expected) {
         }
@@ -535,14 +530,13 @@ public class TestConnectionManagement ex
         }
 
         Assert.assertFalse(conn.isOpen());
-        Assert.assertEquals(0, localServer.getAcceptedConnectionCount());
 
         // the connection is expected to be released back to the manager
-        final HttpClientConnection conn2 = getConnection(mgr, route, 5L, TimeUnit.SECONDS);
+        final HttpClientConnection conn2 = getConnection(this.connManager, route, 5L, TimeUnit.SECONDS);
         Assert.assertFalse("connection should have been closed", conn2.isOpen());
 
-        mgr.releaseConnection(conn2, null, -1, null);
-        mgr.shutdown();
+        this.connManager.releaseConnection(conn2, null, -1, null);
+        this.connManager.shutdown();
     }
 
     @Test
@@ -554,14 +548,16 @@ public class TestConnectionManagement ex
             .register("http", stallingSocketFactory)
             .build();
 
-        final PoolingHttpClientConnectionManager mgr = new PoolingHttpClientConnectionManager(registry);
-        mgr.setMaxTotal(1);
+        this.connManager = new PoolingHttpClientConnectionManager(registry);
+        this.clientBuilder.setConnectionManager(this.connManager);
+
+        this.connManager.setMaxTotal(1);
 
-        final HttpHost target = getServerHttp();
+        final HttpHost target = start();
         final HttpRoute route = new HttpRoute(target, null, false);
         final HttpContext context = new BasicHttpContext();
 
-        final HttpClientConnection conn = getConnection(mgr, route);
+        final HttpClientConnection conn = getConnection(this.connManager, route);
 
         final AtomicReference<Throwable> throwRef = new AtomicReference<Throwable>();
         final Thread abortingThread = new Thread(new Runnable() {
@@ -570,7 +566,7 @@ public class TestConnectionManagement ex
                 try {
                     stallingSocketFactory.waitForState();
                     conn.shutdown();
-                    mgr.releaseConnection(conn, null, -1, null);
+                    connManager.releaseConnection(conn, null, -1, null);
                     connectLatch.countDown();
                 } catch (final Throwable e) {
                     throwRef.set(e);
@@ -580,8 +576,8 @@ public class TestConnectionManagement ex
         abortingThread.start();
 
         try {
-            mgr.connect(conn, route, 0, context);
-            mgr.routeComplete(conn, route, context);
+            this.connManager.connect(conn, route, 0, context);
+            this.connManager.routeComplete(conn, route, context);
             Assert.fail("IOException expected");
         } catch(final IOException expected) {
         }
@@ -592,22 +588,13 @@ public class TestConnectionManagement ex
         }
 
         Assert.assertFalse(conn.isOpen());
-        // Give the server a bit of time to accept the connection, but
-        // ensure that it can accept it.
-        for(int i = 0; i < 10; i++) {
-            if(localServer.getAcceptedConnectionCount() == 1) {
-                break;
-            }
-            Thread.sleep(100);
-        }
-        Assert.assertEquals(1, localServer.getAcceptedConnectionCount());
 
         // the connection is expected to be released back to the manager
-        final HttpClientConnection conn2 = getConnection(mgr, route, 5L, TimeUnit.SECONDS);
+        final HttpClientConnection conn2 = getConnection(this.connManager, route, 5L, TimeUnit.SECONDS);
         Assert.assertFalse("connection should have been closed", conn2.isOpen());
 
-        mgr.releaseConnection(conn2, null, -1, null);
-        mgr.shutdown();
+        this.connManager.releaseConnection(conn2, null, -1, null);
+        this.connManager.shutdown();
     }
 
     static class LatchSupport {

Modified: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestConnectionReuse.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestConnectionReuse.java?rev=1603443&r1=1603442&r2=1603443&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestConnectionReuse.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestConnectionReuse.java Wed Jun 18 13:06:43 2014
@@ -28,7 +28,6 @@
 package org.apache.http.impl.client.integration;
 
 import java.io.IOException;
-import java.net.InetSocketAddress;
 import java.net.URI;
 
 import org.apache.http.Header;
@@ -38,9 +37,7 @@ import org.apache.http.HttpResponse;
 import org.apache.http.HttpResponseInterceptor;
 import org.apache.http.client.HttpClient;
 import org.apache.http.client.methods.HttpGet;
-import org.apache.http.impl.client.HttpClients;
-import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
-import org.apache.http.localserver.LocalTestServer;
+import org.apache.http.localserver.LocalServerTestBase;
 import org.apache.http.localserver.RandomHandler;
 import org.apache.http.protocol.HTTP;
 import org.apache.http.protocol.HttpContext;
@@ -51,46 +48,31 @@ import org.apache.http.protocol.Response
 import org.apache.http.protocol.ResponseDate;
 import org.apache.http.protocol.ResponseServer;
 import org.apache.http.util.EntityUtils;
-import org.junit.After;
 import org.junit.Assert;
 import org.junit.Test;
 
-public class TestConnectionReuse {
-
-    protected LocalTestServer localServer;
-
-    @After
-    public void tearDown() throws Exception {
-        if (this.localServer != null) {
-            this.localServer.stop();
-        }
-    }
+public class TestConnectionReuse extends LocalServerTestBase {
 
     @Test
     public void testReuseOfPersistentConnections() throws Exception {
         final HttpProcessor httpproc = HttpProcessorBuilder.create()
             .add(new ResponseDate())
-            .add(new ResponseServer())
+            .add(new ResponseServer(LocalServerTestBase.ORIGIN))
             .add(new ResponseContent())
             .add(new ResponseConnControl()).build();
 
-        this.localServer = new LocalTestServer(httpproc, null);
-        this.localServer.register("/random/*", new RandomHandler());
-        this.localServer.start();
-
-        final InetSocketAddress saddress = this.localServer.getServiceAddress();
-
-        final PoolingHttpClientConnectionManager mgr = new PoolingHttpClientConnectionManager();
-        mgr.setMaxTotal(5);
-        mgr.setDefaultMaxPerRoute(5);
+        this.serverBootstrap.setHttpProcessor(httpproc)
+                .registerHandler("/random/*", new RandomHandler());
 
-        final HttpClient client = HttpClients.custom().setConnectionManager(mgr).build();
-        final HttpHost target = new HttpHost(saddress.getHostName(), saddress.getPort(), "http");
+        this.connManager.setMaxTotal(5);
+        this.connManager.setDefaultMaxPerRoute(5);
+
+        final HttpHost target = start();
 
         final WorkerThread[] workers = new WorkerThread[10];
         for (int i = 0; i < workers.length; i++) {
             workers[i] = new WorkerThread(
-                    client,
+                    this.httpclient,
                     target,
                     new URI("/random/2000"),
                     10, false);
@@ -108,9 +90,7 @@ public class TestConnectionReuse {
         }
 
         // Expect some connection in the pool
-        Assert.assertTrue(mgr.getTotalStats().getAvailable() > 0);
-
-        mgr.shutdown();
+        Assert.assertTrue(this.connManager.getTotalStats().getAvailable() > 0);
     }
 
     private static class AlwaysCloseConn implements HttpResponseInterceptor {
@@ -128,28 +108,22 @@ public class TestConnectionReuse {
     public void testReuseOfClosedConnections() throws Exception {
         final HttpProcessor httpproc = HttpProcessorBuilder.create()
             .add(new ResponseDate())
-            .add(new ResponseServer())
+            .add(new ResponseServer(LocalServerTestBase.ORIGIN))
             .add(new ResponseContent())
             .add(new AlwaysCloseConn()).build();
 
-        this.localServer = new LocalTestServer(httpproc, null);
-        this.localServer.register("/random/*", new RandomHandler());
-        this.localServer.start();
-
-        final InetSocketAddress saddress = this.localServer.getServiceAddress();
-
-        final PoolingHttpClientConnectionManager mgr = new PoolingHttpClientConnectionManager();
-        mgr.setMaxTotal(5);
-        mgr.setDefaultMaxPerRoute(5);
+        this.serverBootstrap.setHttpProcessor(httpproc)
+                .registerHandler("/random/*", new RandomHandler());
 
-        final HttpClient client = HttpClients.custom().setConnectionManager(mgr).build();
+        this.connManager.setMaxTotal(5);
+        this.connManager.setDefaultMaxPerRoute(5);
 
-        final HttpHost target = new HttpHost(saddress.getHostName(), saddress.getPort(), "http");
+        final HttpHost target = start();
 
         final WorkerThread[] workers = new WorkerThread[10];
         for (int i = 0; i < workers.length; i++) {
             workers[i] = new WorkerThread(
-                    client,
+                    this.httpclient,
                     target,
                     new URI("/random/2000"),
                     10, false);
@@ -167,37 +141,29 @@ public class TestConnectionReuse {
         }
 
         // Expect zero connections in the pool
-        Assert.assertEquals(0, mgr.getTotalStats().getAvailable());
-
-        mgr.shutdown();
+        Assert.assertEquals(0, this.connManager.getTotalStats().getAvailable());
     }
 
     @Test
     public void testReuseOfAbortedConnections() throws Exception {
         final HttpProcessor httpproc = HttpProcessorBuilder.create()
             .add(new ResponseDate())
-            .add(new ResponseServer())
+            .add(new ResponseServer(LocalServerTestBase.ORIGIN))
             .add(new ResponseContent())
             .add(new ResponseConnControl()).build();
 
-        this.localServer = new LocalTestServer(httpproc, null);
-        this.localServer.register("/random/*", new RandomHandler());
-        this.localServer.start();
-
-        final InetSocketAddress saddress = this.localServer.getServiceAddress();
+        this.serverBootstrap.setHttpProcessor(httpproc)
+                .registerHandler("/random/*", new RandomHandler());
 
-        final PoolingHttpClientConnectionManager mgr = new PoolingHttpClientConnectionManager();
-        mgr.setMaxTotal(5);
-        mgr.setDefaultMaxPerRoute(5);
+        this.connManager.setMaxTotal(5);
+        this.connManager.setDefaultMaxPerRoute(5);
 
-        final HttpClient client = HttpClients.custom().setConnectionManager(mgr).build();
-
-        final HttpHost target = new HttpHost(saddress.getHostName(), saddress.getPort(), "http");
+        final HttpHost target = start();
 
         final WorkerThread[] workers = new WorkerThread[10];
         for (int i = 0; i < workers.length; i++) {
             workers[i] = new WorkerThread(
-                    client,
+                    this.httpclient,
                     target,
                     new URI("/random/2000"),
                     10, true);
@@ -215,65 +181,50 @@ public class TestConnectionReuse {
         }
 
         // Expect zero connections in the pool
-        Assert.assertEquals(0, mgr.getTotalStats().getAvailable());
-
-        mgr.shutdown();
+        Assert.assertEquals(0, this.connManager.getTotalStats().getAvailable());
     }
 
     @Test
     public void testKeepAliveHeaderRespected() throws Exception {
         final HttpProcessor httpproc = HttpProcessorBuilder.create()
             .add(new ResponseDate())
-            .add(new ResponseServer())
+                .add(new ResponseServer(LocalServerTestBase.ORIGIN))
             .add(new ResponseContent())
             .add(new ResponseConnControl())
             .add(new ResponseKeepAlive()).build();
 
-        this.localServer = new LocalTestServer(httpproc, null);
-        this.localServer.register("/random/*", new RandomHandler());
-        this.localServer.start();
+        this.serverBootstrap.setHttpProcessor(httpproc)
+                .registerHandler("/random/*", new RandomHandler());
 
-        final InetSocketAddress saddress = this.localServer.getServiceAddress();
+        this.connManager.setMaxTotal(1);
+        this.connManager.setDefaultMaxPerRoute(1);
 
-        final PoolingHttpClientConnectionManager mgr = new PoolingHttpClientConnectionManager();
-        mgr.setMaxTotal(1);
-        mgr.setDefaultMaxPerRoute(1);
+        final HttpHost target = start();
 
-        final HttpClient client = HttpClients.custom().setConnectionManager(mgr).build();
-
-        final HttpHost target = new HttpHost(saddress.getHostName(), saddress.getPort(), "http");
-
-        HttpResponse response = client.execute(target, new HttpGet("/random/2000"));
+        HttpResponse response = this.httpclient.execute(target, new HttpGet("/random/2000"));
         EntityUtils.consume(response.getEntity());
 
-        Assert.assertEquals(1, mgr.getTotalStats().getAvailable());
-        Assert.assertEquals(1, localServer.getAcceptedConnectionCount());
+        Assert.assertEquals(1, this.connManager.getTotalStats().getAvailable());
 
-        response = client.execute(target, new HttpGet("/random/2000"));
+        response = this.httpclient.execute(target, new HttpGet("/random/2000"));
         EntityUtils.consume(response.getEntity());
 
-        Assert.assertEquals(1, mgr.getTotalStats().getAvailable());
-        Assert.assertEquals(1, localServer.getAcceptedConnectionCount());
+        Assert.assertEquals(1, this.connManager.getTotalStats().getAvailable());
 
         // Now sleep for 1.1 seconds and let the timeout do its work
         Thread.sleep(1100);
-        response = client.execute(target, new HttpGet("/random/2000"));
+        response = this.httpclient.execute(target, new HttpGet("/random/2000"));
         EntityUtils.consume(response.getEntity());
 
-        Assert.assertEquals(1, mgr.getTotalStats().getAvailable());
-        Assert.assertEquals(2, localServer.getAcceptedConnectionCount());
+        Assert.assertEquals(1, this.connManager.getTotalStats().getAvailable());
 
         // Do another request just under the 1 second limit & make
         // sure we reuse that connection.
         Thread.sleep(500);
-        response = client.execute(target, new HttpGet("/random/2000"));
+        response = this.httpclient.execute(target, new HttpGet("/random/2000"));
         EntityUtils.consume(response.getEntity());
 
-        Assert.assertEquals(1, mgr.getTotalStats().getAvailable());
-        Assert.assertEquals(2, localServer.getAcceptedConnectionCount());
-
-
-        mgr.shutdown();
+        Assert.assertEquals(1, this.connManager.getTotalStats().getAvailable());
     }
 
     private static class WorkerThread extends Thread {

Modified: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestContentCodings.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestContentCodings.java?rev=1603443&r1=1603442&r2=1603443&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestContentCodings.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestContentCodings.java Wed Jun 18 13:06:43 2014
@@ -43,6 +43,7 @@ import org.apache.http.Consts;
 import org.apache.http.Header;
 import org.apache.http.HeaderElement;
 import org.apache.http.HttpException;
+import org.apache.http.HttpHost;
 import org.apache.http.HttpRequest;
 import org.apache.http.HttpResponse;
 import org.apache.http.HttpStatus;
@@ -51,13 +52,11 @@ import org.apache.http.client.methods.Ht
 import org.apache.http.entity.InputStreamEntity;
 import org.apache.http.entity.StringEntity;
 import org.apache.http.impl.client.BasicResponseHandler;
-import org.apache.http.impl.client.HttpClients;
-import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
+import org.apache.http.localserver.LocalServerTestBase;
 import org.apache.http.protocol.HttpContext;
 import org.apache.http.protocol.HttpRequestHandler;
 import org.apache.http.util.EntityUtils;
 import org.junit.Assert;
-import org.junit.Before;
 import org.junit.Test;
 
 /**
@@ -65,12 +64,7 @@ import org.junit.Test;
  * require no intervention from the user of HttpClient, but we still want to let clients do their
  * own thing if they so wish.
  */
-public class TestContentCodings extends IntegrationTestBase {
-
-    @Before
-    public void setUp() throws Exception {
-        startServer();
-    }
+public class TestContentCodings extends LocalServerTestBase {
 
     /**
      * Test for when we don't get an entity back; e.g. for a 204 or 304 response; nothing blows
@@ -81,7 +75,7 @@ public class TestContentCodings extends 
      */
     @Test
     public void testResponseWithNoContent() throws Exception {
-        this.localServer.register("*", new HttpRequestHandler() {
+        this.serverBootstrap.registerHandler("*", new HttpRequestHandler() {
 
             /**
              * {@inheritDoc}
@@ -95,9 +89,10 @@ public class TestContentCodings extends 
             }
         });
 
-        this.httpclient = HttpClients.custom().build();
+        final HttpHost target = start();
+
         final HttpGet request = new HttpGet("/some-resource");
-        final HttpResponse response = this.httpclient.execute(getServerHttp(), request);
+        final HttpResponse response = this.httpclient.execute(target, request);
         Assert.assertEquals(HttpStatus.SC_NO_CONTENT, response.getStatusLine().getStatusCode());
         Assert.assertNull(response.getEntity());
     }
@@ -112,12 +107,12 @@ public class TestContentCodings extends 
     public void testDeflateSupportForServerReturningRfc1950Stream() throws Exception {
         final String entityText = "Hello, this is some plain text coming back.";
 
-        this.localServer.register("*", createDeflateEncodingRequestHandler(entityText, false));
+        this.serverBootstrap.registerHandler("*", createDeflateEncodingRequestHandler(entityText, false));
 
-        this.httpclient = HttpClients.custom().build();
+        final HttpHost target = start();
 
         final HttpGet request = new HttpGet("/some-resource");
-        final HttpResponse response = this.httpclient.execute(getServerHttp(), request);
+        final HttpResponse response = this.httpclient.execute(target, request);
         Assert.assertEquals("The entity text is correctly transported", entityText,
                 EntityUtils.toString(response.getEntity()));
     }
@@ -132,12 +127,12 @@ public class TestContentCodings extends 
     public void testDeflateSupportForServerReturningRfc1951Stream() throws Exception {
         final String entityText = "Hello, this is some plain text coming back.";
 
-        this.localServer.register("*", createDeflateEncodingRequestHandler(entityText, true));
+        this.serverBootstrap.registerHandler("*", createDeflateEncodingRequestHandler(entityText, true));
 
-        this.httpclient = HttpClients.custom().build();
+        final HttpHost target = start();
 
         final HttpGet request = new HttpGet("/some-resource");
-        final HttpResponse response = this.httpclient.execute(getServerHttp(), request);
+        final HttpResponse response = this.httpclient.execute(target, request);
         Assert.assertEquals("The entity text is correctly transported", entityText,
                 EntityUtils.toString(response.getEntity()));
     }
@@ -151,12 +146,12 @@ public class TestContentCodings extends 
     public void testGzipSupport() throws Exception {
         final String entityText = "Hello, this is some plain text coming back.";
 
-        this.localServer.register("*", createGzipEncodingRequestHandler(entityText));
+        this.serverBootstrap.registerHandler("*", createGzipEncodingRequestHandler(entityText));
 
-        this.httpclient = HttpClients.custom().build();
+        final HttpHost target = start();
 
         final HttpGet request = new HttpGet("/some-resource");
-        final HttpResponse response = this.httpclient.execute(getServerHttp(), request);
+        final HttpResponse response = this.httpclient.execute(target, request);
         Assert.assertEquals("The entity text is correctly transported", entityText,
                 EntityUtils.toString(response.getEntity()));
     }
@@ -171,7 +166,7 @@ public class TestContentCodings extends 
     public void testThreadSafetyOfContentCodings() throws Exception {
         final String entityText = "Hello, this is some plain text coming back.";
 
-        this.localServer.register("*", createGzipEncodingRequestHandler(entityText));
+        this.serverBootstrap.registerHandler("*", createGzipEncodingRequestHandler(entityText));
 
         /*
          * Create a load of workers which will access the resource. Half will use the default
@@ -179,10 +174,9 @@ public class TestContentCodings extends 
          */
         final int clients = 100;
 
-        final PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager();
-        cm.setMaxTotal(clients);
+        this.connManager.setMaxTotal(clients);
 
-        this.httpclient = HttpClients.custom().setConnectionManager(cm).build();
+        final HttpHost target = start();
 
         final ExecutorService executor = Executors.newFixedThreadPool(clients);
 
@@ -192,7 +186,7 @@ public class TestContentCodings extends 
         final List<WorkerTask> workers = new ArrayList<WorkerTask>();
 
         for (int i = 0; i < clients; ++i) {
-            workers.add(new WorkerTask(this.httpclient, i % 2 == 0, startGate, endGate));
+            workers.add(new WorkerTask(this.httpclient, target, i % 2 == 0, startGate, endGate));
         }
 
         for (final WorkerTask workerTask : workers) {
@@ -218,12 +212,12 @@ public class TestContentCodings extends 
     public void testHttpEntityWriteToForGzip() throws Exception {
         final String entityText = "Hello, this is some plain text coming back.";
 
-        this.localServer.register("*", createGzipEncodingRequestHandler(entityText));
+        this.serverBootstrap.registerHandler("*", createGzipEncodingRequestHandler(entityText));
 
-        this.httpclient = HttpClients.custom().build();
+        final HttpHost target = start();
 
         final HttpGet request = new HttpGet("/some-resource");
-        final HttpResponse response = this.httpclient.execute(getServerHttp(), request);
+        final HttpResponse response = this.httpclient.execute(target, request);
         final ByteArrayOutputStream out = new ByteArrayOutputStream();
 
         response.getEntity().writeTo(out);
@@ -235,12 +229,12 @@ public class TestContentCodings extends 
     public void testHttpEntityWriteToForDeflate() throws Exception {
         final String entityText = "Hello, this is some plain text coming back.";
 
-        this.localServer.register("*", createDeflateEncodingRequestHandler(entityText, true));
+        this.serverBootstrap.registerHandler("*", createDeflateEncodingRequestHandler(entityText, true));
 
-        this.httpclient = HttpClients.custom().build();
+        final HttpHost target = start();
 
         final HttpGet request = new HttpGet("/some-resource");
-        final HttpResponse response = this.httpclient.execute(getServerHttp(), request);
+        final HttpResponse response = this.httpclient.execute(target, request);
         final ByteArrayOutputStream out = new ByteArrayOutputStream();
 
         response.getEntity().writeTo(out);
@@ -252,12 +246,12 @@ public class TestContentCodings extends 
     public void gzipResponsesWorkWithBasicResponseHandler() throws Exception {
         final String entityText = "Hello, this is some plain text coming back.";
 
-        this.localServer.register("*", createGzipEncodingRequestHandler(entityText));
+        this.serverBootstrap.registerHandler("*", createGzipEncodingRequestHandler(entityText));
 
-        this.httpclient = HttpClients.custom().build();
+        final HttpHost target = start();
 
         final HttpGet request = new HttpGet("/some-resource");
-        final String response = this.httpclient.execute(getServerHttp(), request, new BasicResponseHandler());
+        final String response = this.httpclient.execute(target, request, new BasicResponseHandler());
         Assert.assertEquals("The entity text is correctly transported", entityText, response);
     }
 
@@ -265,12 +259,12 @@ public class TestContentCodings extends 
     public void deflateResponsesWorkWithBasicResponseHandler() throws Exception {
         final String entityText = "Hello, this is some plain text coming back.";
 
-        this.localServer.register("*", createDeflateEncodingRequestHandler(entityText, false));
+        this.serverBootstrap.registerHandler("*", createDeflateEncodingRequestHandler(entityText, false));
 
-        this.httpclient = HttpClients.custom().build();
+        final HttpHost target = start();
 
         final HttpGet request = new HttpGet("/some-resource");
-        final String response = this.httpclient.execute(getServerHttp(), request, new BasicResponseHandler());
+        final String response = this.httpclient.execute(target, request, new BasicResponseHandler());
         Assert.assertEquals("The entity text is correctly transported", entityText, response);
     }
 
@@ -400,38 +394,18 @@ public class TestContentCodings extends 
      */
     class WorkerTask implements Runnable {
 
-        /**
-         * The {@link HttpClient} used to make requests.
-         */
         private final HttpClient client;
-
-        /**
-         * The {@link HttpRequest} to be executed.
-         */
+        private final HttpHost target;
         private final HttpGet request;
-
-        /**
-         * Flag indicating if there were failures.
-         */
-        private boolean failed = false;
-
-        /**
-         * The latch that this runnable instance should wait on.
-         */
         private final CountDownLatch startGate;
-
-        /**
-         * The latch that this runnable instance should countdown on when the runnable is finished.
-         */
         private final CountDownLatch endGate;
 
-        /**
-         * The text returned from the HTTP server.
-         */
+        private boolean failed = false;
         private String text;
 
-        WorkerTask(final HttpClient client, final boolean identity, final CountDownLatch startGate, final CountDownLatch endGate) {
+        WorkerTask(final HttpClient client, final HttpHost target, final boolean identity, final CountDownLatch startGate, final CountDownLatch endGate) {
             this.client = client;
+            this.target = target;
             this.request = new HttpGet("/some-resource");
             if (identity) {
                 request.addHeader("Accept-Encoding", "identity");
@@ -457,7 +431,7 @@ public class TestContentCodings extends 
             try {
                 startGate.await();
                 try {
-                    final HttpResponse response = client.execute(TestContentCodings.this.getServerHttp(), request);
+                    final HttpResponse response = client.execute(target, request);
                     text = EntityUtils.toString(response.getEntity());
                 } catch (final Exception e) {
                     failed = true;

Modified: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestCookie2Support.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestCookie2Support.java?rev=1603443&r1=1603442&r2=1603443&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestCookie2Support.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestCookie2Support.java Wed Jun 18 13:06:43 2014
@@ -32,6 +32,7 @@ import java.util.List;
 import org.apache.http.Header;
 import org.apache.http.HttpEntity;
 import org.apache.http.HttpException;
+import org.apache.http.HttpHost;
 import org.apache.http.HttpRequest;
 import org.apache.http.HttpResponse;
 import org.apache.http.HttpStatus;
@@ -44,25 +45,18 @@ import org.apache.http.cookie.SM;
 import org.apache.http.cookie.SetCookie2;
 import org.apache.http.entity.StringEntity;
 import org.apache.http.impl.client.BasicCookieStore;
-import org.apache.http.impl.client.HttpClients;
+import org.apache.http.localserver.LocalServerTestBase;
 import org.apache.http.message.BasicHeader;
 import org.apache.http.protocol.HttpContext;
 import org.apache.http.protocol.HttpRequestHandler;
 import org.apache.http.util.EntityUtils;
 import org.junit.Assert;
-import org.junit.Before;
 import org.junit.Test;
 
 /**
  * Cookie2 support tests.
  */
-public class TestCookie2Support extends IntegrationTestBase {
-
-    @Before
-    public void setUp() throws Exception {
-        startServer();
-        this.httpclient = HttpClients.createDefault();
-    }
+public class TestCookie2Support extends LocalServerTestBase {
 
     private static class CookieVer0Service implements HttpRequestHandler {
 
@@ -82,7 +76,9 @@ public class TestCookie2Support extends 
 
     @Test
     public void testCookieVersionSupportHeader1() throws Exception {
-        this.localServer.register("*", new CookieVer0Service());
+        this.serverBootstrap.registerHandler("*", new CookieVer0Service());
+
+        final HttpHost target = start();
 
         final CookieStore cookieStore = new BasicCookieStore();
         final HttpClientContext context = HttpClientContext.create();
@@ -90,7 +86,7 @@ public class TestCookie2Support extends 
 
         final HttpGet httpget = new HttpGet("/test/");
 
-        final HttpResponse response1 = this.httpclient.execute(getServerHttp(), httpget, context);
+        final HttpResponse response1 = this.httpclient.execute(target, httpget, context);
         final HttpEntity e1 = response1.getEntity();
         EntityUtils.consume(e1);
 
@@ -98,7 +94,7 @@ public class TestCookie2Support extends 
         Assert.assertNotNull(cookies);
         Assert.assertEquals(1, cookies.size());
 
-        final HttpResponse response2 = this.httpclient.execute(getServerHttp(), httpget, context);
+        final HttpResponse response2 = this.httpclient.execute(target, httpget, context);
         final HttpEntity e2 = response2.getEntity();
         EntityUtils.consume(e2);
 
@@ -128,7 +124,9 @@ public class TestCookie2Support extends 
 
     @Test
     public void testCookieVersionSupportHeader2() throws Exception {
-        this.localServer.register("*", new CookieVer1Service());
+        this.serverBootstrap.registerHandler("*", new CookieVer1Service());
+
+        final HttpHost target = start();
 
         final CookieStore cookieStore = new BasicCookieStore();
         final HttpClientContext context = HttpClientContext.create();
@@ -136,7 +134,7 @@ public class TestCookie2Support extends 
 
         final HttpGet httpget = new HttpGet("/test/");
 
-        final HttpResponse response1 = this.httpclient.execute(getServerHttp(), httpget, context);
+        final HttpResponse response1 = this.httpclient.execute(target, httpget, context);
         final HttpEntity e1 = response1.getEntity();
         EntityUtils.consume(e1);
 
@@ -144,7 +142,7 @@ public class TestCookie2Support extends 
         Assert.assertNotNull(cookies);
         Assert.assertEquals(2, cookies.size());
 
-        final HttpResponse response2 = this.httpclient.execute(getServerHttp(), httpget, context);
+        final HttpResponse response2 = this.httpclient.execute(target, httpget, context);
         final HttpEntity e2 = response2.getEntity();
         EntityUtils.consume(e2);
 
@@ -173,7 +171,9 @@ public class TestCookie2Support extends 
 
     @Test
     public void testCookieVersionSupportHeader3() throws Exception {
-        this.localServer.register("*", new CookieVer2Service());
+        this.serverBootstrap.registerHandler("*", new CookieVer2Service());
+
+        final HttpHost target = start();
 
         final CookieStore cookieStore = new BasicCookieStore();
         final HttpClientContext context = HttpClientContext.create();
@@ -181,7 +181,7 @@ public class TestCookie2Support extends 
 
         final HttpGet httpget = new HttpGet("/test/");
 
-        final HttpResponse response1 = this.httpclient.execute(getServerHttp(), httpget, context);
+        final HttpResponse response1 = this.httpclient.execute(target, httpget, context);
         final HttpEntity e1 = response1.getEntity();
         EntityUtils.consume(e1);
 
@@ -189,7 +189,7 @@ public class TestCookie2Support extends 
         Assert.assertNotNull(cookies);
         Assert.assertEquals(1, cookies.size());
 
-        final HttpResponse response2 = this.httpclient.execute(getServerHttp(), httpget, context);
+        final HttpResponse response2 = this.httpclient.execute(target, httpget, context);
         final HttpEntity e2 = response2.getEntity();
         EntityUtils.consume(e2);
 
@@ -219,7 +219,9 @@ public class TestCookie2Support extends 
 
     @Test
     public void testSetCookieVersionMix() throws Exception {
-        this.localServer.register("*", new SetCookieVersionMixService());
+        this.serverBootstrap.registerHandler("*", new SetCookieVersionMixService());
+
+        final HttpHost target = start();
 
         final CookieStore cookieStore = new BasicCookieStore();
         final HttpClientContext context = HttpClientContext.create();
@@ -227,7 +229,7 @@ public class TestCookie2Support extends 
 
         final HttpGet httpget = new HttpGet("/test/");
 
-        final HttpResponse response1 = this.httpclient.execute(getServerHttp(), httpget, context);
+        final HttpResponse response1 = this.httpclient.execute(target, httpget, context);
         final HttpEntity e1 = response1.getEntity();
         EntityUtils.consume(e1);
 

Modified: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestCookieVirtualHost.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestCookieVirtualHost.java?rev=1603443&r1=1603442&r2=1603443&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestCookieVirtualHost.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestCookieVirtualHost.java Wed Jun 18 13:06:43 2014
@@ -32,6 +32,7 @@ import java.util.List;
 
 import org.apache.http.HttpEntity;
 import org.apache.http.HttpException;
+import org.apache.http.HttpHost;
 import org.apache.http.HttpRequest;
 import org.apache.http.HttpResponse;
 import org.apache.http.HttpStatus;
@@ -41,31 +42,22 @@ import org.apache.http.client.methods.Ht
 import org.apache.http.client.protocol.HttpClientContext;
 import org.apache.http.cookie.Cookie;
 import org.apache.http.impl.client.BasicCookieStore;
-import org.apache.http.impl.client.HttpClients;
-import org.apache.http.localserver.LocalTestServer;
+import org.apache.http.localserver.LocalServerTestBase;
 import org.apache.http.message.BasicHeader;
 import org.apache.http.protocol.HttpContext;
 import org.apache.http.protocol.HttpRequestHandler;
 import org.apache.http.util.EntityUtils;
 import org.junit.Assert;
-import org.junit.Before;
 import org.junit.Test;
 
 /**
  * This class tests cookie matching when using Virtual Host.
  */
-public class TestCookieVirtualHost extends IntegrationTestBase {
-
-    @Before
-    public void setUp() throws Exception {
-        this.localServer = new LocalTestServer(null, null);
-        this.localServer.registerDefaultHandlers();
-        this.localServer.start();
-    }
+public class TestCookieVirtualHost extends LocalServerTestBase {
 
     @Test
     public void testCookieMatchingWithVirtualHosts() throws Exception {
-        this.localServer.register("*", new HttpRequestHandler() {
+        this.serverBootstrap.registerHandler("*", new HttpRequestHandler() {
             @Override
             public void handle(
                     final HttpRequest request,
@@ -115,7 +107,7 @@ public class TestCookieVirtualHost exten
 
         });
 
-        this.httpclient = HttpClients.createDefault();
+        final HttpHost target = start();
 
         final CookieStore cookieStore = new BasicCookieStore();
         final HttpClientContext context = HttpClientContext.create();
@@ -126,8 +118,7 @@ public class TestCookieVirtualHost exten
         HttpRequest httpRequest = new HttpGet(uri);
         httpRequest.addHeader("X-Request", "1");
         @SuppressWarnings("resource")
-        final HttpResponse response1 = this.httpclient.execute(getServerHttp(),
-                httpRequest, context);
+        final HttpResponse response1 = this.httpclient.execute(target, httpRequest, context);
         final HttpEntity e1 = response1.getEntity();
         EntityUtils.consume(e1);
 
@@ -142,8 +133,7 @@ public class TestCookieVirtualHost exten
         httpRequest = new HttpGet(uri);
         httpRequest.addHeader("X-Request", "2");
         @SuppressWarnings("resource")
-        final HttpResponse response2 = this.httpclient.execute(getServerHttp(),
-                httpRequest, context);
+        final HttpResponse response2 = this.httpclient.execute(target, httpRequest, context);
         final HttpEntity e2 = response2.getEntity();
         EntityUtils.consume(e2);
 
@@ -152,8 +142,7 @@ public class TestCookieVirtualHost exten
         httpRequest = new HttpGet(uri);
         httpRequest.addHeader("X-Request", "3");
         @SuppressWarnings("resource")
-        final HttpResponse response3 = this.httpclient.execute(getServerHttp(),
-                httpRequest, context);
+        final HttpResponse response3 = this.httpclient.execute(target, httpRequest, context);
         final HttpEntity e3 = response3.getEntity();
         EntityUtils.consume(e3);
     }

Modified: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestIdleConnectionEviction.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestIdleConnectionEviction.java?rev=1603443&r1=1603442&r2=1603443&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestIdleConnectionEviction.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestIdleConnectionEviction.java Wed Jun 18 13:06:43 2014
@@ -27,7 +27,6 @@
 
 package org.apache.http.impl.client.integration;
 
-import java.net.InetSocketAddress;
 import java.util.concurrent.TimeUnit;
 
 import org.apache.http.HttpHost;
@@ -37,38 +36,22 @@ import org.apache.http.client.HttpClient
 import org.apache.http.client.methods.HttpGet;
 import org.apache.http.client.methods.HttpUriRequest;
 import org.apache.http.conn.HttpClientConnectionManager;
-import org.apache.http.impl.client.HttpClients;
-import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
 import org.apache.http.localserver.LocalServerTestBase;
-import org.apache.http.localserver.LocalTestServer;
 import org.apache.http.util.EntityUtils;
-import org.junit.Before;
-import org.junit.Ignore;
 import org.junit.Test;
 
 public class TestIdleConnectionEviction extends LocalServerTestBase {
 
-    @Before
-    public void setUp() throws Exception {
-        this.localServer = new LocalTestServer(null, null);
-        this.localServer.registerDefaultHandlers();
-        this.localServer.start();
-    }
-
     @Test
-    @Ignore("We have a concurrency bug in HttpCore which will be addressed after HttpClient 4.3.2 is released")
     public void testIdleConnectionEviction() throws Exception {
-        final PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager();
-        cm.setDefaultMaxPerRoute(10);
-        cm.setMaxTotal(50);
+        this.connManager.setDefaultMaxPerRoute(10);
+        this.connManager.setMaxTotal(50);
 
-        final HttpClient httpclient = HttpClients.custom().setConnectionManager(cm).build();
+        final HttpHost target = start();
 
-        final IdleConnectionMonitor idleConnectionMonitor = new IdleConnectionMonitor(cm);
+        final IdleConnectionMonitor idleConnectionMonitor = new IdleConnectionMonitor(this.connManager);
         idleConnectionMonitor.start();
 
-        final InetSocketAddress address = this.localServer.getServiceAddress();
-        final HttpHost target = new HttpHost(address.getHostName(), address.getPort());
         final HttpGet httpget = new HttpGet("/random/1024");
         final WorkerThread[] workers = new WorkerThread[5];
         for (int i = 0; i < workers.length; i++) {

Modified: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestMinimalClientRequestExecution.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestMinimalClientRequestExecution.java?rev=1603443&r1=1603442&r2=1603443&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestMinimalClientRequestExecution.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestMinimalClientRequestExecution.java Wed Jun 18 13:06:43 2014
@@ -33,6 +33,7 @@ import java.util.Set;
 
 import org.apache.http.Header;
 import org.apache.http.HttpException;
+import org.apache.http.HttpHost;
 import org.apache.http.HttpRequest;
 import org.apache.http.HttpResponse;
 import org.apache.http.HttpStatus;
@@ -40,22 +41,17 @@ import org.apache.http.client.methods.Ht
 import org.apache.http.client.protocol.HttpClientContext;
 import org.apache.http.entity.StringEntity;
 import org.apache.http.impl.client.HttpClients;
+import org.apache.http.localserver.LocalServerTestBase;
 import org.apache.http.protocol.HttpContext;
 import org.apache.http.protocol.HttpRequestHandler;
 import org.apache.http.util.EntityUtils;
 import org.junit.Assert;
-import org.junit.Before;
 import org.junit.Test;
 
 /**
  * Client protocol handling tests.
  */
-public class TestMinimalClientRequestExecution extends IntegrationTestBase {
-
-    @Before
-    public void setUp() throws Exception {
-        startServer();
-    }
+public class TestMinimalClientRequestExecution extends LocalServerTestBase {
 
     private static class SimpleService implements HttpRequestHandler {
 
@@ -76,13 +72,14 @@ public class TestMinimalClientRequestExe
 
     @Test
     public void testNonCompliantURI() throws Exception {
-        this.localServer.register("*", new SimpleService());
+        this.serverBootstrap.registerHandler("*", new SimpleService());
         this.httpclient = HttpClients.createMinimal();
+        final HttpHost target = start();
 
         final HttpClientContext context = HttpClientContext.create();
         for (int i = 0; i < 10; i++) {
             final HttpGet request = new HttpGet("/");
-            final HttpResponse response = this.httpclient.execute(getServerHttp(), request, context);
+            final HttpResponse response = this.httpclient.execute(target, request, context);
             EntityUtils.consume(response.getEntity());
             Assert.assertEquals(HttpStatus.SC_OK, response.getStatusLine().getStatusCode());
 



Mime
View raw message