Added new functionality to the pooling conn manager introduced by HTTPCORE-374
Contributed by Dmitry Potapov <potapov.d at gmail.com> git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@1606665 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
d20886cd56
commit
dbf7a77171
|
@ -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<HttpRoute> getRoutes() {
|
||||
return this.pool.getRoutes();
|
||||
}
|
||||
|
||||
public SocketConfig getDefaultSocketConfig() {
|
||||
return this.configData.getDefaultSocketConfig();
|
||||
}
|
||||
|
|
|
@ -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());
|
||||
|
||||
|
|
Loading…
Reference in New Issue