use of org.asynchttpclient.BoundRequestBuilder in project async-http-client by AsyncHttpClient.
the class AsyncHttpSingleTest method testNewRequestForEachSubscription.
@Test(groups = "standalone")
public void testNewRequestForEachSubscription() throws Exception {
final BoundRequestBuilder builder = mock(BoundRequestBuilder.class);
final Single<?> underTest = AsyncHttpSingle.create(builder);
underTest.subscribe(new TestSubscriber<>());
underTest.subscribe(new TestSubscriber<>());
verify(builder, times(2)).execute(any());
verifyNoMoreInteractions(builder);
}
use of org.asynchttpclient.BoundRequestBuilder in project async-http-client by AsyncHttpClient.
the class BodyDeferringAsyncHandlerTest method deferredInputStreamTrickWithFailure.
@Test(groups = "standalone", expectedExceptions = RemotelyClosedException.class)
public void deferredInputStreamTrickWithFailure() throws Throwable {
try (AsyncHttpClient client = asyncHttpClient(getAsyncHttpClientConfig())) {
BoundRequestBuilder r = client.prepareGet("http://localhost:" + port1 + "/deferredInputStreamTrickWithFailure").addHeader("X-FAIL-TRANSFER", Boolean.TRUE.toString());
PipedOutputStream pos = new PipedOutputStream();
PipedInputStream pis = new PipedInputStream(pos);
BodyDeferringAsyncHandler bdah = new BodyDeferringAsyncHandler(pos);
Future<Response> f = r.execute(bdah);
BodyDeferringInputStream is = new BodyDeferringInputStream(f, bdah, pis);
Response resp = is.getAsapResponse();
assertNotNull(resp);
assertEquals(resp.getStatusCode(), HttpServletResponse.SC_OK);
assertEquals(resp.getHeader(CONTENT_LENGTH), String.valueOf(CONTENT_LENGTH_VALUE));
// "consume" the body, but our code needs input stream
CountingOutputStream cos = new CountingOutputStream();
try {
try {
copy(is, cos);
} finally {
is.close();
cos.close();
}
} catch (IOException e) {
throw e.getCause();
}
}
}
use of org.asynchttpclient.BoundRequestBuilder in project async-http-client by AsyncHttpClient.
the class BodyDeferringAsyncHandlerTest method testConnectionRefused.
@Test(groups = "standalone", expectedExceptions = IOException.class)
public void testConnectionRefused() throws IOException, ExecutionException, TimeoutException, InterruptedException {
int newPortWithoutAnyoneListening = findFreePort();
try (AsyncHttpClient client = asyncHttpClient(getAsyncHttpClientConfig())) {
BoundRequestBuilder r = client.prepareGet("http://localhost:" + newPortWithoutAnyoneListening + "/testConnectionRefused");
CountingOutputStream cos = new CountingOutputStream();
BodyDeferringAsyncHandler bdah = new BodyDeferringAsyncHandler(cos);
r.execute(bdah);
bdah.getResponse();
}
}
use of org.asynchttpclient.BoundRequestBuilder in project async-http-client by AsyncHttpClient.
the class BodyDeferringAsyncHandlerTest method deferredSimple.
@Test(groups = "standalone")
public void deferredSimple() throws IOException, ExecutionException, TimeoutException, InterruptedException {
try (AsyncHttpClient client = asyncHttpClient(getAsyncHttpClientConfig())) {
BoundRequestBuilder r = client.prepareGet("http://localhost:" + port1 + "/deferredSimple");
CountingOutputStream cos = new CountingOutputStream();
BodyDeferringAsyncHandler bdah = new BodyDeferringAsyncHandler(cos);
Future<Response> f = r.execute(bdah);
Response resp = bdah.getResponse();
assertNotNull(resp);
assertEquals(resp.getStatusCode(), HttpServletResponse.SC_OK);
assertEquals(resp.getHeader(CONTENT_LENGTH), String.valueOf(CONTENT_LENGTH_VALUE));
// we got headers only, it's probably not all yet here (we have BIG file
// downloading)
assertTrue(cos.getByteCount() <= CONTENT_LENGTH_VALUE);
// now be polite and wait for body arrival too (otherwise we would be
// dropping the "line" on server)
f.get();
// it all should be here now
assertEquals(cos.getByteCount(), CONTENT_LENGTH_VALUE);
}
}
use of org.asynchttpclient.BoundRequestBuilder in project async-http-client by AsyncHttpClient.
the class ReactiveStreamsTest method testConnectionDoesNotGetClosed.
@Test(groups = "standalone")
public void testConnectionDoesNotGetClosed() throws Exception {
// test that we can stream the same request multiple times
try (AsyncHttpClient client = asyncHttpClient(config().setRequestTimeout(100 * 6000))) {
BoundRequestBuilder requestBuilder = client.preparePut(getTargetUrl()).setBody(LARGE_IMAGE_PUBLISHER);
Response response = requestBuilder.execute().get();
assertEquals(response.getStatusCode(), 200);
assertEquals(response.getResponseBodyAsBytes(), LARGE_IMAGE_BYTES);
response = requestBuilder.execute().get();
assertEquals(response.getStatusCode(), 200);
assertEquals(response.getResponseBodyAsBytes(), LARGE_IMAGE_BYTES);
}
}
Aggregations