Skip to content

Commit e5ad56f

Browse files
author
Stephane Landelle
committed
Fix test
1 parent f101f54 commit e5ad56f

File tree

1 file changed

+26
-13
lines changed

1 file changed

+26
-13
lines changed

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

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,39 +19,52 @@
1919
import static org.testng.Assert.assertTrue;
2020
import static org.testng.Assert.fail;
2121

22+
import java.io.IOException;
23+
import java.util.ArrayList;
24+
import java.util.List;
25+
import java.util.concurrent.ExecutionException;
26+
import java.util.concurrent.Future;
27+
2228
import org.asynchttpclient.AsyncHttpClient;
2329
import org.asynchttpclient.AsyncHttpClientConfig;
30+
import org.asynchttpclient.ListenableFuture;
2431
import org.asynchttpclient.Response;
2532
import org.slf4j.Logger;
2633
import org.slf4j.LoggerFactory;
34+
import org.testng.Assert;
2735
import org.testng.annotations.Test;
2836

29-
import java.io.IOException;
30-
import java.util.ArrayList;
31-
import java.util.List;
32-
import java.util.concurrent.ExecutionException;
33-
import java.util.concurrent.Future;
34-
3537
public abstract class MaxTotalConnectionTest extends AbstractBasicTest {
3638
protected final Logger log = LoggerFactory.getLogger(AbstractBasicTest.class);
3739

3840
@Test(groups = { "standalone", "default_provider" })
39-
public void testMaxTotalConnectionsExceedingException() {
41+
public void testMaxTotalConnectionsExceedingException() throws IOException {
4042
String[] urls = new String[] { "http://google.com", "http://github.com/" };
4143

42-
AsyncHttpClient client = getAsyncHttpClient(new AsyncHttpClientConfig.Builder().setConnectTimeout(1000).setRequestTimeout(5000).setAllowPoolingConnections(false).setMaxConnections(1).setMaxConnectionsPerHost(1).build());
44+
AsyncHttpClient client = getAsyncHttpClient(new AsyncHttpClientConfig.Builder().setConnectTimeout(1000)
45+
.setRequestTimeout(5000).setAllowPoolingConnections(false).setMaxConnections(1).setMaxConnectionsPerHost(1)
46+
.build());
47+
4348
try {
44-
boolean caughtError = false;
49+
List<ListenableFuture<Response>> futures = new ArrayList<>();
4550
for (int i = 0; i < urls.length; i++) {
51+
futures.add(client.prepareGet(urls[i]).execute());
52+
}
53+
54+
boolean caughtError = false;
55+
int i;
56+
for (i = 0; i < urls.length; i++) {
4657
try {
47-
client.prepareGet(urls[i]).execute();
48-
} catch (IOException e) {
58+
futures.get(i).get();
59+
} catch (Exception e) {
4960
// assert that 2nd request fails, because maxTotalConnections=1
50-
assertEquals(i, 1);
5161
caughtError = true;
62+
break;
5263
}
5364
}
54-
assertTrue(caughtError);
65+
66+
Assert.assertEquals(1, i);
67+
Assert.assertTrue(caughtError);
5568
} finally {
5669
client.close();
5770
}

0 commit comments

Comments
 (0)