Skip to main content
hegdemahendra
Gold ⭐️⭐️
Jul 13, 2022 8:14 AM UTC
Solved

org.apache.nifi.util.TestRunners giving error in Nifi unit test - As of version 1.14.0, ProcessSession.commit() should be avoided when possible.

Hello Experts,

 

I am using org.apache.nifi.util.TestRunners in Nifi custom processor unit test cases, and code something like below..

 

Spoiler
testRunner = TestRunners.newTestRunner(O9QueueRouting.class);
.
.
.
.

MockFlowFile ff = this.testRunner.enqueue(new ByteArrayInputStream(ffContents.getBytes(StandardCharsets.UTF_8)));
Map<String, String> attrs = new HashMap<String, String>();
attrs.put("routingheader", "headervalue");
attrs.put("kafka.topic", "topic1");
ff.putAttributes(attrs);
testRunner.run();


It was working earlier now started giving error like below -

[ERROR] O9QueueRoutingTest.test:73 java.lang.RuntimeException: As of version 1.14.0, ProcessSession.commit() should be avoided when possible.
See JavaDocs for explanations. Instead, use commitAsync(), commitAsync(Runnable), or commitAsync(Runnable, Consumer<Throwable>). However, if this is not possible,
ProcessSession.commit() may still be used, but this must be explicitly enabled by calling TestRunner.

 

Any idea how this can be resolved ?
How to explicitly enable by calling TestRunner ?

Thanks
Mahendra

hegdemahendra
Gold ⭐️⭐️
Jul 14, 2022 10:25 AM UTC

testRunner.setAllowSynchronousSessionCommits(true);

Helped me to get rid of this error 

1 reply

hegdemahendra
hegdemahendraAuthorAnswer
Gold ⭐️⭐️
Jul 14, 2022 10:25 AM UTC

testRunner.setAllowSynchronousSessionCommits(true);

Helped me to get rid of this error 

Translate