work on connection management
This commit is contained in:
parent
40dc518df0
commit
c3f0555b20
@ -288,7 +288,7 @@ public class HttpClientConnectionManagementTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
// 7.2 ARTICLE VERSION
|
// 6.2 ARTICLE VERSION
|
||||||
// @Ignore
|
// @Ignore
|
||||||
public final void whenConnectionsNeededGreaterThanMaxTotal_thenLeaseMasTotalandReuse() throws InterruptedException {
|
public final void whenConnectionsNeededGreaterThanMaxTotal_thenLeaseMasTotalandReuse() throws InterruptedException {
|
||||||
final HttpGet get = new HttpGet("http://echo.200please.com");
|
final HttpGet get = new HttpGet("http://echo.200please.com");
|
||||||
@ -308,9 +308,10 @@ public class HttpClientConnectionManagementTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 7
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
// @Ignore
|
// 7.1
|
||||||
// 7.2.1
|
|
||||||
public final void whenConfiguringTimeOut_thenNoExceptions() {
|
public final void whenConfiguringTimeOut_thenNoExceptions() {
|
||||||
route = new HttpRoute(new HttpHost("localhost", 80));
|
route = new HttpRoute(new HttpHost("localhost", 80));
|
||||||
poolingConnManager = new PoolingHttpClientConnectionManager();
|
poolingConnManager = new PoolingHttpClientConnectionManager();
|
||||||
@ -368,26 +369,20 @@ public class HttpClientConnectionManagementTest {
|
|||||||
@Test(expected = IllegalStateException.class)
|
@Test(expected = IllegalStateException.class)
|
||||||
// @Ignore
|
// @Ignore
|
||||||
// 9.1
|
// 9.1
|
||||||
public final void whenClosingConnectionsandManager_thenCloseWithNoExceptions() throws InterruptedException, ExecutionException, IOException, HttpException {
|
public final void whenClosingConnectionsandManager_thenCloseWithNoExceptions1() throws InterruptedException, ExecutionException, IOException, HttpException {
|
||||||
route = new HttpRoute(new HttpHost("google.com", 80));
|
|
||||||
final HttpGet get = new HttpGet("http://google.com");
|
|
||||||
poolingConnManager = new PoolingHttpClientConnectionManager();
|
poolingConnManager = new PoolingHttpClientConnectionManager();
|
||||||
final ConnectionRequest connRequest = poolingConnManager.requestConnection(route, null);
|
|
||||||
context = HttpClientContext.create();
|
|
||||||
conn = connRequest.get(10, TimeUnit.SECONDS);
|
|
||||||
poolingConnManager.connect(conn, route, 10000, context);
|
|
||||||
client = HttpClients.custom().setConnectionManager(poolingConnManager).build();
|
client = HttpClients.custom().setConnectionManager(poolingConnManager).build();
|
||||||
|
final HttpGet get = new HttpGet("http://google.com");
|
||||||
response = client.execute(get);
|
response = client.execute(get);
|
||||||
|
|
||||||
EntityUtils.consume(response.getEntity());
|
EntityUtils.consume(response.getEntity());
|
||||||
client.close();
|
|
||||||
conn.close();
|
|
||||||
response.close();
|
response.close();
|
||||||
|
client.close();
|
||||||
poolingConnManager.close();
|
poolingConnManager.close();
|
||||||
poolingConnManager.shutdown();
|
poolingConnManager.shutdown();
|
||||||
|
|
||||||
client.execute(get);
|
client.execute(get);
|
||||||
conn.sendRequestHeader(get);
|
|
||||||
assertTrue(!conn.isOpen());
|
|
||||||
assertTrue(conn.isOpen());
|
|
||||||
assertTrue(response.getEntity() == null);
|
assertTrue(response.getEntity() == null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,8 +14,10 @@ public class IdleConnectionMonitorThread extends Thread {
|
|||||||
this.connMgr = connMgr;
|
this.connMgr = connMgr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// API
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public final void run() {
|
||||||
try {
|
try {
|
||||||
while (!shutdown) {
|
while (!shutdown) {
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
@ -26,14 +28,14 @@ public class IdleConnectionMonitorThread extends Thread {
|
|||||||
}
|
}
|
||||||
} catch (final InterruptedException ex) {
|
} catch (final InterruptedException ex) {
|
||||||
shutdown();
|
shutdown();
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void shutdown() {
|
public final void shutdown() {
|
||||||
shutdown = true;
|
shutdown = true;
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
notifyAll();
|
notifyAll();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user