use of test.r2.integ.helper.BytesWriter 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());
}
use of test.r2.integ.helper.BytesWriter in project rest.li by linkedin.
the class TestJetty404 method testJetty404.
// make sure jetty's default behavior will read all the request bytes in case of 404
// Known to be flaky in CI
@Test(retryAnalyzer = SingleRetry.class)
public void testJetty404() throws Exception {
BytesWriter writer = new BytesWriter(200 * 1024, (byte) 100);
final AtomicReference<Throwable> exRef = new AtomicReference<>();
final CountDownLatch latch = new CountDownLatch(1);
_client.streamRequest(new StreamRequestBuilder(Bootstrap.createHttpURI(PORT, URI.create("/wrong-path"))).build(EntityStreams.newEntityStream(writer)), new Callback<StreamResponse>() {
@Override
public void onError(Throwable e) {
exRef.set(e);
latch.countDown();
}
@Override
public void onSuccess(StreamResponse result) {
latch.countDown();
}
});
latch.await(5000, TimeUnit.MILLISECONDS);
Assert.assertTrue(writer.isDone());
Throwable ex = exRef.get();
Assert.assertTrue(ex instanceof StreamException, "Expected StreamException but found: " + ex);
StreamResponse response = ((StreamException) ex).getResponse();
Assert.assertEquals(response.getStatus(), RestStatus.NOT_FOUND);
response.getEntityStream().setReader(new DrainReader());
}
Aggregations