use of com.linkedin.multipart.exceptions.SinglePartFinishedException in project rest.li by linkedin.
the class TestMIMEReaderR2Error method testMidProcessingR2Error.
//This test will verify that, in the middle of normal processing, we are able to handle R2
//errors gracefully. We simulate a pause in the middle of normal processing by counting down the latch
//in the callbacks in the middle of the 2nd part.
@Test
public void testMidProcessingR2Error() throws Exception {
MimeMultipart multiPartMimeBody = new MimeMultipart();
multiPartMimeBody.addBodyPart(LARGE_DATA_SOURCE);
multiPartMimeBody.addBodyPart(LARGE_DATA_SOURCE);
multiPartMimeBody.addBodyPart(LARGE_DATA_SOURCE);
multiPartMimeBody.addBodyPart(LARGE_DATA_SOURCE);
multiPartMimeBody.addBodyPart(LARGE_DATA_SOURCE);
multiPartMimeBody.addBodyPart(LARGE_DATA_SOURCE);
final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
multiPartMimeBody.writeTo(byteArrayOutputStream);
final ByteString requestPayload = ByteString.copy(byteArrayOutputStream.toByteArray());
CountDownLatch countDownLatch = executeRequestPartialReadWithException(requestPayload, 1, multiPartMimeBody.getContentType());
countDownLatch.await(_testTimeout, TimeUnit.MILLISECONDS);
//When this returns, its partially complete
//In this point in time let us simulate an R2 error
_reader.getR2MultiPartMIMEReader().onError(new NullPointerException());
Assert.assertTrue(_currentMultiPartMIMEReaderCallback._streamError instanceof NullPointerException);
try {
_currentMultiPartMIMEReaderCallback._singlePartMIMEReaderCallbacks.get(0)._singlePartMIMEReader.requestPartData();
Assert.fail();
} catch (SinglePartFinishedException singlePartFinishedException) {
//pass
}
Assert.assertEquals(_currentMultiPartMIMEReaderCallback._singlePartMIMEReaderCallbacks.size(), 2);
Assert.assertNull(_currentMultiPartMIMEReaderCallback._singlePartMIMEReaderCallbacks.get(0)._streamError);
Assert.assertTrue(_currentMultiPartMIMEReaderCallback._singlePartMIMEReaderCallbacks.get(1)._streamError instanceof NullPointerException);
try {
_currentMultiPartMIMEReaderCallback._singlePartMIMEReaderCallbacks.get(1)._singlePartMIMEReader.requestPartData();
Assert.fail();
} catch (SinglePartFinishedException singlePartFinishedException) {
//pass
}
}
use of com.linkedin.multipart.exceptions.SinglePartFinishedException in project rest.li by linkedin.
the class TestMIMEReaderClientCallbackExceptions method testMultiPartMIMEReaderCallbackExceptionOnFinished.
@Test(dataProvider = "allTypesOfBodiesDataSource")
public void testMultiPartMIMEReaderCallbackExceptionOnFinished(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_FINISHED, SinglePartMIMEThrowOnFlag.NO_THROW);
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(), 6);
//callback threw
for (int i = 0; i < _currentMultiPartMIMEReaderCallback.getSinglePartMIMEReaderCallbacks().size(); i++) {
Assert.assertNull(_currentMultiPartMIMEReaderCallback.getSinglePartMIMEReaderCallbacks().get(i).getStreamError());
//Verify this is unusable.
try {
_currentMultiPartMIMEReaderCallback.getSinglePartMIMEReaderCallbacks().get(i).getSinglePartMIMEReader().requestPartData();
Assert.fail();
} catch (SinglePartFinishedException singlePartFinishedException) {
//pass
}
}
}
Aggregations