From dbf7a77171581d28c76054db170c7d5ca04d260f Mon Sep 17 00:00:00 2001 From: Oleg Kalnichevski Date: Mon, 30 Jun 2014 10:12:31 +0000 Subject: [PATCH] Added new functionality to the pooling conn manager introduced by HTTPCORE-374 Contributed by Dmitry Potapov git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@1606665 13f79535-47bb-0310-9956-ffa450edef68 --- .../impl/conn/PoolingHttpClientConnectionManager.java | 8 ++++++++ .../client/integration/TestConnectionManagement.java | 9 +++++++++ 2 files changed, 17 insertions(+) diff --git a/httpclient/src/main/java/org/apache/http/impl/conn/PoolingHttpClientConnectionManager.java b/httpclient/src/main/java/org/apache/http/impl/conn/PoolingHttpClientConnectionManager.java index 3713f3f43..83bbbde1b 100644 --- a/httpclient/src/main/java/org/apache/http/impl/conn/PoolingHttpClientConnectionManager.java +++ b/httpclient/src/main/java/org/apache/http/impl/conn/PoolingHttpClientConnectionManager.java @@ -30,6 +30,7 @@ import java.io.Closeable; import java.io.IOException; import java.net.InetSocketAddress; import java.util.Map; +import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; @@ -445,6 +446,13 @@ public class PoolingHttpClientConnectionManager return this.pool.getStats(route); } + /** + * @since 4.4 + */ + public Set getRoutes() { + return this.pool.getRoutes(); + } + public SocketConfig getDefaultSocketConfig() { return this.configData.getDefaultSocketConfig(); } diff --git a/httpclient/src/test/java/org/apache/http/impl/client/integration/TestConnectionManagement.java b/httpclient/src/test/java/org/apache/http/impl/client/integration/TestConnectionManagement.java index 607e45b57..781a09640 100644 --- a/httpclient/src/test/java/org/apache/http/impl/client/integration/TestConnectionManagement.java +++ b/httpclient/src/test/java/org/apache/http/impl/client/integration/TestConnectionManagement.java @@ -31,6 +31,7 @@ import java.io.IOException; import java.net.InetSocketAddress; import java.net.Socket; import java.net.SocketException; +import java.util.Collections; import java.util.concurrent.CountDownLatch; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; @@ -297,18 +298,21 @@ public class TestConnectionManagement extends LocalServerTestBase { this.connManager.connect(conn, route, 0, context); this.connManager.routeComplete(conn, route, context); + Assert.assertEquals(Collections.singleton(route), this.connManager.getRoutes()); Assert.assertEquals(1, this.connManager.getTotalStats().getLeased()); Assert.assertEquals(1, this.connManager.getStats(route).getLeased()); this.connManager.releaseConnection(conn, null, 100, TimeUnit.MILLISECONDS); // Released, still active. + Assert.assertEquals(Collections.singleton(route), this.connManager.getRoutes()); Assert.assertEquals(1, this.connManager.getTotalStats().getAvailable()); Assert.assertEquals(1, this.connManager.getStats(route).getAvailable()); this.connManager.closeExpiredConnections(); // Time has not expired yet. + Assert.assertEquals(Collections.singleton(route), this.connManager.getRoutes()); Assert.assertEquals(1, this.connManager.getTotalStats().getAvailable()); Assert.assertEquals(1, this.connManager.getStats(route).getAvailable()); @@ -317,6 +321,7 @@ public class TestConnectionManagement extends LocalServerTestBase { this.connManager.closeExpiredConnections(); // Time expired now, connections are destroyed. + Assert.assertEquals(Collections.emptySet(), this.connManager.getRoutes()); Assert.assertEquals(0, this.connManager.getTotalStats().getAvailable()); Assert.assertEquals(0, this.connManager.getStats(route).getAvailable()); @@ -340,18 +345,21 @@ public class TestConnectionManagement extends LocalServerTestBase { this.connManager.connect(conn, route, 0, context); this.connManager.routeComplete(conn, route, context); + Assert.assertEquals(Collections.singleton(route), this.connManager.getRoutes()); Assert.assertEquals(1, this.connManager.getTotalStats().getLeased()); Assert.assertEquals(1, this.connManager.getStats(route).getLeased()); // Release, let remain idle for forever this.connManager.releaseConnection(conn, null, -1, TimeUnit.MILLISECONDS); // Released, still active. + Assert.assertEquals(Collections.singleton(route), this.connManager.getRoutes()); Assert.assertEquals(1, this.connManager.getTotalStats().getAvailable()); Assert.assertEquals(1, this.connManager.getStats(route).getAvailable()); this.connManager.closeExpiredConnections(); // Time has not expired yet. + Assert.assertEquals(Collections.singleton(route), this.connManager.getRoutes()); Assert.assertEquals(1, this.connManager.getTotalStats().getAvailable()); Assert.assertEquals(1, this.connManager.getStats(route).getAvailable()); @@ -360,6 +368,7 @@ public class TestConnectionManagement extends LocalServerTestBase { this.connManager.closeExpiredConnections(); // TTL expired now, connections are destroyed. + Assert.assertEquals(Collections.emptySet(), this.connManager.getRoutes()); Assert.assertEquals(0, this.connManager.getTotalStats().getAvailable()); Assert.assertEquals(0, this.connManager.getStats(route).getAvailable());