本文整理汇总了Java中org.asynchttpclient.ListenableFuture.get方法的典型用法代码示例。如果您正苦于以下问题:Java ListenableFuture.get方法的具体用法?Java ListenableFuture.get怎么用?Java ListenableFuture.get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.asynchttpclient.ListenableFuture
的用法示例。
在下文中一共展示了ListenableFuture.get方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testMaxTotalConnectionsException
import org.asynchttpclient.ListenableFuture; //导入方法依赖的package包/类
@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();
}
}
示例2: waitForAndAssertResponse
import org.asynchttpclient.ListenableFuture; //导入方法依赖的package包/类
private void waitForAndAssertResponse(ListenableFuture<Response> responseFuture) throws InterruptedException, java.util.concurrent.ExecutionException, IOException {
Response response = responseFuture.get();
if (500 == response.getStatusCode()) {
StringBuilder sb = new StringBuilder();
sb.append("==============\n");
sb.append("500 response from call\n");
sb.append("Headers:" + response.getHeaders() + "\n");
sb.append("==============\n");
logger.debug(sb.toString());
assertEquals(response.getStatusCode(), 500, "Should have 500 status code");
assertTrue(response.getHeader("X-Exception").contains("invalid.chunk.length"), "Should have failed due to chunking");
fail("HARD Failing the test due to provided InputStreamBodyGenerator, chunking incorrectly:" + response.getHeader("X-Exception"));
} else {
assertEquals(response.getResponseBodyAsBytes(), LARGE_IMAGE_BYTES);
}
}
示例3: markDimensionCacheHealthy
import org.asynchttpclient.ListenableFuture; //导入方法依赖的package包/类
/**
* Makes the dimensions passthrough.
* <p>
* This method sends a lastUpdated date to each dimension in the dimension cache, allowing the health checks
* to pass without having to set up a proper dimension loader. For each dimension, d, the following query is
* sent to the /v1/cache/dimensions/d endpoint:
* {
* "name": "d",
* "lastUpdated": "2016-01-01"
* }
*
* @param port The port through which we access the webservice
*
* @throws IOException If something goes terribly wrong when building the JSON or sending it
*/
private static void markDimensionCacheHealthy(int port) throws IOException {
AsyncHttpClient asyncHttpClient = new DefaultAsyncHttpClient();
for (DimensionConfig dimensionConfig : new WikiDimensions().getAllDimensionConfigurations()) {
String dimension = dimensionConfig.getApiName();
BoundRequestBuilder boundRequestBuilder = asyncHttpClient.preparePost("http://localhost:" + port +
"/v1/cache/dimensions/" + dimension)
.addHeader("Content-type", "application/json")
.setBody(
String.format("{\n \"name\":\"%s\",\n \"lastUpdated\":\"2016-01-01\"\n}", dimension)
);
ListenableFuture<Response> responseFuture = boundRequestBuilder.execute();
try {
Response response = responseFuture.get();
LOG.debug("Mark Dimension Cache Updated Response: ", response);
} catch (InterruptedException | ExecutionException e) {
LOG.warn("Failed while marking dimensions healthy", e);
}
}
}
示例4: testRetryNonBlocking
import org.asynchttpclient.ListenableFuture; //导入方法依赖的package包/类
/**
* 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();
}
}
示例5: testRetryNonBlockingAsyncConnect
import org.asynchttpclient.ListenableFuture; //导入方法依赖的package包/类
@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();
}
}
示例6: doExecute
import org.asynchttpclient.ListenableFuture; //导入方法依赖的package包/类
@Override
protected HttpResponse doExecute() throws Exception {
HttpUrl endpoint = getEndpoint();
String scheme = endpoint.getScheme();
String userInfo = null;
String host = endpoint.getHost();
int port = endpoint.getPort();
String path = Utf8UrlEncoder.encodePath(endpoint.getPath());
String query = null;
Uri uri = new Uri(scheme, userInfo, host, port, path, query);
String method = getMethod().getVerb();
RequestBuilder builder = new RequestBuilder(method, true).setUri(uri);
handleQueryParameters(builder);
handleBody(builder);
handleHeaders(builder);
handleCookies(builder);
Request request = builder.build();
ListenableFuture<Response> future = client.executeRequest(request);
long start = nanoTime();
Response response = future.get();
long duration = nanoTime() - start;
return new AsyncHttpResponse(response, duration);
}