|
12 | 12 | */
|
13 | 13 | package org.asynchttpclient.netty;
|
14 | 14 |
|
15 |
| -import org.asynchttpclient.*; |
16 |
| -import org.testng.annotations.Test; |
| 15 | +import static org.asynchttpclient.Dsl.*; |
17 | 16 |
|
18 | 17 | import java.util.concurrent.Future;
|
19 | 18 | import java.util.concurrent.TimeUnit;
|
20 | 19 |
|
21 |
| -import static org.testng.Assert.assertEquals; |
| 20 | +import org.asynchttpclient.AbstractBasicTest; |
| 21 | +import org.asynchttpclient.AsyncHttpClient; |
| 22 | +import org.asynchttpclient.Request; |
| 23 | +import org.asynchttpclient.RequestBuilder; |
| 24 | +import org.asynchttpclient.Response; |
| 25 | +import org.testng.annotations.Test; |
22 | 26 |
|
23 |
| -public class TimeToLiveIssue extends AbstractBasicTest |
24 |
| -{ |
25 |
| - @Test(groups = "standalone", enabled = false, description = "https://github.com/AsyncHttpClient/async-http-client/issues/1113") |
26 |
| - public void testTTLBug() throws Throwable |
27 |
| - { |
| 27 | +public class TimeToLiveIssue extends AbstractBasicTest { |
| 28 | + @Test(enabled = false, description = "https://github.com/AsyncHttpClient/async-http-client/issues/1113") |
| 29 | + public void testTTLBug() throws Throwable { |
28 | 30 | // The purpose of this test is to reproduce two issues:
|
29 | 31 | // 1) Connections that are rejected by the pool are not closed and eventually use all available sockets.
|
30 | 32 | // 2) It is possible for a connection to be closed while active by the timer task that checks for expired connections.
|
31 | 33 |
|
32 |
| - DefaultAsyncHttpClientConfig.Builder config = new DefaultAsyncHttpClientConfig.Builder(); |
33 |
| - config.setKeepAlive(true); |
34 |
| - config.setConnectionTtl(1); |
35 |
| - config.setPooledConnectionIdleTimeout(1); |
36 |
| - |
37 |
| - AsyncHttpClient client = new DefaultAsyncHttpClient(config.build()); |
| 34 | + try (AsyncHttpClient client = asyncHttpClient(config().setKeepAlive(true).setConnectionTtl(1).setPooledConnectionIdleTimeout(1))) { |
38 | 35 |
|
39 |
| - for (int i = 0; i < 200000; ++i) { |
40 |
| - Request request = new RequestBuilder().setUrl(String.format("http://localhost:%d/", port1)).build(); |
| 36 | + for (int i = 0; i < 200000; ++i) { |
| 37 | + Request request = new RequestBuilder().setUrl(String.format("http://localhost:%d/", port1)).build(); |
41 | 38 |
|
42 |
| - Future<Response> future = client.executeRequest(request); |
43 |
| - future.get(5, TimeUnit.SECONDS); |
| 39 | + Future<Response> future = client.executeRequest(request); |
| 40 | + future.get(5, TimeUnit.SECONDS); |
44 | 41 |
|
45 |
| - // This is to give a chance to the timer task that removes expired connection |
46 |
| - // from sometimes winning over poll for the ownership of a connection. |
47 |
| - if (System.currentTimeMillis() % 100 == 0) { |
48 |
| - Thread.sleep(5); |
| 42 | + // This is to give a chance to the timer task that removes expired connection |
| 43 | + // from sometimes winning over poll for the ownership of a connection. |
| 44 | + if (System.currentTimeMillis() % 100 == 0) { |
| 45 | + Thread.sleep(5); |
| 46 | + } |
49 | 47 | }
|
50 | 48 | }
|
51 | 49 | }
|
|
0 commit comments