use of test.r2.integ.helper.BytesReader in project rest.li by linkedin.
the class TestStreamResponse method testErrorWhileStreaming.
@Test
public void testErrorWhileStreaming() throws Exception {
HttpClientFactory clientFactory = new HttpClientFactory.Builder().build();
Map<String, Object> clientProperties = new HashMap<>();
clientProperties.put(HttpClientFactory.HTTP_REQUEST_TIMEOUT, "1000");
Client client = _clientProvider.createClient(FilterChains.empty(), clientProperties);
StreamRequestBuilder builder = new StreamRequestBuilder(_clientProvider.createHttpURI(_port, SERVER_ERROR_URI));
StreamRequest request = builder.build(EntityStreams.emptyStream());
final AtomicInteger status = new AtomicInteger(-1);
final CountDownLatch latch = new CountDownLatch(1);
final AtomicReference<Throwable> error = new AtomicReference<>();
final Callback<None> readerCallback = getReaderCallback(latch, error);
final BytesReader reader = new BytesReader(BYTE, readerCallback);
Callback<StreamResponse> callback = getCallback(status, readerCallback, reader);
client.streamRequest(request, callback);
latch.await(2000, TimeUnit.MILLISECONDS);
Assert.assertEquals(status.get(), RestStatus.OK);
Throwable throwable = error.get();
System.out.println(_clientProvider.createHttpURI(_port, SERVER_ERROR_URI));
System.out.println(_serverProvider.getClass());
Assert.assertNotNull(throwable);
final FutureCallback<None> clientShutdownCallback = new FutureCallback<>();
client.shutdown(clientShutdownCallback);
clientShutdownCallback.get();
final FutureCallback<None> factoryShutdownCallback = new FutureCallback<>();
clientFactory.shutdown(factoryShutdownCallback);
factoryShutdownCallback.get();
}
use of test.r2.integ.helper.BytesReader in project rest.li by linkedin.
the class TestStreamingTimeout method testStreamSuccessWithoutStreamingTimeout.
@Test
public void testStreamSuccessWithoutStreamingTimeout() throws Exception {
final long totalBytes = TINY_BYTES_NUM;
final EntityStream entityStream = EntityStreams.newEntityStream(new BytesWriter(totalBytes, BYTE));
final StreamRequestBuilder builder = new StreamRequestBuilder(_clientProvider.createHttpURI(_port, NON_RATE_LIMITED_URI));
final StreamRequest request = builder.setMethod("POST").build(entityStream);
final AtomicInteger status = new AtomicInteger(-1);
final CountDownLatch latch = new CountDownLatch(1);
final Callback<StreamResponse> callback = expectSuccessCallback(latch, status);
_client.streamRequest(request, callback);
latch.await(HTTP_REQUEST_TIMEOUT, TimeUnit.MILLISECONDS);
Assert.assertEquals(status.get(), RestStatus.OK);
final BytesReader reader = _requestHandler.getReader();
Assert.assertNotNull(reader);
Assert.assertEquals(totalBytes, reader.getTotalBytes());
Assert.assertTrue(reader.allBytesCorrect());
}
Aggregations