use of org.apache.nifi.util.MockFlowFile in project kylo by Teradata.
the class GetTableDataTest method testAvro.
/**
* Verify Avro output.
*/
@Test
public void testAvro() throws IOException {
// Trigger processor
runner.setProperty(GetTableData.OUTPUT_TYPE, GetTableDataSupport.OutputType.AVRO.toString());
runner.enqueue(new byte[0]);
runner.run();
List<MockFlowFile> flowFiles = runner.getFlowFilesForRelationship(CommonProperties.REL_SUCCESS);
Assert.assertEquals(0, runner.getFlowFilesForRelationship(CommonProperties.REL_FAILURE).size());
Assert.assertEquals(0, runner.getFlowFilesForRelationship(GetTableData.REL_NO_DATA).size());
Assert.assertEquals(1, flowFiles.size());
Assert.assertEquals("2", flowFiles.get(0).getAttribute(GetTableData.RESULT_ROW_COUNT));
Assert.assertEquals("2", flowFiles.get(0).getAttribute(ComponentAttributes.NUM_SOURCE_RECORDS.key()));
// Build Avro record reader
final SeekableInput avroInput = new SeekableByteArrayInput(flowFiles.get(0).toByteArray());
final Schema schema = SchemaBuilder.record("NiFi_ExecuteSQL_Record").namespace("any.data").fields().name("id").type().nullable().intType().noDefault().name("first_name").type().nullable().stringType().noDefault().name("last_name").type().nullable().stringType().noDefault().name("email").type().nullable().stringType().noDefault().name("last_updated").type().nullable().stringType().noDefault().endRecord();
final DatumReader<GenericRecord> datumReader = new GenericDatumReader<>(schema);
final DataFileReader<GenericRecord> dataReader = new DataFileReader<>(avroInput, datumReader);
// Verify Avro records
List<GenericRecord> records = StreamSupport.stream(dataReader.spliterator(), false).collect(Collectors.toList());
Assert.assertEquals(2, records.size());
Assert.assertEquals(1, records.get(0).get(0));
Assert.assertEquals(new Utf8("Mike"), records.get(0).get(1));
Assert.assertEquals(new Utf8("Hillyer"), records.get(0).get(2));
Assert.assertEquals(new Utf8("Mike.Hillyer@sakilastaff.com"), records.get(0).get(3));
Assert.assertEquals(new Utf8("2006-02-15T03:57:16.000Z"), records.get(0).get(4));
Assert.assertEquals(2, records.get(1).get(0));
Assert.assertEquals(new Utf8("Jon"), records.get(1).get(1));
Assert.assertEquals(new Utf8("Stephens"), records.get(1).get(2));
Assert.assertEquals(new Utf8("Jon.Stephens@sakilastaff.com"), records.get(1).get(3));
Assert.assertEquals(new Utf8("2006-02-15T03:57:16.000Z"), records.get(1).get(4));
}
use of org.apache.nifi.util.MockFlowFile in project kylo by Teradata.
the class StripHeaderTest method testBypass.
@Test
public void testBypass() throws IOException {
final TestRunner runner = TestRunners.newTestRunner(new StripHeader());
runner.setProperty(StripHeader.HEADER_LINE_COUNT, "1");
runner.setProperty(StripHeader.ENABLED, "false");
runner.enqueue(file);
runner.run();
runner.assertTransferCount(StripHeader.REL_CONTENT, 1);
runner.assertTransferCount(StripHeader.REL_HEADER, 0);
runner.assertTransferCount(StripHeader.REL_ORIGINAL, 1);
List<MockFlowFile> originalFlows = runner.getFlowFilesForRelationship(StripHeader.REL_ORIGINAL);
String originalContent = new String(originalFlows.get(0).toByteArray());
assertTrue(originalContent.startsWith("name") && originalContent.endsWith("94550\n"));
}
use of org.apache.nifi.util.MockFlowFile in project kylo by Teradata.
the class GetFeedsHistoryReindexTest method testTwoFeedsToReindex.
@Test
public void testTwoFeedsToReindex() throws Exception {
final String METADATA_SERVICE_IDENTIFIER = "MockMetadataProviderService_TwoFeedsToReindex";
final TestRunner runner = TestRunners.newTestRunner(GetFeedsHistoryReindex.class);
final MetadataProviderService metadataService = new MockMetadataProviderService_TwoFeedsToReindex();
runner.addControllerService(METADATA_SERVICE_IDENTIFIER, metadataService);
runner.enableControllerService(metadataService);
runner.setProperty(GetFeedsHistoryReindex.METADATA_SERVICE, METADATA_SERVICE_IDENTIFIER);
runner.run(1);
runner.assertQueueEmpty();
runner.assertTransferCount(GetFeedsHistoryReindex.REL_FOUND, 2);
runner.assertTransferCount(GetFeedsHistoryReindex.REL_NOT_FOUND, 0);
runner.assertTransferCount(GetFeedsHistoryReindex.REL_FAILURE, 0);
runner.assertTransferCount(GetFeedsHistoryReindex.REL_ORIGINAL, 1);
List<MockFlowFile> results = runner.getFlowFilesForRelationship(GetFeedsHistoryReindex.REL_FOUND);
for (int i = 0; i < results.size(); i++) {
MockFlowFile resultFlowFile = results.get(i);
resultFlowFile.assertAttributeExists(GetFeedsHistoryReindex.FEED_ID_FOR_HISTORY_REINDEX_KEY);
resultFlowFile.assertAttributeExists(GetFeedsHistoryReindex.FEED_SYSTEM_NAME_FOR_HISTORY_REINDEX_KEY);
resultFlowFile.assertAttributeExists(GetFeedsHistoryReindex.FEED_CATEGORY_SYSTEM_NAME_FOR_HISTORY_REINDEX_KEY);
resultFlowFile.assertAttributeExists(GetFeedsHistoryReindex.FEED_STATUS_FOR_HISTORY_REINDEX_KEY);
resultFlowFile.assertAttributeExists(GetFeedsHistoryReindex.FEED_LAST_MODIFIED_UTC_FOR_HISTORY_REINDEX_KEY);
resultFlowFile.assertAttributeExists(GetFeedsHistoryReindex.FEEDS_TOTAL_COUNT_FOR_HISTORY_REINDEX_KEY);
resultFlowFile.assertAttributeExists(GetFeedsHistoryReindex.FEEDS_TOTAL_IDS_FOR_HISTORY_REINDEX_KEY);
resultFlowFile.assertAttributeExists(GetFeedsHistoryReindex.FEEDS_CHECK_TIME_UTC_FOR_HISTORY_REINDEX_KEY);
resultFlowFile.assertAttributeEquals(GetFeedsHistoryReindex.FEED_ID_FOR_HISTORY_REINDEX_KEY, "feed-" + i + "-id");
resultFlowFile.assertAttributeEquals(GetFeedsHistoryReindex.FEED_SYSTEM_NAME_FOR_HISTORY_REINDEX_KEY, "feed-" + i + "-systemName");
resultFlowFile.assertAttributeEquals(GetFeedsHistoryReindex.FEED_CATEGORY_SYSTEM_NAME_FOR_HISTORY_REINDEX_KEY, "cat-" + i + "-systemName");
resultFlowFile.assertAttributeEquals(GetFeedsHistoryReindex.FEED_STATUS_FOR_HISTORY_REINDEX_KEY, "DIRTY");
if (i == 0) {
String feedLastModifiedUtcForHistoryReindexActualValue = resultFlowFile.getAttribute(GetFeedsHistoryReindex.FEED_LAST_MODIFIED_UTC_FOR_HISTORY_REINDEX_KEY);
String feedLastModifiedUtcForHistoryReindexExpectedValuePrefixWithoutTimeZone = "2017-12-18T14:53:24.013";
assertTrue(feedLastModifiedUtcForHistoryReindexActualValue.contains(feedLastModifiedUtcForHistoryReindexExpectedValuePrefixWithoutTimeZone));
} else if (i == 1) {
String feedLastModifiedUtcForHistoryReindexActualValue = resultFlowFile.getAttribute(GetFeedsHistoryReindex.FEED_LAST_MODIFIED_UTC_FOR_HISTORY_REINDEX_KEY);
String feedLastModifiedUtcForHistoryReindexExpectedValuePrefixWithoutTimeZone = "2017-12-17T09:35:45.335";
assertTrue(feedLastModifiedUtcForHistoryReindexActualValue.contains(feedLastModifiedUtcForHistoryReindexExpectedValuePrefixWithoutTimeZone));
}
resultFlowFile.assertAttributeEquals(GetFeedsHistoryReindex.FEEDS_TOTAL_COUNT_FOR_HISTORY_REINDEX_KEY, String.valueOf(2));
resultFlowFile.assertAttributeEquals(GetFeedsHistoryReindex.FEEDS_TOTAL_IDS_FOR_HISTORY_REINDEX_KEY, "[feed-0-id, feed-1-id]");
resultFlowFile.assertAttributeNotEquals(GetFeedsHistoryReindex.FEEDS_CHECK_TIME_UTC_FOR_HISTORY_REINDEX_KEY, null);
}
}
use of org.apache.nifi.util.MockFlowFile in project kylo by Teradata.
the class GetFeedsHistoryReindexTest method testGeneralExceptionGettingFeedsToReindex.
@Test
public void testGeneralExceptionGettingFeedsToReindex() throws Exception {
final String METADATA_SERVICE_IDENTIFIER = "MockMetadataProviderService_GeneralExceptionGettingFeedsToReindex";
final TestRunner runner = TestRunners.newTestRunner(GetFeedsHistoryReindex.class);
final MetadataProviderService metadataService = new MockMetadataProviderService_GeneralExceptionGettingFeedsToReindex();
runner.addControllerService(METADATA_SERVICE_IDENTIFIER, metadataService);
runner.enableControllerService(metadataService);
runner.setProperty(GetFeedsHistoryReindex.METADATA_SERVICE, METADATA_SERVICE_IDENTIFIER);
runner.run(1);
runner.assertQueueEmpty();
runner.assertTransferCount(GetFeedsHistoryReindex.REL_FOUND, 0);
runner.assertTransferCount(GetFeedsHistoryReindex.REL_NOT_FOUND, 0);
runner.assertTransferCount(GetFeedsHistoryReindex.REL_FAILURE, 1);
runner.assertTransferCount(GetFeedsHistoryReindex.REL_ORIGINAL, 0);
List<MockFlowFile> results = runner.getFlowFilesForRelationship(GetFeedsHistoryReindex.REL_FAILURE);
MockFlowFile resultFlowFile = results.get(0);
resultFlowFile.assertAttributeNotExists(GetFeedsHistoryReindex.FEEDS_TOTAL_COUNT_FOR_HISTORY_REINDEX_KEY);
resultFlowFile.assertAttributeNotExists(GetFeedsHistoryReindex.FEEDS_TOTAL_IDS_FOR_HISTORY_REINDEX_KEY);
resultFlowFile.assertAttributeNotExists(GetFeedsHistoryReindex.FEEDS_CHECK_TIME_UTC_FOR_HISTORY_REINDEX_KEY);
}
use of org.apache.nifi.util.MockFlowFile in project kylo by Teradata.
the class GetFeedsHistoryReindexTest method testErrorGettingFeedsToReindex.
@Test
public void testErrorGettingFeedsToReindex() throws Exception {
final String METADATA_SERVICE_IDENTIFIER = "MockMetadataProviderService_ErrorGettingFeedsToReindex";
final TestRunner runner = TestRunners.newTestRunner(GetFeedsHistoryReindex.class);
final MetadataProviderService metadataService = new MockMetadataProviderService_ErrorGettingFeedsToReindex();
runner.addControllerService(METADATA_SERVICE_IDENTIFIER, metadataService);
runner.enableControllerService(metadataService);
runner.setProperty(GetFeedsHistoryReindex.METADATA_SERVICE, METADATA_SERVICE_IDENTIFIER);
runner.run(1);
runner.assertQueueEmpty();
runner.assertTransferCount(GetFeedsHistoryReindex.REL_FOUND, 0);
runner.assertTransferCount(GetFeedsHistoryReindex.REL_NOT_FOUND, 0);
runner.assertTransferCount(GetFeedsHistoryReindex.REL_FAILURE, 1);
runner.assertTransferCount(GetFeedsHistoryReindex.REL_ORIGINAL, 0);
List<MockFlowFile> results = runner.getFlowFilesForRelationship(GetFeedsHistoryReindex.REL_FAILURE);
MockFlowFile resultFlowFile = results.get(0);
resultFlowFile.assertAttributeNotExists(GetFeedsHistoryReindex.FEEDS_TOTAL_COUNT_FOR_HISTORY_REINDEX_KEY);
resultFlowFile.assertAttributeNotExists(GetFeedsHistoryReindex.FEEDS_TOTAL_IDS_FOR_HISTORY_REINDEX_KEY);
resultFlowFile.assertAttributeNotExists(GetFeedsHistoryReindex.FEEDS_CHECK_TIME_UTC_FOR_HISTORY_REINDEX_KEY);
}
Aggregations