Skip to content

Commit 0d5e592

Browse files
rlubkeStephane Landelle
authored andcommitted
Improve Grizzly's copy of the testMaxTotalConnectionsException test. Original copied test logic relied on timing for the failure to occur. New logic uses two requests - one to use the connection and wait, and the second to ensure the connection pool throws an exception because we have a max connection limit of one.
1 parent 31a721d commit 0d5e592

File tree

1 file changed

+16
-15
lines changed

1 file changed

+16
-15
lines changed

src/test/java/com/ning/http/client/async/grizzly/GrizzlyConnectionPoolTest.java

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@
1717
import static org.testng.Assert.assertNotNull;
1818
import static org.testng.Assert.fail;
1919

20+
import java.io.IOException;
2021
import java.util.concurrent.TimeUnit;
2122

23+
import com.ning.http.client.ListenableFuture;
2224
import org.testng.annotations.Test;
2325

2426
import com.ning.http.client.AsyncHttpClient;
@@ -42,22 +44,21 @@ public void testMaxTotalConnectionsException() {
4244
String url = getTargetUrl();
4345
int i;
4446
Exception exception = null;
45-
for (i = 0; i < 20; i++) {
46-
try {
47-
log.info("{} requesting url [{}]...", i, url);
48-
49-
if (i < 5) {
50-
client.prepareGet(url).execute().get();
51-
} else {
52-
client.prepareGet(url).execute();
53-
}
54-
} catch (Exception ex) {
55-
exception = ex;
56-
break;
57-
}
47+
ListenableFuture lockRequest = null;
48+
try {
49+
lockRequest = client.prepareGet(url).addHeader("LockThread", "true").execute();
50+
} catch (Exception e) {
51+
fail("Unexpected exception thrown.", e);
5852
}
59-
assertNotNull(exception);
60-
assertNotNull(exception.getMessage());
53+
try {
54+
client.prepareConnect(url).execute().get();
55+
} catch (IOException ioe) {
56+
assertNotNull(ioe);
57+
assertEquals("Max connections exceeded", ioe.getMessage());
58+
} catch (Exception e) {
59+
fail("Unexpected exception thrown.", e);
60+
}
61+
lockRequest.cancel(true);
6162
} finally {
6263
client.close();
6364
}

0 commit comments

Comments
 (0)