Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
@Test
public void testNoMatchingRecords() throws InitializationException {
TestRunner runner = getRunner();
final JsonTreeReader jsonReader = new JsonTreeReader();
runner.addControllerService("reader", jsonReader);
runner.setProperty(jsonReader, SchemaAccessUtils.SCHEMA_ACCESS_STRATEGY, SchemaInferenceUtil.INFER_SCHEMA);
final JsonRecordSetWriter jsonWriter = new JsonRecordSetWriter();
runner.addControllerService("writer", jsonWriter);
runner.setProperty(jsonWriter, SchemaAccessUtils.SCHEMA_ACCESS_STRATEGY, SchemaAccessUtils.INHERIT_RECORD_SCHEMA);
runner.enableControllerService(jsonReader);
runner.enableControllerService(jsonWriter);
runner.setProperty(REL_NAME, "select * from FLOWFILE WHERE event LIKE '%ERROR%'");
runner.setProperty(QueryRecord.RECORD_READER_FACTORY, "reader");
runner.setProperty(QueryRecord.RECORD_WRITER_FACTORY, "writer");
// Test 1
runner.setProperty(QueryRecord.INCLUDE_ZERO_RECORD_FLOWFILES, "false");
runner.enqueue("[{\"event\": \"test - INFO - test\"}, {\"event\": \"test - INFO - test\"}]");
runner.run();
// no matching record, and does not include zero record flow file, should be 0
runner.assertTransferCount(REL_NAME, 0);
// Test 2
runner.clearTransferState();
runner.setProperty(QueryRecord.INCLUDE_ZERO_RECORD_FLOWFILES, "true");
runner.enqueue("[{\"event\": \"test - INFO - test\"}]");
runner.run();
// no matching record, but includes zero record flow file, should be 1 with record.count = 0
runner.assertTransferCount(REL_NAME, 1);
MockFlowFile flowFileOut = runner.getFlowFilesForRelationship(REL_NAME).get(0);
flowFileOut.assertAttributeEquals("record.count", "0");
flowFileOut.assertContentEquals("[]");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment