use of javax.mail.internet.MimeBodyPart in project rest.li by linkedin.
the class TestMIMEReaderClientCallbackExceptions method testMultiPartMIMEReaderCallbackExceptionOnDrainComplete.
@Test(dataProvider = "allTypesOfBodiesDataSource")
public void testMultiPartMIMEReaderCallbackExceptionOnDrainComplete(final int chunkSize, final List<MimeBodyPart> bodyPartList) throws Exception {
MimeMultipart multiPartMimeBody = new MimeMultipart();
//Add your body parts
for (final MimeBodyPart bodyPart : bodyPartList) {
multiPartMimeBody.addBodyPart(bodyPart);
}
final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
multiPartMimeBody.writeTo(byteArrayOutputStream);
final ByteString requestPayload = ByteString.copy(byteArrayOutputStream.toByteArray());
final CountDownLatch countDownLatch = executeRequestPartialReadWithException(requestPayload, chunkSize, multiPartMimeBody.getContentType(), MultiPartMIMEThrowOnFlag.THROW_ON_DRAIN_COMPLETE, SinglePartMIMEThrowOnFlag.NO_THROW);
countDownLatch.await(_testTimeout, TimeUnit.MILLISECONDS);
Assert.assertTrue(_currentMultiPartMIMEReaderCallback.getStreamError() instanceof IllegalMonitorStateException);
Assert.assertEquals(_currentMultiPartMIMEReaderCallback.getSinglePartMIMEReaderCallbacks().size(), 0);
//Verify this is unusable.
try {
_currentMultiPartMIMEReaderCallback.getReader().drainAllParts();
Assert.fail();
} catch (MultiPartReaderFinishedException multiPartReaderFinishedException) {
//pass
}
}
use of javax.mail.internet.MimeBodyPart in project rest.li by linkedin.
the class TestMIMEReaderClientCallbackExceptions method testSinglePartMIMEReaderCallbackExceptionOnDrainComplete.
@Test(dataProvider = "allTypesOfBodiesDataSource")
public void testSinglePartMIMEReaderCallbackExceptionOnDrainComplete(final int chunkSize, final List<MimeBodyPart> bodyPartList) throws Exception {
MimeMultipart multiPartMimeBody = new MimeMultipart();
//Add your body parts
for (final MimeBodyPart bodyPart : bodyPartList) {
multiPartMimeBody.addBodyPart(bodyPart);
}
final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
multiPartMimeBody.writeTo(byteArrayOutputStream);
final ByteString requestPayload = ByteString.copy(byteArrayOutputStream.toByteArray());
final CountDownLatch countDownLatch = executeRequestPartialReadWithException(requestPayload, chunkSize, multiPartMimeBody.getContentType(), MultiPartMIMEThrowOnFlag.NO_THROW, SinglePartMIMEThrowOnFlag.THROW_ON_DRAIN_COMPLETE);
countDownLatch.await(_testTimeout, TimeUnit.MILLISECONDS);
Assert.assertTrue(_currentMultiPartMIMEReaderCallback.getStreamError() instanceof IllegalMonitorStateException);
//Verify these are unusable.
try {
_currentMultiPartMIMEReaderCallback.getReader().drainAllParts();
Assert.fail();
} catch (MultiPartReaderFinishedException multiPartReaderFinishedException) {
//pass
}
Assert.assertEquals(_currentMultiPartMIMEReaderCallback.getSinglePartMIMEReaderCallbacks().size(), 1);
Assert.assertTrue(_currentMultiPartMIMEReaderCallback.getSinglePartMIMEReaderCallbacks().get(0).getStreamError() instanceof IllegalMonitorStateException);
try {
_currentMultiPartMIMEReaderCallback.getSinglePartMIMEReaderCallbacks().get(0).getSinglePartMIMEReader().requestPartData();
Assert.fail();
} catch (SinglePartFinishedException singlePartFinishedException) {
//pass
}
}
use of javax.mail.internet.MimeBodyPart in project rest.li by linkedin.
the class TestMIMEReaderClientCallbackExceptions method testSinglePartMIMEReaderCallbackExceptionOnPartDataAvailable.
///////////////////////////////////////////////////////////////////////////////////////
//SinglePartMIMEReader callback invocations throwing exceptions:
//These tests all verify the resilience of the single part mime reader when single part mime reader client callbacks throw runtime exceptions
@Test(dataProvider = "allTypesOfBodiesDataSource")
public void testSinglePartMIMEReaderCallbackExceptionOnPartDataAvailable(final int chunkSize, final List<MimeBodyPart> bodyPartList) throws Exception {
MimeMultipart multiPartMimeBody = new MimeMultipart();
//Add your body parts
for (final MimeBodyPart bodyPart : bodyPartList) {
multiPartMimeBody.addBodyPart(bodyPart);
}
final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
multiPartMimeBody.writeTo(byteArrayOutputStream);
final ByteString requestPayload = ByteString.copy(byteArrayOutputStream.toByteArray());
final CountDownLatch countDownLatch = executeRequestPartialReadWithException(requestPayload, chunkSize, multiPartMimeBody.getContentType(), MultiPartMIMEThrowOnFlag.NO_THROW, SinglePartMIMEThrowOnFlag.THROW_ON_PART_DATA_AVAILABLE);
countDownLatch.await(_testTimeout, TimeUnit.MILLISECONDS);
Assert.assertTrue(_currentMultiPartMIMEReaderCallback.getStreamError() instanceof IllegalMonitorStateException);
//Verify this is unusable.
try {
_currentMultiPartMIMEReaderCallback.getReader().drainAllParts();
Assert.fail();
} catch (MultiPartReaderFinishedException multiPartReaderFinishedException) {
//pass
}
Assert.assertEquals(_currentMultiPartMIMEReaderCallback.getSinglePartMIMEReaderCallbacks().size(), 1);
Assert.assertTrue(_currentMultiPartMIMEReaderCallback.getSinglePartMIMEReaderCallbacks().get(0).getStreamError() instanceof IllegalMonitorStateException);
try {
_currentMultiPartMIMEReaderCallback.getSinglePartMIMEReaderCallbacks().get(0).getSinglePartMIMEReader().requestPartData();
Assert.fail();
} catch (SinglePartFinishedException singlePartFinishedException) {
//pass
}
}
use of javax.mail.internet.MimeBodyPart in project rest.li by linkedin.
the class TestMIMEReaderClientCallbackExceptions method testSinglePartMIMEReaderCallbackExceptionOnFinished.
@Test(dataProvider = "allTypesOfBodiesDataSource")
public void testSinglePartMIMEReaderCallbackExceptionOnFinished(final int chunkSize, final List<MimeBodyPart> bodyPartList) throws Exception {
MimeMultipart multiPartMimeBody = new MimeMultipart();
//Add your body parts
for (final MimeBodyPart bodyPart : bodyPartList) {
multiPartMimeBody.addBodyPart(bodyPart);
}
final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
multiPartMimeBody.writeTo(byteArrayOutputStream);
final ByteString requestPayload = ByteString.copy(byteArrayOutputStream.toByteArray());
final CountDownLatch countDownLatch = executeRequestPartialReadWithException(requestPayload, chunkSize, multiPartMimeBody.getContentType(), MultiPartMIMEThrowOnFlag.NO_THROW, SinglePartMIMEThrowOnFlag.THROW_ON_FINISHED);
countDownLatch.await(_testTimeout, TimeUnit.MILLISECONDS);
Assert.assertTrue(_currentMultiPartMIMEReaderCallback.getStreamError() instanceof IllegalMonitorStateException);
//Verify this is unusable.
try {
_currentMultiPartMIMEReaderCallback.getReader().drainAllParts();
Assert.fail();
} catch (MultiPartReaderFinishedException multiPartReaderFinishedException) {
//pass
}
Assert.assertEquals(_currentMultiPartMIMEReaderCallback.getSinglePartMIMEReaderCallbacks().size(), 1);
Assert.assertTrue(_currentMultiPartMIMEReaderCallback.getSinglePartMIMEReaderCallbacks().get(0).getStreamError() instanceof IllegalMonitorStateException);
try {
_currentMultiPartMIMEReaderCallback.getSinglePartMIMEReaderCallbacks().get(0).getSinglePartMIMEReader().requestPartData();
Assert.fail();
} catch (SinglePartFinishedException singlePartFinishedException) {
//pass
}
}
use of javax.mail.internet.MimeBodyPart in project rest.li by linkedin.
the class TestMIMEReaderDrain method executeRequestWithDrainStrategy.
///////////////////////////////////////////////////////////////////////////////////////
private void executeRequestWithDrainStrategy(final int chunkSize, final List<MimeBodyPart> bodyPartList, final String drainStrategy, final String serverHeaderPrefix) throws Exception {
MimeMultipart multiPartMimeBody = new MimeMultipart();
//Add your body parts
for (final MimeBodyPart bodyPart : bodyPartList) {
multiPartMimeBody.addBodyPart(bodyPart);
}
final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
multiPartMimeBody.writeTo(byteArrayOutputStream);
final ByteString requestPayload = ByteString.copy(byteArrayOutputStream.toByteArray());
_currentMimeMultipartBody = multiPartMimeBody;
mockR2AndWrite(requestPayload, chunkSize, multiPartMimeBody.getContentType());
final CountDownLatch latch = new CountDownLatch(1);
MultiPartMIMEReader reader = MultiPartMIMEReader.createAndAcquireStream(_streamRequest);
_currentMultiPartMIMEReaderCallback = new MultiPartMIMEDrainReaderCallbackImpl(latch, drainStrategy, reader);
reader.registerReaderCallback(_currentMultiPartMIMEReaderCallback);
latch.await(_testTimeout, TimeUnit.MILLISECONDS);
Assert.assertEquals(_currentMultiPartMIMEReaderCallback.getResponseHeaders().get(DRAIN_HEADER), serverHeaderPrefix + drainStrategy);
try {
reader.drainAllParts();
Assert.fail();
} catch (MultiPartReaderFinishedException multiPartReaderFinishedException) {
}
Assert.assertTrue(reader.haveAllPartsFinished());
//mock verifies
verify(_streamRequest, times(1)).getEntityStream();
verify(_streamRequest, times(1)).getHeader(HEADER_CONTENT_TYPE);
verify(_entityStream, times(1)).setReader(isA(MultiPartMIMEReader.R2MultiPartMIMEReader.class));
final int expectedRequests = (int) Math.ceil((double) requestPayload.length() / chunkSize);
//One more expected request because we have to make the last call to get called onDone().
verify(_readHandle, times(expectedRequests + 1)).request(1);
verifyNoMoreInteractions(_streamRequest);
verifyNoMoreInteractions(_entityStream);
verifyNoMoreInteractions(_readHandle);
}
Aggregations