Search in sources :

Example 6 with MIMEDataPart

use of com.linkedin.multipart.utils.MIMEDataPart in project rest.li by linkedin.

the class TestMIMEIntegrationReaderWriter method executeRequestAndAssert.

// /////////////////////////////////////////////////////////////////////////////////////
// This method will execute a StreamRequest using a payload comprised of the provided MultiPartMIMEWriter. The request
// makes its way to a server which will read all the parts one by one and store them in a list. Subsequently,
// an assertion is performed to make sure that each part was read and saved properly on the server.
private void executeRequestAndAssert(final MultiPartMIMEWriter requestWriter, final List<MIMEDataPart> expectedParts) throws Exception {
    final StreamRequest streamRequest = MultiPartMIMEStreamRequestFactory.generateMultiPartMIMEStreamRequest(Bootstrap.createHttpURI(PORT, SERVER_URI), "mixed", requestWriter, Collections.<String, String>emptyMap());
    final AtomicInteger status = new AtomicInteger(-1);
    final CountDownLatch latch = new CountDownLatch(1);
    Callback<StreamResponse> callback = expectSuccessCallback(latch, status, new HashMap<>());
    _client.streamRequest(streamRequest, callback);
    latch.await(TEST_TIMEOUT, TimeUnit.MILLISECONDS);
    Assert.assertEquals(status.get(), RestStatus.OK);
    List<SinglePartMIMEReaderCallbackImpl> singlePartMIMEReaderCallbacks = _mimeServerRequestHandler.getTestMultiPartMIMEReaderCallback().getSinglePartMIMEReaderCallbacks();
    _mimeServerRequestHandler.getTestMultiPartMIMEReaderCallback().getSinglePartMIMEReaderCallbacks();
    Assert.assertEquals(singlePartMIMEReaderCallbacks.size(), expectedParts.size());
    for (int i = 0; i < singlePartMIMEReaderCallbacks.size(); i++) {
        // Actual
        final SinglePartMIMEReaderCallbackImpl currentCallback = singlePartMIMEReaderCallbacks.get(i);
        // Expected
        final MIMEDataPart currentExpectedPart = expectedParts.get(i);
        Assert.assertEquals(currentCallback.getHeaders(), currentExpectedPart.getPartHeaders());
        Assert.assertEquals(currentCallback.getFinishedData(), currentExpectedPart.getPartData());
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) StreamResponse(com.linkedin.r2.message.stream.StreamResponse) MIMEDataPart(com.linkedin.multipart.utils.MIMEDataPart) CountDownLatch(java.util.concurrent.CountDownLatch) StreamRequest(com.linkedin.r2.message.stream.StreamRequest)

Aggregations

MIMEDataPart (com.linkedin.multipart.utils.MIMEDataPart)6 ByteString (com.linkedin.data.ByteString)5 StreamRequest (com.linkedin.r2.message.stream.StreamRequest)4 BeforeTest (org.testng.annotations.BeforeTest)4 FutureCallback (com.linkedin.common.callback.FutureCallback)3 FullEntityReader (com.linkedin.r2.message.stream.entitystream.FullEntityReader)3 Test (org.testng.annotations.Test)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 StreamResponse (com.linkedin.r2.message.stream.StreamResponse)1 ArrayList (java.util.ArrayList)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 BeforeClass (org.testng.annotations.BeforeClass)1