3333import org .apache .http .util .EntityUtils ;
3434import org .junit .After ;
3535import org .junit .Before ;
36- import org .junit .Ignore ;
3736import org .junit .Test ;
3837
39-
4038public class HttpClientConnectionManagementTest {
4139 private BasicHttpClientConnectionManager basicConnManager ;
4240 private HttpClientContext context ;
@@ -75,13 +73,12 @@ public final void after() throws IllegalStateException, IOException {
7573 client .close ();
7674 if (response != null )
7775 response .close ();
78-
7976 }
8077
8178 // tests
8279
8380 @ Test
84- @ Ignore
81+ // @Ignore
8582 // 2.1 IN ARTCLE
8683 public final void whenLowLevelConnectionIsEstablished_thenNoExceptions () throws IOException , HttpException , InterruptedException , ExecutionException {
8784 basicConnManager = new BasicHttpClientConnectionManager ();
@@ -90,7 +87,7 @@ public final void whenLowLevelConnectionIsEstablished_thenNoExceptions() throws
9087 }
9188
9289 @ Test
93- @ Ignore
90+ // @Ignore
9491 // 2.2 IN ARTICLE
9592 public final void whenOpeningLowLevelConnectionWithSocketTimeout_thenNoExceptions () throws InterruptedException , ExecutionException , IOException , HttpException {
9693 basicConnManager = new BasicHttpClientConnectionManager ();
@@ -106,11 +103,11 @@ public final void whenOpeningLowLevelConnectionWithSocketTimeout_thenNoException
106103 }
107104
108105 @ Test
109- @ Ignore
106+ // @Ignore
110107 // Example 3.1. TESTER VERSION
111108 public final void WhenTwoConnectionsForTwoRequests_ThenLeaseTwoConnectionsNoExceptions () throws InterruptedException {
112- get1 = new HttpGet ("http://localhost " );
113- get2 = new HttpGet ("http://google. com" );
109+ get1 = new HttpGet ("http://www.petrikainulainen.net/ " );
110+ get2 = new HttpGet ("http://www.baeldung. com/ " );
114111 poolingConnManager = new PoolingHttpClientConnectionManager ();
115112 final CloseableHttpClient client1 = HttpClients .custom ().setConnectionManager (poolingConnManager ).build ();
116113 final CloseableHttpClient client2 = HttpClients .custom ().setConnectionManager (poolingConnManager ).build ();
@@ -119,13 +116,12 @@ public final void WhenTwoConnectionsForTwoRequests_ThenLeaseTwoConnectionsNoExce
119116 thread1 .start ();
120117 thread1 .join ();
121118 thread2 .start ();
122- assertTrue (poolingConnManager .getTotalStats ().getLeased () == 1 );
123119 thread2 .join (1000 );
124120 assertTrue (poolingConnManager .getTotalStats ().getLeased () == 2 );
125121 }
126122
127123 @ Test
128- @ Ignore
124+ // @Ignore
129125 // Example 3.1.ARTICLE VERSION
130126 public final void WhenTwoConnectionsForTwoRequests_ThensNoExceptions () throws InterruptedException {
131127 get1 = new HttpGet ("http://localhost" );
@@ -142,10 +138,9 @@ public final void WhenTwoConnectionsForTwoRequests_ThensNoExceptions() throws In
142138 }
143139
144140 @ Test
145- @ Ignore
141+ // @Ignore
146142 // 3.3
147143 public final void whenIncreasingConnectionPool_thenNoEceptions () {
148-
149144 poolingConnManager = new PoolingHttpClientConnectionManager ();
150145 poolingConnManager .setMaxTotal (5 );
151146 poolingConnManager .setDefaultMaxPerRoute (4 );
@@ -154,7 +149,7 @@ public final void whenIncreasingConnectionPool_thenNoEceptions() {
154149 }
155150
156151 @ Test
157- @ Ignore
152+ // @Ignore
158153 // 3.4 Tester Version
159154 public final void whenExecutingSameRequestsInDifferentThreads_thenUseDefaultConnLimitNoExceptions () throws InterruptedException , IOException {
160155 final HttpGet get = new HttpGet ("http://google.com" );
@@ -174,7 +169,7 @@ public final void whenExecutingSameRequestsInDifferentThreads_thenUseDefaultConn
174169 }
175170
176171 @ Test
177- @ Ignore
172+ // @Ignore
178173 // 3.4 Article version
179174 public final void whenExecutingSameRequestsInDifferentThreads_thenExxecuteReuqesttNoExceptions () throws InterruptedException {
180175 final HttpGet get = new HttpGet ("http://localhost" );
@@ -192,7 +187,7 @@ public final void whenExecutingSameRequestsInDifferentThreads_thenExxecuteReuqes
192187 }
193188
194189 @ Test
195- @ Ignore
190+ // @Ignore
196191 // 4.1
197192 public final void whenCustomizingKeepAliveStrategy_thenNoExceptions () throws ClientProtocolException , IOException {
198193 final ConnectionKeepAliveStrategy myStrategy = new ConnectionKeepAliveStrategy () {
@@ -222,7 +217,7 @@ public long getKeepAliveDuration(final HttpResponse myResponse, final HttpContex
222217 }
223218
224219 @ Test
225- @ Ignore
220+ // @Ignore
226221 // 5.1
227222 public final void GivenBasicHttpClientConnManager_whenConnectionReuse_thenNoExceptions () throws InterruptedException , ExecutionException , IOException , HttpException {
228223 basicConnManager = new BasicHttpClientConnectionManager ();
@@ -248,7 +243,7 @@ public final void GivenBasicHttpClientConnManager_whenConnectionReuse_thenNoExce
248243 }
249244
250245 @ Test
251- @ Ignore
246+ // @Ignore
252247 // 5.2 TESTER VERSION
253248 public final void WhenConnectionsNeededGreaterThanMaxTotal_thenReuseConnectionsNoExceptions () throws InterruptedException {
254249 poolingConnManager = new PoolingHttpClientConnectionManager ();
@@ -271,9 +266,9 @@ public final void WhenConnectionsNeededGreaterThanMaxTotal_thenReuseConnectionsN
271266 }
272267 }
273268
274- @ Test
275269 // 5.2 ARTICLE VERSION
276- @ Ignore
270+ @ Test
271+ // @Ignore
277272 public final void WhenConnectionsNeededGreaterThanMaxTotal_thenLeaseMasTotalandReuseNoExceptions () throws InterruptedException {
278273 final HttpGet get = new HttpGet ("http://echo.200please.com" );
279274 poolingConnManager = new PoolingHttpClientConnectionManager ();
@@ -293,7 +288,7 @@ public final void WhenConnectionsNeededGreaterThanMaxTotal_thenLeaseMasTotalandR
293288 }
294289
295290 @ Test
296- @ Ignore
291+ // @Ignore
297292 // 6.2.1
298293 public final void whenConfiguringTimeOut_thenNoExceptions () {
299294 route = new HttpRoute (new HttpHost ("localhost" , 80 ));
@@ -303,15 +298,15 @@ public final void whenConfiguringTimeOut_thenNoExceptions() {
303298 }
304299
305300 @ Test
306- @ Ignore
301+ // @Ignore
307302 // 7.1
308303 public final void whenHttpClientChecksStaleConns_thenNoExceptions () {
309304 poolingConnManager = new PoolingHttpClientConnectionManager ();
310305 client = HttpClients .custom ().setDefaultRequestConfig (RequestConfig .custom ().setStaleConnectionCheckEnabled (true ).build ()).setConnectionManager (poolingConnManager ).build ();
311306 }
312307
313308 @ Test
314- @ Ignore
309+ // @Ignore
315310 // 7.2 TESTER VERSION
316311 public final void whenCustomizedIdleConnMonitor_thenEliminateIdleConnsNoExceptions () throws InterruptedException , IOException {
317312 poolingConnManager = new PoolingHttpClientConnectionManager ();
@@ -334,7 +329,7 @@ public final void whenCustomizedIdleConnMonitor_thenEliminateIdleConnsNoExceptio
334329 }
335330
336331 @ Test
337- @ Ignore
332+ // @Ignore
338333 // 7.2 ARTICLE VERSION
339334 public final void whenCustomizedIdleConnMonitor_thenNoExceptions () throws InterruptedException , IOException {
340335 final HttpGet get = new HttpGet ("http://google.com" );
@@ -346,7 +341,7 @@ public final void whenCustomizedIdleConnMonitor_thenNoExceptions() throws Interr
346341 }
347342
348343 @ Test (expected = IllegalStateException .class )
349- @ Ignore
344+ // @Ignore
350345 // 8.1
351346 public final void whenClosingConnectionsandManager_thenCloseWithNoExceptions () throws InterruptedException , ExecutionException , IOException , HttpException {
352347 route = new HttpRoute (new HttpHost ("google.com" , 80 ));
@@ -370,4 +365,5 @@ public final void whenClosingConnectionsandManager_thenCloseWithNoExceptions() t
370365 assertTrue (conn .isOpen ());
371366 assertTrue (response .getEntity () == null );
372367 }
368+
373369}
0 commit comments