use of org.asynchttpclient.ListenableFuture in project async-http-client by AsyncHttpClient.
the class ConnectionPoolTest method testMaxTotalConnectionsException.
@Test(groups = "standalone", expectedExceptions = TooManyConnectionsException.class)
public void testMaxTotalConnectionsException() throws Throwable {
try (AsyncHttpClient client = asyncHttpClient(config().setKeepAlive(true).setMaxConnections(1))) {
String url = getTargetUrl();
List<ListenableFuture<Response>> futures = new ArrayList<>();
for (int i = 0; i < 5; i++) {
logger.info("{} requesting url [{}]...", i, url);
futures.add(client.prepareGet(url).execute());
}
Exception exception = null;
for (ListenableFuture<Response> future : futures) {
try {
future.get();
} catch (Exception ex) {
exception = ex;
break;
}
}
assertNotNull(exception);
throw exception.getCause();
}
}
use of org.asynchttpclient.ListenableFuture in project async-http-client by AsyncHttpClient.
the class RetryNonBlockingIssue method testRetryNonBlockingAsyncConnect.
@Test(groups = "standalone")
public void testRetryNonBlockingAsyncConnect() throws IOException, InterruptedException, ExecutionException {
AsyncHttpClientConfig config = //
config().setKeepAlive(//
true).setMaxConnections(//
100).setConnectTimeout(//
60000).setRequestTimeout(//
30000).build();
try (AsyncHttpClient client = asyncHttpClient(config)) {
List<ListenableFuture<Response>> res = new ArrayList<>();
for (int i = 0; i < 32; i++) {
res.add(testMethodRequest(client, 3, "servlet", UUID.randomUUID().toString()));
}
StringBuilder b = new StringBuilder();
for (ListenableFuture<Response> r : res) {
Response theres = r.get();
assertEquals(theres.getStatusCode(), 200);
b.append("==============\r\n");
b.append("Response Headers\r\n");
HttpHeaders heads = theres.getHeaders();
b.append(heads + "\r\n");
b.append("==============\r\n");
}
System.out.println(b.toString());
System.out.flush();
}
}
use of org.asynchttpclient.ListenableFuture in project async-http-client by AsyncHttpClient.
the class RetryNonBlockingIssue method testRetryNonBlocking.
/**
* Tests that a head request can be made
*
* @throws IOException
* @throws ExecutionException
* @throws InterruptedException
*/
@Test(groups = "standalone")
public void testRetryNonBlocking() throws IOException, InterruptedException, ExecutionException {
AsyncHttpClientConfig config = //
config().setKeepAlive(//
true).setMaxConnections(//
100).setConnectTimeout(//
60000).setRequestTimeout(//
30000).build();
try (AsyncHttpClient client = asyncHttpClient(config)) {
List<ListenableFuture<Response>> res = new ArrayList<>();
for (int i = 0; i < 32; i++) {
res.add(testMethodRequest(client, 3, "servlet", UUID.randomUUID().toString()));
}
StringBuilder b = new StringBuilder();
for (ListenableFuture<Response> r : res) {
Response theres = r.get();
assertEquals(200, theres.getStatusCode());
b.append("==============\r\n");
b.append("Response Headers\r\n");
HttpHeaders heads = theres.getHeaders();
b.append(heads + "\r\n");
b.append("==============\r\n");
}
System.out.println(b.toString());
System.out.flush();
}
}
use of org.asynchttpclient.ListenableFuture in project async-http-client by AsyncHttpClient.
the class MaxTotalConnectionTest method testMaxTotalConnectionsExceedingException.
@Test(groups = "online")
public void testMaxTotalConnectionsExceedingException() throws IOException {
String[] urls = new String[] { "http://google.com", "http://github.com/" };
AsyncHttpClientConfig config = //
config().setConnectTimeout(//
1000).setRequestTimeout(//
5000).setKeepAlive(//
false).setMaxConnections(//
1).setMaxConnectionsPerHost(//
1).build();
try (AsyncHttpClient client = asyncHttpClient(config)) {
List<ListenableFuture<Response>> futures = new ArrayList<>();
for (String url : urls) {
futures.add(client.prepareGet(url).execute());
}
boolean caughtError = false;
int i;
for (i = 0; i < urls.length; i++) {
try {
futures.get(i).get();
} catch (Exception e) {
// assert that 2nd request fails, because
// maxTotalConnections=1
caughtError = true;
break;
}
}
Assert.assertEquals(1, i);
Assert.assertTrue(caughtError);
}
}
Aggregations