Search in sources :

Example 1 with BytesReader

use of test.r2.integ.helper.BytesReader 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());
}
Also used : EntityStream(com.linkedin.r2.message.stream.entitystream.EntityStream) TimedBytesWriter(test.r2.integ.helper.TimedBytesWriter) BytesWriter(test.r2.integ.helper.BytesWriter) BytesReader(test.r2.integ.helper.BytesReader) TimedBytesReader(test.r2.integ.helper.TimedBytesReader) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) StreamResponse(com.linkedin.r2.message.stream.StreamResponse) CountDownLatch(java.util.concurrent.CountDownLatch) StreamRequestBuilder(com.linkedin.r2.message.stream.StreamRequestBuilder) StreamRequest(com.linkedin.r2.message.stream.StreamRequest) Test(org.testng.annotations.Test) AbstractServiceTest(test.r2.integ.clientserver.providers.AbstractServiceTest)

Example 2 with BytesReader

use of test.r2.integ.helper.BytesReader in project rest.li by linkedin.

the class TestStreamResponseCompression method testResponseCompression.

private void testResponseCompression(URI uri, long bytes, String acceptEncoding) throws InterruptedException, TimeoutException, ExecutionException {
    StreamRequestBuilder builder = new StreamRequestBuilder((_clientProvider.createHttpURI(_port, uri)));
    builder.addHeaderValue(HttpConstants.ACCEPT_ENCODING, acceptEncoding);
    StreamRequest request = builder.build(EntityStreams.emptyStream());
    final FutureCallback<StreamResponse> callback = new FutureCallback<>();
    _client.streamRequest(request, 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);
    final EntityStream decompressedStream = response.getEntityStream();
    decompressedStream.setReader(reader);
    readerCallback.get(60, TimeUnit.SECONDS);
    Assert.assertEquals(reader.getTotalBytes(), bytes);
    Assert.assertTrue(reader.allBytesCorrect());
}
Also used : EntityStream(com.linkedin.r2.message.stream.entitystream.EntityStream) BytesReader(test.r2.integ.helper.BytesReader) StreamResponse(com.linkedin.r2.message.stream.StreamResponse) StreamRequestBuilder(com.linkedin.r2.message.stream.StreamRequestBuilder) None(com.linkedin.common.util.None) FutureCallback(com.linkedin.common.callback.FutureCallback) StreamRequest(com.linkedin.r2.message.stream.StreamRequest)

Example 3 with BytesReader

use of test.r2.integ.helper.BytesReader 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());
}
Also used : BytesWriter(test.r2.integ.helper.BytesWriter) BytesReader(test.r2.integ.helper.BytesReader) StreamResponse(com.linkedin.r2.message.stream.StreamResponse) RequestContext(com.linkedin.r2.message.RequestContext) StreamRequestBuilder(com.linkedin.r2.message.stream.StreamRequestBuilder) None(com.linkedin.common.util.None) FutureCallback(com.linkedin.common.callback.FutureCallback) StreamRequest(com.linkedin.r2.message.stream.StreamRequest) Test(org.testng.annotations.Test) AbstractServiceTest(test.r2.integ.clientserver.providers.AbstractServiceTest)

Example 4 with BytesReader

use of test.r2.integ.helper.BytesReader 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());
}
Also used : TimedBytesWriter(test.r2.integ.helper.TimedBytesWriter) BytesWriter(test.r2.integ.helper.BytesWriter) StreamResponse(com.linkedin.r2.message.stream.StreamResponse) AtomicReference(java.util.concurrent.atomic.AtomicReference) CountDownLatch(java.util.concurrent.CountDownLatch) StreamRequestBuilder(com.linkedin.r2.message.stream.StreamRequestBuilder) StreamRequest(com.linkedin.r2.message.stream.StreamRequest) BytesReader(test.r2.integ.helper.BytesReader) TimedBytesReader(test.r2.integ.helper.TimedBytesReader) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) None(com.linkedin.common.util.None)

Example 5 with BytesReader

use of test.r2.integ.helper.BytesReader in project rest.li by linkedin.

the class TestStreamResponse method testResponse.

private void testResponse(URI uri) throws Exception {
    StreamRequestBuilder builder = new StreamRequestBuilder(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(60000, TimeUnit.MILLISECONDS);
    Assert.assertNull(error.get());
    Assert.assertEquals(status.get(), RestStatus.OK);
    Assert.assertEquals(reader.getTotalBytes(), LARGE_BYTES_NUM);
    Assert.assertTrue(reader.allBytesCorrect());
}
Also used : BytesReader(test.r2.integ.helper.BytesReader) TimedBytesReader(test.r2.integ.helper.TimedBytesReader) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) StreamResponse(com.linkedin.r2.message.stream.StreamResponse) AtomicReference(java.util.concurrent.atomic.AtomicReference) CountDownLatch(java.util.concurrent.CountDownLatch) StreamRequestBuilder(com.linkedin.r2.message.stream.StreamRequestBuilder) None(com.linkedin.common.util.None) StreamRequest(com.linkedin.r2.message.stream.StreamRequest)

Aggregations

StreamRequest (com.linkedin.r2.message.stream.StreamRequest)7 StreamRequestBuilder (com.linkedin.r2.message.stream.StreamRequestBuilder)7 StreamResponse (com.linkedin.r2.message.stream.StreamResponse)7 BytesReader (test.r2.integ.helper.BytesReader)7 None (com.linkedin.common.util.None)5 CountDownLatch (java.util.concurrent.CountDownLatch)5 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)5 TimedBytesReader (test.r2.integ.helper.TimedBytesReader)5 Test (org.testng.annotations.Test)4 AbstractServiceTest (test.r2.integ.clientserver.providers.AbstractServiceTest)4 BytesWriter (test.r2.integ.helper.BytesWriter)4 FutureCallback (com.linkedin.common.callback.FutureCallback)3 EntityStream (com.linkedin.r2.message.stream.entitystream.EntityStream)3 AtomicReference (java.util.concurrent.atomic.AtomicReference)3 TimedBytesWriter (test.r2.integ.helper.TimedBytesWriter)2 RequestContext (com.linkedin.r2.message.RequestContext)1 Client (com.linkedin.r2.transport.common.Client)1 HttpClientFactory (com.linkedin.r2.transport.http.client.HttpClientFactory)1 HashMap (java.util.HashMap)1