use of test.r2.integ.helper.BytesWriter in project rest.li by linkedin.
the class TestStreamRequest method test404.
// jetty 404 tests singled out
@Test(enabled = false)
public void test404() throws Exception {
final long totalBytes = TINY_BYTES_NUM;
EntityStream entityStream = EntityStreams.newEntityStream(new BytesWriter(totalBytes, BYTE));
StreamRequestBuilder builder = new StreamRequestBuilder(_clientProvider.createHttpURI(_port, URI.create("/boo")));
StreamRequest request = builder.setMethod("POST").build(entityStream);
final AtomicInteger status = new AtomicInteger(-1);
final CountDownLatch latch = new CountDownLatch(1);
Callback<StreamResponse> callback = expectErrorCallback(latch, status);
_client.streamRequest(request, callback);
latch.await(60000, TimeUnit.MILLISECONDS);
Assert.assertEquals(status.get(), 404);
}
use of test.r2.integ.helper.BytesWriter in project rest.li by linkedin.
the class TestStreamEcho method testNormalEcho.
private void testNormalEcho(long bytesNum, URI uri) throws Exception {
BytesWriter writer = new BytesWriter(bytesNum, BYTE);
StreamRequest request = new StreamRequestBuilder(_clientProvider.createHttpURI(_port, uri)).build(EntityStreams.newEntityStream(writer));
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(60000, TimeUnit.MILLISECONDS);
Assert.assertNull(error.get());
Assert.assertEquals(status.get(), RestStatus.OK);
Assert.assertEquals(reader.getTotalBytes(), bytesNum);
Assert.assertTrue(reader.allBytesCorrect());
}
use of test.r2.integ.helper.BytesWriter in project rest.li by linkedin.
the class TestStreamingTimeout method testStreamTimeoutWithStreamingTimeoutInServerStream.
@Test
public void testStreamTimeoutWithStreamingTimeoutInServerStream() throws Exception {
final EntityStream entityStream = EntityStreams.newEntityStream(new BytesWriter(SMALL_BYTES_NUM, BYTE));
final StreamRequestBuilder builder = new StreamRequestBuilder(_clientProvider.createHttpURI(_port, RATE_LIMITED_URI));
final StreamRequest request = builder.setMethod("POST").build(entityStream);
final AtomicReference<Throwable> throwable = new AtomicReference<>();
final CountDownLatch latch = new CountDownLatch(1);
final Callback<StreamResponse> callback = expectErrorCallback(latch, throwable);
_client.streamRequest(request, callback);
latch.await(HTTP_REQUEST_TIMEOUT, TimeUnit.MILLISECONDS);
Assert.assertNotNull(throwable.get());
final Throwable rootCause = ExceptionUtils.getRootCause(throwable.get());
Assert.assertTrue(rootCause instanceof TimeoutException);
final TimeoutException timeoutException = (TimeoutException) rootCause;
Assert.assertEquals(timeoutException.getMessage(), String.format(StreamingTimeout.STREAMING_TIMEOUT_MESSAGE, HTTP_STREAMING_TIMEOUT));
}
use of test.r2.integ.helper.BytesWriter in project rest.li by linkedin.
the class TestStreamingTimeout method testStreamTimeoutWhenGreaterThanRequestTimeout.
@Test
public void testStreamTimeoutWhenGreaterThanRequestTimeout() throws Exception {
final EntityStream entityStream = EntityStreams.newEntityStream(new BytesWriter(SMALL_BYTES_NUM, BYTE));
final StreamRequestBuilder builder = new StreamRequestBuilder(_clientProvider.createHttpURI(_port, RATE_LIMITED_URI));
final StreamRequest request = builder.setMethod("POST").build(entityStream);
final AtomicReference<Throwable> throwable = new AtomicReference<>();
final CountDownLatch latch = new CountDownLatch(1);
final Callback<StreamResponse> callback = expectErrorCallback(latch, throwable);
Map<String, Object> clientProperties = getHttpClientProperties();
clientProperties.put(HttpClientFactory.HTTP_REQUEST_TIMEOUT, String.valueOf(HTTP_STREAMING_TIMEOUT));
clientProperties.put(HttpClientFactory.HTTP_STREAMING_TIMEOUT, String.valueOf(HTTP_STREAMING_TIMEOUT));
Client client = _clientProvider.createClient(getClientFilterChain(), clientProperties);
client.streamRequest(request, callback);
latch.await(HTTP_REQUEST_TIMEOUT, TimeUnit.MILLISECONDS);
Assert.assertNotNull(throwable.get());
final Throwable rootCause = ExceptionUtils.getRootCause(throwable.get());
Assert.assertTrue(rootCause instanceof TimeoutException);
final TimeoutException timeoutException = (TimeoutException) rootCause;
Assert.assertEquals(timeoutException.getMessage(), String.format(REQUEST_TIMEOUT_MESSAGE, HTTP_STREAMING_TIMEOUT));
tearDown(client);
}
use of test.r2.integ.helper.BytesWriter in project rest.li by linkedin.
the class TestStreamingTimeout method testStreamTimeoutWithStreamTimeoutInClientStream.
@Test
public void testStreamTimeoutWithStreamTimeoutInClientStream() throws Exception {
final EntityStream entityStream = EntityStreams.newEntityStream(new BytesWriter(LARGE_BYTES_NUM, BYTE) {
int count = 2;
@Override
protected void afterWrite(WriteHandle wh, long written) {
count = count * 2;
long delay = Math.min(count, HTTP_STREAMING_TIMEOUT);
try {
Thread.sleep(delay);
} catch (Exception ex) {
// Do Nothing
}
}
});
final StreamRequestBuilder builder = new StreamRequestBuilder(_clientProvider.createHttpURI(_port, NON_RATE_LIMITED_URI));
final StreamRequest request = builder.setMethod("POST").build(entityStream);
final AtomicReference<Throwable> throwable = new AtomicReference<>();
final CountDownLatch latch = new CountDownLatch(1);
final Callback<StreamResponse> callback = expectErrorCallback(latch, throwable);
_client.streamRequest(request, callback);
latch.await(30000, TimeUnit.MILLISECONDS);
Assert.assertNotNull(throwable.get());
final Throwable rootCause = ExceptionUtils.getRootCause(throwable.get());
Assert.assertTrue(rootCause instanceof TimeoutException);
final TimeoutException timeoutException = (TimeoutException) rootCause;
Assert.assertEquals(timeoutException.getMessage(), String.format(StreamingTimeout.STREAMING_TIMEOUT_MESSAGE, HTTP_STREAMING_TIMEOUT));
}
Aggregations