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));
}
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;
}
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());
}
Aggregations