Search in sources :

Example 1 with MultiPartMIMEDataSourceWriter

use of com.linkedin.multipart.MultiPartMIMEDataSourceWriter in project rest.li by linkedin.

the class TestMIMEIntegrationReaderWriter method testEachSingleBodyDataSourceMultipleTimes.

@Test(dataProvider = "eachSingleBodyDataSource", enabled = false)
public void testEachSingleBodyDataSourceMultipleTimes(final int chunkSize, final MIMEDataPart bodyPart) throws Exception {
    final List<MultiPartMIMEDataSourceWriter> dataSources = new ArrayList<MultiPartMIMEDataSourceWriter>();
    for (int i = 0; i < 4; i++) {
        final MultiPartMIMEInputStream inputStreamDataSource = new MultiPartMIMEInputStream.Builder(new ByteArrayInputStream(bodyPart.getPartData().copyBytes()), scheduledExecutorService, bodyPart.getPartHeaders()).withWriteChunkSize(chunkSize).build();
        dataSources.add(inputStreamDataSource);
    }
    final MultiPartMIMEWriter writer = new MultiPartMIMEWriter.Builder("some preamble", "").appendDataSources(dataSources).build();
    executeRequestAndAssert(writer, ImmutableList.of(bodyPart, bodyPart, bodyPart, bodyPart));
}
Also used : MultiPartMIMEDataSourceWriter(com.linkedin.multipart.MultiPartMIMEDataSourceWriter) ByteArrayInputStream(java.io.ByteArrayInputStream) TransportDispatcherBuilder(com.linkedin.r2.transport.common.bridge.server.TransportDispatcherBuilder) ArrayList(java.util.ArrayList) MultiPartMIMEWriter(com.linkedin.multipart.MultiPartMIMEWriter) MultiPartMIMEInputStream(com.linkedin.multipart.MultiPartMIMEInputStream) Test(org.testng.annotations.Test)

Example 2 with MultiPartMIMEDataSourceWriter

use of com.linkedin.multipart.MultiPartMIMEDataSourceWriter in project rest.li by linkedin.

the class MIMETestUtils method generateInputStreamDataSources.

//The chaining tests will use these:
public static List<MultiPartMIMEDataSourceWriter> generateInputStreamDataSources(final int chunkSize, final ExecutorService executorService) {
    final MultiPartMIMEInputStream bodyADataSource = new MultiPartMIMEInputStream.Builder(new ByteArrayInputStream(BODY_A.getPartData().copyBytes()), executorService, BODY_A.getPartHeaders()).withWriteChunkSize(chunkSize).build();
    final MultiPartMIMEInputStream bodyBDataSource = new MultiPartMIMEInputStream.Builder(new ByteArrayInputStream(BODY_B.getPartData().copyBytes()), executorService, BODY_B.getPartHeaders()).withWriteChunkSize(chunkSize).build();
    final MultiPartMIMEInputStream bodyCDataSource = new MultiPartMIMEInputStream.Builder(new ByteArrayInputStream(BODY_C.getPartData().copyBytes()), executorService, BODY_C.getPartHeaders()).withWriteChunkSize(chunkSize).build();
    final MultiPartMIMEInputStream bodyDDataSource = new MultiPartMIMEInputStream.Builder(new ByteArrayInputStream(BODY_D.getPartData().copyBytes()), executorService, BODY_D.getPartHeaders()).withWriteChunkSize(chunkSize).build();
    final List<MultiPartMIMEDataSourceWriter> dataSources = new ArrayList<MultiPartMIMEDataSourceWriter>();
    dataSources.add(bodyADataSource);
    dataSources.add(bodyBDataSource);
    dataSources.add(bodyCDataSource);
    dataSources.add(bodyDDataSource);
    return dataSources;
}
Also used : MultiPartMIMEDataSourceWriter(com.linkedin.multipart.MultiPartMIMEDataSourceWriter) ByteArrayInputStream(java.io.ByteArrayInputStream) ArrayList(java.util.ArrayList) MultiPartMIMEInputStream(com.linkedin.multipart.MultiPartMIMEInputStream)

Example 3 with MultiPartMIMEDataSourceWriter

use of com.linkedin.multipart.MultiPartMIMEDataSourceWriter in project rest.li by linkedin.

the class TestMIMEChainingMultipleSources method testSinglePartDataSource.

