use of test.r2.integ.helper.BytesWriter in project rest.li by linkedin.
the class TestStreamRequest method testErrorReceiver.
@Test
public void testErrorReceiver() throws Exception {
final long totalBytes = SMALL_BYTES_NUM;
EntityStream entityStream = EntityStreams.newEntityStream(new BytesWriter(totalBytes, BYTE));
StreamRequestBuilder builder = new StreamRequestBuilder(_clientProvider.createHttpURI(_port, ERROR_RECEIVER_URI));
StreamRequest request = builder.setMethod("POST").build(entityStream);
final CountDownLatch latch = new CountDownLatch(1);
final AtomicReference<Throwable> error = new AtomicReference<>();
Callback<StreamResponse> callback = new Callback<StreamResponse>() {
@Override
public void onError(Throwable e) {
error.set(e);
latch.countDown();
}
@Override
public void onSuccess(StreamResponse result) {
latch.countDown();
}
};
_client.streamRequest(request, callback);
latch.await();
Assert.assertNotNull(error.get());
}
use of test.r2.integ.helper.BytesWriter in project rest.li by linkedin.
the class TestStreamRequest method testRequestLarge.
@Test
public void testRequestLarge() throws Exception {
final long totalBytes = LARGE_BYTES_NUM;
EntityStream entityStream = EntityStreams.newEntityStream(new BytesWriter(totalBytes, BYTE));
StreamRequestBuilder builder = new StreamRequestBuilder(_clientProvider.createHttpURI(_port, LARGE_URI));
StreamRequest request = builder.setMethod("POST").build(entityStream);
final AtomicInteger status = new AtomicInteger(-1);
final CountDownLatch latch = new CountDownLatch(1);
Callback<StreamResponse> callback = expectSuccessCallback(latch, status);
_client.streamRequest(request, callback);
latch.await(60000, TimeUnit.MILLISECONDS);
Assert.assertEquals(status.get(), RestStatus.OK);
BytesReader reader = _checkRequestHandler.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 TestRequestCompression method testNoCompression.
@Test(dataProvider = "noCompressionData")
public void testNoCompression(Client client) throws InterruptedException, TimeoutException, ExecutionException {
StreamRequestBuilder builder = new StreamRequestBuilder((_clientProvider.createHttpURI(_port, NO_COMPRESSION_URI)));
BytesWriter writer = new BytesWriter(THRESHOLD - 1, BYTE);
StreamRequest request = builder.build(EntityStreams.newEntityStream(writer));
final FutureCallback<StreamResponse> callback = new FutureCallback<>();
client.streamRequest(request, callback);
final StreamResponse response = callback.get(60, TimeUnit.SECONDS);
Assert.assertEquals(response.getStatus(), RestStatus.OK);
}
use of test.r2.integ.helper.BytesWriter in project rest.li by linkedin.
the class TestRequestCompression method testRequestCompression.
@Test(dataProvider = "requestCompressionData")
public void testRequestCompression(Client client, URI uri) throws InterruptedException, TimeoutException, ExecutionException {
StreamRequestBuilder builder = new StreamRequestBuilder((_clientProvider.createHttpURI(_port, uri)));
BytesWriter writer = new BytesWriter(NUM_BYTES, BYTE);
StreamRequest request = builder.build(EntityStreams.newEntityStream(writer));
final FutureCallback<StreamResponse> callback = new FutureCallback<>();
client.streamRequest(request, callback);
final StreamResponse response = callback.get(60, TimeUnit.SECONDS);
Assert.assertEquals(response.getStatus(), RestStatus.OK);
}
use of test.r2.integ.helper.BytesWriter in project rest.li by linkedin.
the class TestCompressionEcho method testResponseCompression.
@Test(dataProvider = "compressionEchoData")
public void testResponseCompression(Client client, long bytes) throws InterruptedException, TimeoutException, ExecutionException {
StreamRequestBuilder builder = new StreamRequestBuilder((_clientProvider.createHttpURI(_port, ECHO_URI)));
BytesWriter writer = new BytesWriter(bytes, BYTE);
StreamRequest request = builder.build(EntityStreams.newEntityStream(writer));
// add operation to enable sending accept encoding
RequestContext requestContext = new RequestContext();
requestContext.putLocalAttr(R2Constants.OPERATION, "get");
final FutureCallback<StreamResponse> callback = new FutureCallback<>();
client.streamRequest(request, requestContext, callback);
final StreamResponse response = callback.get(60, TimeUnit.SECONDS);
Assert.assertEquals(response.getStatus(), RestStatus.OK);
final FutureCallback<None> readerCallback = new FutureCallback<>();
final BytesReader reader = new BytesReader(BYTE, readerCallback);
response.getEntityStream().setReader(reader);
readerCallback.get(60, TimeUnit.SECONDS);
Assert.assertEquals(reader.getTotalBytes(), bytes);
Assert.assertTrue(reader.allBytesCorrect());
}
Aggregations