[ https://issues.apache.org/jira/browse/NIFI-4686?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16289956#comment-16289956 ]
Mark Payne commented on NIFI-4686: ---------------------------------- [~jlwt90] Yes, I do believe it is a bug. Would be happy to review a PR if one is submitted. > MockFlowFile Penalized status is lost after putting attributes > -------------------------------------------------------------- > > Key: NIFI-4686 > URL: https://issues.apache.org/jira/browse/NIFI-4686 > Project: Apache NiFi > Issue Type: Bug > Reporter: jlwt90 > > Hello, > When I write unit tests to test whether a FlowFile is penalised after an > exception is thrown by an external resource, I find a possible issue in the > current *MockFlowFile* class. > I first penalized the FlowFile and put a *Error* attribute to the file > afterwards. The class attribute *penalized* will be reset after the calling > {code}session.putAttributes(xxx){code} function. > Here is the unit test I added to the test class *TestMockProcessSession*. > {code} > @Test > public void testKeepPenalizedStatusAfterPuttingAttribute(){ > final Processor processor = new PoorlyBehavedProcessor(); > final MockProcessSession session = new MockProcessSession(new > SharedSessionState(processor, new AtomicLong(0L)), processor); > FlowFile ff1 = session.createFlowFile("hello, world".getBytes()); > ff1 = session.penalize(ff1); > assertEquals(ff1.isPenalized(), true); > ff1 = session.putAttribute(ff1, "hello", "world"); > assertEquals(ff1.isPenalized(), true); > } > {code} > In the current MockFlowFile implementation: > {code} > public MockFlowFile(final long id, final FlowFile toCopy) {} > {code} > Class attribute *penalized* will not be copied and therefore, this test will > fail. > I think this behaviour is unexpected and checked how this logic is > implemented in *StandardFlowFileRecord*. > https://github.com/apache/nifi/blob/c138987bb46b975379daa00e57c42f498b6ef207/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-repository-models/src/main/java/org/apache/nifi/controller/repository/StandardFlowFileRecord.java#L320 > *Calling method in StandardProcessSession:* > https://github.com/apache/nifi/blob/c138987bb46b975379daa00e57c42f498b6ef207/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/repository/StandardProcessSession.java#L1756 > Could you please advise whether this is a bug? The fix is simple and I would > like to submit the change if needed. :) > Thanks! -- This message was sent by Atlassian JIRA (v6.4.14#64029)