diff --git a/httpclient/src/test/java/org/baeldung/httpclient/conn/HttpClientConnectionManagementTest.java b/httpclient/src/test/java/org/baeldung/httpclient/conn/HttpClientConnectionManagementTest.java index 619e2539cf..c5c960f527 100644 --- a/httpclient/src/test/java/org/baeldung/httpclient/conn/HttpClientConnectionManagementTest.java +++ b/httpclient/src/test/java/org/baeldung/httpclient/conn/HttpClientConnectionManagementTest.java @@ -288,7 +288,7 @@ public class HttpClientConnectionManagementTest { } @Test - // 7.2 ARTICLE VERSION + // 6.2 ARTICLE VERSION // @Ignore public final void whenConnectionsNeededGreaterThanMaxTotal_thenLeaseMasTotalandReuse() throws InterruptedException { final HttpGet get = new HttpGet("http://echo.200please.com"); @@ -308,9 +308,10 @@ public class HttpClientConnectionManagementTest { } } + // 7 + @Test - // @Ignore - // 7.2.1 + // 7.1 public final void whenConfiguringTimeOut_thenNoExceptions() { route = new HttpRoute(new HttpHost("localhost", 80)); poolingConnManager = new PoolingHttpClientConnectionManager(); @@ -368,26 +369,20 @@ public class HttpClientConnectionManagementTest { @Test(expected = IllegalStateException.class) // @Ignore // 9.1 - public final void whenClosingConnectionsandManager_thenCloseWithNoExceptions() throws InterruptedException, ExecutionException, IOException, HttpException { - route = new HttpRoute(new HttpHost("google.com", 80)); - final HttpGet get = new HttpGet("http://google.com"); + public final void whenClosingConnectionsandManager_thenCloseWithNoExceptions1() throws InterruptedException, ExecutionException, IOException, HttpException { 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(); + final HttpGet get = new HttpGet("http://google.com"); response = client.execute(get); + EntityUtils.consume(response.getEntity()); - client.close(); - conn.close(); response.close(); + client.close(); poolingConnManager.close(); poolingConnManager.shutdown(); + client.execute(get); - conn.sendRequestHeader(get); - assertTrue(!conn.isOpen()); - assertTrue(conn.isOpen()); + assertTrue(response.getEntity() == null); } diff --git a/httpclient/src/test/java/org/baeldung/httpclient/conn/IdleConnectionMonitorThread.java b/httpclient/src/test/java/org/baeldung/httpclient/conn/IdleConnectionMonitorThread.java index cd0acef09b..2a1c419e41 100644 --- a/httpclient/src/test/java/org/baeldung/httpclient/conn/IdleConnectionMonitorThread.java +++ b/httpclient/src/test/java/org/baeldung/httpclient/conn/IdleConnectionMonitorThread.java @@ -14,8 +14,10 @@ public class IdleConnectionMonitorThread extends Thread { this.connMgr = connMgr; } + // API + @Override - public void run() { + public final void run() { try { while (!shutdown) { synchronized (this) { @@ -26,14 +28,14 @@ public class IdleConnectionMonitorThread extends Thread { } } catch (final InterruptedException ex) { shutdown(); - } } - public void shutdown() { + public final void shutdown() { shutdown = true; synchronized (this) { notifyAll(); } } + }