Thanks for the suggestions. Not really finding what I wanted, I put together
my own (FlowRunner). Fairly basic at the moment, but who knows, maybe it might
be a useful addition to NiFi one day. Next step is to allow for hooks to be
added so that assertions can be made during the flow (eg: confirming that the
data from A -> B is correct before proceeding to C).
It maintains a list of connections and forwards flowfiles along those
connections. I suppose in a fully fledged version, you’d be able to configure
these as per NiFi proper.
It also identifies processors that aren’t connected, to assist with fault
finding (some of my testing will involve a lot of the same type of processor
being daisy chained together, so that would be an easy mistake to make).
The simple example processor here prefixes whatever the incoming FlowFile is
with a configured string. That incoming FiowFile in this case is generated by
GenerateFlowFile. The test confirms that the two strings were concatenated.
Cheers,
Phil
public class MyProcessorTest
{
private FlowRunner flowRunner;
private TestRunner generateFlowFile;
private TestRunner myProcessor;
private final String PREFIX_TEST_VAL = "MyProcessor says: ";
private final String SUFFIX_TEST_VAL = "Hello World!";
@Before
public void init()
{
flowRunner = new FlowRunner();
generateFlowFile = flowRunner.addNewProcessor(GenerateFlowFile.class);
generateFlowFile.setProperty(GenerateFlowFile.CUSTOM_TEXT,
SUFFIX_TEST_VAL);
generateFlowFile.setProperty(GenerateFlowFile.DATA_FORMAT,
GenerateFlowFile.DATA_FORMAT_TEXT);
myProcessor = flowRunner.addNewProcessor(MyProcessor.class);
myProcessor.setProperty(MyProcessor.PREFIX, PREFIX_TEST_VAL);
flowRunner.connectProcessors(generateFlowFile,
GenerateFlowFile.SUCCESS, myProcessor);
}
@Test
public void testFlow()
{
try
{
flowRunner.start();
}
catch (UnattachedProcessorException e)
{
Assert.fail(e.getProcessor().getProcessor().getClass() + ": " +
e.getMessage());
}
myProcessor.assertQueueEmpty();
myProcessor.getFlowFilesForRelationship(MyProcessor.MY_RELATIONSHIP).forEach(flowFile
->
{
Assert.assertEquals(PREFIX_TEST_VAL + SUFFIX_TEST_VAL,
flowFile.getContent());
System.out.format("\n'%s'\n", flowFile.getContent());
});
}
}
> On 23 Jul 2021, at 4:57 pm, Kovaľ Anton <[email protected]> wrote:
>
> Hi,
>
> I found a project Plumber, try this.
>
>
>
> https://github.com/TouK/plumber
>
>
>
> Tony Koval
>
>
>
> On 2021/07/22 03:25:31, Phil H <[email protected]<mailto:[email protected]>> wrote:
>
>> Hi there,>
>
>>
>
>> I use the built in unit tests in the maven processor archetype for each of>
>
>> my processors, but I would like to set up some integration testing using>
>
>> multiple processors.>
>
>>
>
>> Is this possible? If so, anyone care to sling me some example code? Eg: say>
>
>> I wanted to run a test connecting GenerateFlowFile's output to PutFile's>
>
>> input.>
>
>>
>
>> Thanks!>
>
>> Phil>
>
>>
>
> ________________________________
>
> Informacie, ktore su obsahom tejto spravy elektronickej posty a vsetky
> pripojene subory a prilohy su doverne a su/mozu byt obchodnym a/alebo
> bankovym tajomstvom alebo su/mozu byt pravne chranene podla inych pravnych
> predpisov. Pre blizsie informacie navstivte, prosim, www.vub.sk/legalcaution.
>
> The information contained in this electronic mail message and any files and
> attachments transmitted are confidential and are/may be a trade and/or bank
> secret or are/may be legally privileged under other legal regulations. For
> further information, please, visit www.vub.sk/legalcaution.
>
> VUB, a.s., Mlynske nivy 1, 829 90 Bratislava 25, Slovenska republika
>
> ________________________________
>
> Pred vytlacenim e-mailu prosim zvazte dopad na zivotne prostredie.
> Before printing this e-mail, think about the impact on the environment.