Skip to content

Commit c3f0555

Browse files
author
eugenp
committed
work on connection management
1 parent 40dc518 commit c3f0555

2 files changed

Lines changed: 15 additions & 18 deletions

File tree

‎httpclient/src/test/java/org/baeldung/httpclient/conn/HttpClientConnectionManagementTest.java‎

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ public final void givenBasicHttpClientConnManager_whenConnectionReuse_thenNoExce
288288
}
289289

290290
@Test
291-
// 7.2 ARTICLE VERSION
291+
// 6.2 ARTICLE VERSION
292292
// @Ignore
293293
public final void whenConnectionsNeededGreaterThanMaxTotal_thenLeaseMasTotalandReuse() throws InterruptedException {
294294
final HttpGet get = new HttpGet("http://echo.200please.com");
@@ -308,9 +308,10 @@ public final void whenConnectionsNeededGreaterThanMaxTotal_thenLeaseMasTotalandR
308308
}
309309
}
310310

311+
// 7
312+
311313
@Test
312-
// @Ignore
313-
// 7.2.1
314+
// 7.1
314315
public final void whenConfiguringTimeOut_thenNoExceptions() {
315316
route = new HttpRoute(new HttpHost("localhost", 80));
316317
poolingConnManager = new PoolingHttpClientConnectionManager();
@@ -368,26 +369,20 @@ public final void whenCustomizedIdleConnMonitor_thenNoExceptions() throws Interr
368369
@Test(expected = IllegalStateException.class)
369370
// @Ignore
370371
// 9.1
371-
public final void whenClosingConnectionsandManager_thenCloseWithNoExceptions() throws InterruptedException, ExecutionException, IOException, HttpException {
372-
route = new HttpRoute(new HttpHost("google.com", 80));
373-
final HttpGet get = new HttpGet("http://google.com");
372+
public final void whenClosingConnectionsandManager_thenCloseWithNoExceptions1() throws InterruptedException, ExecutionException, IOException, HttpException {
374373
poolingConnManager = new PoolingHttpClientConnectionManager();
375-
final ConnectionRequest connRequest = poolingConnManager.requestConnection(route, null);
376-
context = HttpClientContext.create();
377-
conn = connRequest.get(10, TimeUnit.SECONDS);
378-
poolingConnManager.connect(conn, route, 10000, context);
379374
client = HttpClients.custom().setConnectionManager(poolingConnManager).build();
375+
final HttpGet get = new HttpGet("http://google.com");
380376
response = client.execute(get);
377+
381378
EntityUtils.consume(response.getEntity());
382-
client.close();
383-
conn.close();
384379
response.close();
380+
client.close();
385381
poolingConnManager.close();
386382
poolingConnManager.shutdown();
383+
387384
client.execute(get);
388-
conn.sendRequestHeader(get);
389-
assertTrue(!conn.isOpen());
390-
assertTrue(conn.isOpen());
385+
391386
assertTrue(response.getEntity() == null);
392387
}
393388

‎httpclient/src/test/java/org/baeldung/httpclient/conn/IdleConnectionMonitorThread.java‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@ public IdleConnectionMonitorThread(final PoolingHttpClientConnectionManager conn
1414
this.connMgr = connMgr;
1515
}
1616

17+
// API
18+
1719
@Override
18-
public void run() {
20+
public final void run() {
1921
try {
2022
while (!shutdown) {
2123
synchronized (this) {
@@ -26,14 +28,14 @@ public void run() {
2628
}
2729
} catch (final InterruptedException ex) {
2830
shutdown();
29-
3031
}
3132
}
3233

33-
public void shutdown() {
34+
public final void shutdown() {
3435
shutdown = true;
3536
synchronized (this) {
3637
notifyAll();
3738
}
3839
}
40+
3941
}

0 commit comments

Comments
 (0)