Search in sources :

Example 1 with MultiPartMIMEInputStream

use of com.linkedin.multipart.MultiPartMIMEInputStream 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<>();
    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, Collections.unmodifiableList(Arrays.asList(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 MultiPartMIMEInputStream

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

the class TestMIMEIntegrationReaderWriter method testMultipleBodies.

@Test(dataProvider = "chunkSizes")
public void testMultipleBodies(final int chunkSize) throws Exception {
    final MultiPartMIMEInputStream normalBodyInputStream = new MultiPartMIMEInputStream.Builder(new ByteArrayInputStream(_normalBody.getPartData().copyBytes()), scheduledExecutorService, _normalBody.getPartHeaders()).withWriteChunkSize(chunkSize).build();
    final MultiPartMIMEInputStream headerLessBodyInputStream = new MultiPartMIMEInputStream.Builder(new ByteArrayInputStream(_headerLessBody.getPartData().copyBytes()), scheduledExecutorService, _headerLessBody.getPartHeaders()).withWriteChunkSize(chunkSize).build();
    // Copying over empty ByteString, but let's keep things consistent.
    final MultiPartMIMEInputStream bodyLessBodyInputStream = new MultiPartMIMEInputStream.Builder(new ByteArrayInputStream(_bodyLessBody.getPartData().copyBytes()), scheduledExecutorService, _bodyLessBody.getPartHeaders()).withWriteChunkSize(chunkSize).build();
    final MultiPartMIMEInputStream purelyEmptyBodyInputStream = new MultiPartMIMEInputStream.Builder(new ByteArrayInputStream(_purelyEmptyBody.getPartData().copyBytes()), scheduledExecutorService, _purelyEmptyBody.getPartHeaders()).withWriteChunkSize(chunkSize).build();
    final MultiPartMIMEWriter writer = new MultiPartMIMEWriter.Builder("some preamble", "").appendDataSource(normalBodyInputStream).appendDataSource(headerLessBodyInputStream).appendDataSource(bodyLessBodyInputStream).appendDataSource(purelyEmptyBodyInputStream).build();
    executeRequestAndAssert(writer, Collections.unmodifiableList(Arrays.asList(_normalBody, _headerLessBody, _bodyLessBody, _purelyEmptyBody)));
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) TransportDispatcherBuilder(com.linkedin.r2.transport.common.bridge.server.TransportDispatcherBuilder) MultiPartMIMEWriter(com.linkedin.multipart.MultiPartMIMEWriter) MultiPartMIMEInputStream(com.linkedin.multipart.MultiPartMIMEInputStream) Test(org.testng.annotations.Test)

Example 3 with MultiPartMIMEInputStream

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

the class TestMIMEIntegrationReaderWriter method testEachSingleBodyDataSource.

@Test(dataProvider = "eachSingleBodyDataSource", enabled = false)
public void testEachSingleBodyDataSource(final int chunkSize, final MIMEDataPart bodyPart) throws Exception {
    final MultiPartMIMEInputStream inputStreamDataSource = new MultiPartMIMEInputStream.Builder(new ByteArrayInputStream(bodyPart.getPartData().copyBytes()), scheduledExecutorService, bodyPart.getPartHeaders()).withWriteChunkSize(chunkSize).build();
    final MultiPartMIMEWriter writer = new MultiPartMIMEWriter.Builder("some preamble", "").appendDataSource(inputStreamDataSource).build();
    executeRequestAndAssert(writer, Collections.unmodifiableList(Collections.singletonList(bodyPart)));
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) TransportDispatcherBuilder(com.linkedin.r2.transport.common.bridge.server.TransportDispatcherBuilder) MultiPartMIMEWriter(com.linkedin.multipart.MultiPartMIMEWriter) MultiPartMIMEInputStream(com.linkedin.multipart.MultiPartMIMEInputStream) Test(org.testng.annotations.Test)

Example 4 with MultiPartMIMEInputStream

use of com.linkedin.multipart.MultiPartMIMEInputStream 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<>();
    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)

Aggregations

MultiPartMIMEInputStream (com.linkedin.multipart.MultiPartMIMEInputStream)4 ByteArrayInputStream (java.io.ByteArrayInputStream)4 MultiPartMIMEWriter (com.linkedin.multipart.MultiPartMIMEWriter)3 TransportDispatcherBuilder (com.linkedin.r2.transport.common.bridge.server.TransportDispatcherBuilder)3 Test (org.testng.annotations.Test)3 MultiPartMIMEDataSourceWriter (com.linkedin.multipart.MultiPartMIMEDataSourceWriter)2 ArrayList (java.util.ArrayList)2