Support Questions

Find answers, ask questions, and share your expertise
Announcements
Celebrating as our community reaches 100,000 members! Thank you!

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

avatar
Master Collaborator

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

1 ACCEPTED SOLUTION

avatar
Master Collaborator
testRunner.setAllowSynchronousSessionCommits(true);

Helped me to get rid of this error 

View solution in original post

1 REPLY 1

avatar
Master Collaborator
testRunner.setAllowSynchronousSessionCommits(true);

Helped me to get rid of this error