//Test breakdown:
//1. Main thread sends mime request
//2. Server A sends a simple POST request to Server B
//3. Server B sends back a mime response to Server A
//4. Server A takes the original incoming request from the main thread + a local input
//stream + the first part from the incoming mime response from Server B.
//5. Main thread then gets all of this and stores it.
//6. Server A then drains and stores the rest of the parts from Server B's response.
@Test(dataProvider = "chunkSizes", groups = TESTNG_GROUP_KNOWN_ISSUE)
public void testSinglePartDataSource(final int chunkSize) throws Exception {
    _chunkSize = chunkSize;
    final List<MultiPartMIMEDataSourceWriter> dataSources = generateInputStreamDataSources(chunkSize, _scheduledExecutorService);
    final MultiPartMIMEWriter writer = new MultiPartMIMEWriter.Builder().appendDataSources(dataSources).build();
    final StreamRequest streamRequest = MultiPartMIMEStreamRequestFactory.generateMultiPartMIMEStreamRequest(Bootstrap.createHttpsURI(PORT_SERVER_A, SERVER_A_URI), "mixed", writer, Collections.<String, String>emptyMap());
    ClientMultiPartReceiver clientReceiver = new ClientMultiPartReceiver();
    Callback<StreamResponse> callback = generateSuccessChainCallback(clientReceiver);
    //Send the request to Server A
    _client.streamRequest(streamRequest, callback);
    _latch.await(TEST_TIMEOUT, TimeUnit.MILLISECONDS);
    //Verify client
    List<MIMETestUtils.SinglePartMIMEFullReaderCallback> clientSinglePartCallbacks = clientReceiver.getSinglePartMIMEReaderCallbacks();
    Assert.assertEquals(clientReceiver.getSinglePartMIMEReaderCallbacks().size(), 6);
    Assert.assertEquals(clientSinglePartCallbacks.get(0).getFinishedData(), BODY_1.getPartData());
    Assert.assertEquals(clientSinglePartCallbacks.get(0).getHeaders(), BODY_1.getPartHeaders());
    Assert.assertEquals(clientSinglePartCallbacks.get(1).getFinishedData(), BODY_5.getPartData());
    Assert.assertEquals(clientSinglePartCallbacks.get(1).getHeaders(), BODY_5.getPartHeaders());
    Assert.assertEquals(clientSinglePartCallbacks.get(2).getFinishedData(), BODY_A.getPartData());
    Assert.assertEquals(clientSinglePartCallbacks.get(2).getHeaders(), BODY_A.getPartHeaders());
    Assert.assertEquals(clientSinglePartCallbacks.get(3).getFinishedData(), BODY_B.getPartData());
    Assert.assertEquals(clientSinglePartCallbacks.get(3).getHeaders(), BODY_B.getPartHeaders());
    Assert.assertEquals(clientSinglePartCallbacks.get(4).getFinishedData(), BODY_C.getPartData());
    Assert.assertEquals(clientSinglePartCallbacks.get(4).getHeaders(), BODY_C.getPartHeaders());
    Assert.assertEquals(clientSinglePartCallbacks.get(5).getFinishedData(), BODY_D.getPartData());
    Assert.assertEquals(clientSinglePartCallbacks.get(5).getHeaders(), BODY_D.getPartHeaders());
    //Verify Server A
    List<MIMETestUtils.SinglePartMIMEFullReaderCallback> serverASinglePartCallbacks = _serverAMultiPartCallback.getSinglePartMIMEReaderCallbacks();
    Assert.assertEquals(serverASinglePartCallbacks.size(), 3);
    Assert.assertEquals(serverASinglePartCallbacks.get(0).getFinishedData(), BODY_2.getPartData());
    Assert.assertEquals(serverASinglePartCallbacks.get(0).getHeaders(), BODY_2.getPartHeaders());
    Assert.assertEquals(serverASinglePartCallbacks.get(1).getFinishedData(), BODY_3.getPartData());
    Assert.assertEquals(serverASinglePartCallbacks.get(1).getHeaders(), BODY_3.getPartHeaders());
    Assert.assertEquals(serverASinglePartCallbacks.get(2).getFinishedData(), BODY_4.getPartData());
    Assert.assertEquals(serverASinglePartCallbacks.get(2).getHeaders(), BODY_4.getPartHeaders());
}
Also used : MultiPartMIMEDataSourceWriter(com.linkedin.multipart.MultiPartMIMEDataSourceWriter) TransportDispatcherBuilder(com.linkedin.r2.transport.common.bridge.server.TransportDispatcherBuilder) StreamRequestBuilder(com.linkedin.r2.message.stream.StreamRequestBuilder) StreamResponse(com.linkedin.r2.message.stream.StreamResponse) MultiPartMIMEWriter(com.linkedin.multipart.MultiPartMIMEWriter) StreamRequest(com.linkedin.r2.message.stream.StreamRequest) Test(org.testng.annotations.Test)

Aggregations

MultiPartMIMEDataSourceWriter (com.linkedin.multipart.MultiPartMIMEDataSourceWriter)3 MultiPartMIMEInputStream (com.linkedin.multipart.MultiPartMIMEInputStream)2 MultiPartMIMEWriter (com.linkedin.multipart.MultiPartMIMEWriter)2 TransportDispatcherBuilder (com.linkedin.r2.transport.common.bridge.server.TransportDispatcherBuilder)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 ArrayList (java.util.ArrayList)2 Test (org.testng.annotations.Test)2 StreamRequest (com.linkedin.r2.message.stream.StreamRequest)1 StreamRequestBuilder (com.linkedin.r2.message.stream.StreamRequestBuilder)1 StreamResponse (com.linkedin.r2.message.stream.StreamResponse)1