Skip to content

Commit a7d646d

Browse files
author
Stephane Landelle
committed
Fix ConnectionPool tests
1 parent 87ccf94 commit a7d646d

File tree

2 files changed

+28
-22
lines changed

2 files changed

+28
-22
lines changed

api/src/test/java/org/asynchttpclient/async/ConnectionPoolTest.java

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -20,23 +20,26 @@
2020
import static org.testng.Assert.assertNull;
2121
import static org.testng.Assert.fail;
2222

23+
import java.io.IOException;
24+
import java.util.ArrayList;
25+
import java.util.List;
26+
import java.util.Map;
27+
import java.util.concurrent.ConcurrentHashMap;
28+
import java.util.concurrent.CountDownLatch;
29+
import java.util.concurrent.ExecutionException;
30+
import java.util.concurrent.TimeUnit;
31+
import java.util.concurrent.atomic.AtomicInteger;
32+
2333
import org.asynchttpclient.AsyncCompletionHandler;
2434
import org.asynchttpclient.AsyncCompletionHandlerBase;
2535
import org.asynchttpclient.AsyncHttpClient;
2636
import org.asynchttpclient.AsyncHttpClientConfig;
37+
import org.asynchttpclient.ListenableFuture;
2738
import org.asynchttpclient.Response;
2839
import org.slf4j.Logger;
2940
import org.slf4j.LoggerFactory;
3041
import org.testng.annotations.Test;
3142

32-
import java.io.IOException;
33-
import java.util.Map;
34-
import java.util.concurrent.ConcurrentHashMap;
35-
import java.util.concurrent.CountDownLatch;
36-
import java.util.concurrent.ExecutionException;
37-
import java.util.concurrent.TimeUnit;
38-
import java.util.concurrent.atomic.AtomicInteger;
39-
4043
public abstract class ConnectionPoolTest extends AbstractBasicTest {
4144
protected final Logger log = LoggerFactory.getLogger(AbstractBasicTest.class);
4245

@@ -63,29 +66,30 @@ public void testMaxTotalConnections() {
6366
}
6467

6568
@Test(groups = { "standalone", "default_provider" })
66-
public void testMaxTotalConnectionsException() {
69+
public void testMaxTotalConnectionsException() throws IOException {
6770
AsyncHttpClient client = getAsyncHttpClient(new AsyncHttpClientConfig.Builder().setAllowPoolingConnections(true).setMaxConnections(1).build());
6871
try {
6972
String url = getTargetUrl();
70-
int i;
73+
74+
List<ListenableFuture<Response>> futures = new ArrayList<>();
75+
for (int i = 0; i < 5; i++) {
76+
log.info("{} requesting url [{}]...", i, url);
77+
futures.add(client.prepareGet(url).execute());
78+
}
79+
7180
Exception exception = null;
72-
for (i = 0; i < 20; i++) {
81+
for (ListenableFuture<Response> future : futures) {
7382
try {
74-
log.info("{} requesting url [{}]...", i, url);
75-
76-
if (i < 5) {
77-
client.prepareGet(url).execute().get();
78-
} else {
79-
client.prepareGet(url).execute();
80-
}
83+
future.get();
8184
} catch (Exception ex) {
8285
exception = ex;
8386
break;
8487
}
8588
}
89+
8690
assertNotNull(exception);
87-
assertNotNull(exception.getMessage());
88-
assertEquals(exception.getMessage(), "Too many connections 1");
91+
assertNotNull(exception.getCause());
92+
assertEquals(exception.getCause().getMessage(), "Too many connections 1");
8993
} finally {
9094
client.close();
9195
}
@@ -152,7 +156,8 @@ public void multipleMaxConnectionOpenTest() throws Exception {
152156
exception = ex;
153157
}
154158
assertNotNull(exception);
155-
assertEquals(exception.getMessage(), "Too many connections 1");
159+
assertNotNull(exception.getCause());
160+
assertEquals(exception.getCause().getMessage(), "Too many connections 1");
156161
} finally {
157162
c.close();
158163
}

providers/netty/src/test/java/org/asynchttpclient/providers/netty/NettyConnectionPoolTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ public boolean isOpen() {
6262
exception = ex;
6363
}
6464
assertNotNull(exception);
65-
assertEquals(exception.getMessage(), "Too many connections -1");
65+
assertNotNull(exception.getCause());
66+
assertEquals(exception.getCause().getMessage(), "Too many connections -1");
6667
} finally {
6768
client.close();
6869
}

0 commit comments

Comments
 (0)