You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@nifi.apache.org by Russell Bateman <ru...@windofkeltia.com> on 2020/08/31 13:01:35 UTC
TestRunner: enqueueing multiple flowfiles
In my JUnit testing of a custom processor, I need to queue up at least
two flowfiles. I see that there is an implementation of
TestRunner.enqueue()that takes*a list of flowfiles*, but I'm used to
using the implementation of this method that creates me a flowfile from
bytes or a stream. I do not know how to create a flowfile from scratch
inside test code. MockFlowFile's two constructors are no help. Getting
there via interface ProcessorSessionseems a long road to travel just for
this.
Examples using TestRunner.enqueue( FlowFile ... flowfiles ) do not
abound out there in Googleland. Has someone else done this?
Thanks.
Re: TestRunner: enqueueing multiple flowfiles
Posted by Russell Bateman <ru...@windofkeltia.com>.
Oh, no, Brian, calling runner.enqueue()multiple times is a perfect
solution. It wasn't clear that this was an option. I guess I missed that
semantic in the Javadoc, but, certainly, the name, "enqueue" should have
been a huge hint to me.
Thanks!
On 8/31/20 7:26 AM, Bryan Bende wrote:
> I think you could call any of the enqueue methods multiple times to queue
> multiple flow files.
>
> If you really want to use the one that takes var args of FlowFile, then you
> would need to create the MockFlowFiles yourself doing something like this...
>
> https://github.com/apache/nifi/blob/main/nifi-mock/src/main/java/org/apache/nifi/util/StandardProcessorTestRunner.java#L443-L448
>
> Instead of creating a new MockProcessSession, you would get the
> ProcessSessionFactory from the TestRunner and then call
> createProcessSession().
>
>
> On Mon, Aug 31, 2020 at 9:01 AM Russell Bateman <ru...@windofkeltia.com>
> wrote:
>
>> In my JUnit testing of a custom processor, I need to queue up at least
>> two flowfiles. I see that there is an implementation of
>> TestRunner.enqueue()that takes*a list of flowfiles*, but I'm used to
>> using the implementation of this method that creates me a flowfile from
>> bytes or a stream. I do not know how to create a flowfile from scratch
>> inside test code. MockFlowFile's two constructors are no help. Getting
>> there via interface ProcessorSessionseems a long road to travel just for
>> this.
>>
>> Examples using TestRunner.enqueue( FlowFile ... flowfiles ) do not
>> abound out there in Googleland. Has someone else done this?
>>
>> Thanks.
>>
Re: TestRunner: enqueueing multiple flowfiles
Posted by Bryan Bende <bb...@gmail.com>.
I think you could call any of the enqueue methods multiple times to queue
multiple flow files.
If you really want to use the one that takes var args of FlowFile, then you
would need to create the MockFlowFiles yourself doing something like this...
https://github.com/apache/nifi/blob/main/nifi-mock/src/main/java/org/apache/nifi/util/StandardProcessorTestRunner.java#L443-L448
Instead of creating a new MockProcessSession, you would get the
ProcessSessionFactory from the TestRunner and then call
createProcessSession().
On Mon, Aug 31, 2020 at 9:01 AM Russell Bateman <ru...@windofkeltia.com>
wrote:
> In my JUnit testing of a custom processor, I need to queue up at least
> two flowfiles. I see that there is an implementation of
> TestRunner.enqueue()that takes*a list of flowfiles*, but I'm used to
> using the implementation of this method that creates me a flowfile from
> bytes or a stream. I do not know how to create a flowfile from scratch
> inside test code. MockFlowFile's two constructors are no help. Getting
> there via interface ProcessorSessionseems a long road to travel just for
> this.
>
> Examples using TestRunner.enqueue( FlowFile ... flowfiles ) do not
> abound out there in Googleland. Has someone else done this?
>
> Thanks.
>