Github user trixpan commented on a diff in the pull request: https://github.com/apache/nifi/pull/1553#discussion_r104170950 --- Diff: nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestPutEmail.java --- @@ -230,27 +234,42 @@ public void testOutgoingMessageAttachment() throws Exception { runner.assertAllFlowFilesTransferred(PutEmail.REL_SUCCESS); // Verify that the Message was populated correctly - assertEquals("Expected a single message to be sent", 1, processor.getMessages().size()); - Message message = processor.getMessages().get(0); - assertEquals("t...@apache.org", message.getFrom()[0].toString()); - assertEquals("X-Mailer Header", "TestingNiFi", message.getHeader("X-Mailer")[0]); - assertEquals("recipi...@apache.org", message.getRecipients(RecipientType.TO)[0].toString()); - - assertTrue(message.getContent() instanceof MimeMultipart); - - final MimeMultipart multipart = (MimeMultipart) message.getContent(); - final BodyPart part = multipart.getBodyPart(0); - final InputStream is = part.getDataHandler().getInputStream(); - final String decodedText = StringUtils.newStringUtf8(Base64.decodeBase64(IOUtils.toString(is, "UTF-8"))); - assertEquals("Message Body", decodedText); - - final BodyPart attachPart = multipart.getBodyPart(1); - final InputStream attachIs = attachPart.getDataHandler().getInputStream(); - final String text = IOUtils.toString(attachIs, "UTF-8"); - assertEquals("Some text", text); - - assertNull(message.getRecipients(RecipientType.BCC)); - assertNull(message.getRecipients(RecipientType.CC)); + assertEquals("Expected a single message to be sent", 1, smtpRunner.getFlowFilesForRelationship(PutEmail.REL_SUCCESS).size()); + + MockFlowFile message; + + message = smtpRunner.getFlowFilesForRelationship(PutEmail.REL_SUCCESS).get(0); + + extractHeadersRunner.enqueue(message); + extractHeadersRunner.run(); + extractHeadersRunner.shutdown(); + + message = extractHeadersRunner.getFlowFilesForRelationship(ExtractEmailHeaders.REL_SUCCESS).get(0); + + assertEquals("t...@apache.org", message.getAttribute("email.headers.from.0")); + assertEquals("X-Mailer Header", "TestingNiFi", message.getAttribute("email.headers.x-mailer")); + + // Needed in order to avoid errors like + // "already in use for an active callback or InputStream created by ProcessSession.read(FlowFile) has not been closed" + + + message = extractHeadersRunner.getFlowFilesForRelationship(ExtractEmailHeaders.REL_SUCCESS).get(0); + +// extractAttachmentsRunner.enqueue(message); +// extractAttachmentsRunner.run(); +// +// final List<MockFlowFile> splits = extractAttachmentsRunner.getFlowFilesForRelationship(ExtractEmailAttachments.REL_ATTACHMENTS); +// +// final MimeMultipart multipart = (MimeMultipart) message.getContent(); +// final BodyPart part = multipart.getBodyPart(0); +// final InputStream is = part.getDataHandler().getInputStream(); +// final String decodedText = StringUtils.newStringUtf8(Base64.decodeBase64(IOUtils.toString(is, "UTF-8"))); +// assertEquals("Message Body", decodedText); +// +// final BodyPart attachPart = multipart.getBodyPart(1); +// final InputStream attachIs = attachPart.getDataHandler().getInputStream(); +// final String text = IOUtils.toString(attachIs, "UTF-8"); +// assertEquals("Some text", text); --- End diff -- @olegz @bbende has shed some light and the issue seems to be caused by the way TestRunner/MockFlowFile works: Feeding a runner with flowfiles from a distinct processor may cause some issues like the one observed. Tested the theory using SplitText instead of ExtractEmailAttributes and a similar error message arises: ``` [pool-3-thread-1] INFO org.apache.nifi.processors.standard.GetFile - GetFile[id=21d110fa-75a0-4cc8-b425-af6c55f352df] added FlowFile[0,sample.msg,893B] to flow [pool-4-thread-1] ERROR org.apache.nifi.processors.standard.SplitText - SplitText[id=e064a6bb-5640-4008-b490-4e6b127244af] SplitText[id=e064a6bb-5640-4008-b490-4e6b127244af] failed to process due to org.apache.nifi.processor.exception.FlowFileHandlingException: FlowFile[0,sample.msg,893B] is not the most recent version of this flow file within this session; rolling back session: org.apache.nifi.processor.exception.FlowFileHandlingException: FlowFile[0,sample.msg,893B] is not the most recent version of this flow file within this session java.lang.AssertionError: org.apache.nifi.processor.exception.FlowFileHandlingException: FlowFile[0,sample.msg,893B] is not the most recent version of this flow file within this session ``` Will continue the test migration and let you know when ready for review. Cheers
--- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---