use of org.apache.nifi.serialization.record.MockRecordParser in project nifi by apache.
the class TestPutKudu method createRecordReader.
private void createRecordReader(int numOfRecord) throws InitializationException {
readerFactory = new MockRecordParser();
readerFactory.addSchemaField("id", RecordFieldType.INT);
readerFactory.addSchemaField("stringVal", RecordFieldType.STRING);
readerFactory.addSchemaField("num32Val", RecordFieldType.INT);
readerFactory.addSchemaField("doubleVal", RecordFieldType.DOUBLE);
for (int i = 0; i < numOfRecord; i++) {
readerFactory.addRecord(i, "val_" + i, 1000 + i, 100.88 + i);
}
testRunner.addControllerService("mock-reader-factory", readerFactory);
testRunner.enableControllerService(readerFactory);
}
use of org.apache.nifi.serialization.record.MockRecordParser in project nifi by apache.
the class TestUpdateRecord method testRelativePath.
@Test
public void testRelativePath() throws InitializationException {
readerService = new MockRecordParser();
readerService.addSchemaField("name", RecordFieldType.STRING);
readerService.addSchemaField("nickname", RecordFieldType.STRING);
runner.addControllerService("reader", readerService);
runner.enableControllerService(readerService);
runner.setProperty("/name", "../nickname");
runner.setProperty(UpdateRecord.REPLACEMENT_VALUE_STRATEGY, UpdateRecord.RECORD_PATH_VALUES.getValue());
runner.enqueue("", Collections.singletonMap("recordPath", "hello"));
readerService.addRecord("John Doe", "Johnny");
runner.run();
runner.assertAllFlowFilesTransferred(UpdateRecord.REL_SUCCESS, 1);
final MockFlowFile mff = runner.getFlowFilesForRelationship(UpdateRecord.REL_SUCCESS).get(0);
mff.assertContentEquals("header\nJohnny,Johnny\n");
}
use of org.apache.nifi.serialization.record.MockRecordParser in project nifi by apache.
the class TestUpdateRecord method testReplaceWithMissingRecordPath.
@Test
public void testReplaceWithMissingRecordPath() throws InitializationException {
readerService = new MockRecordParser();
readerService.addSchemaField("name", RecordFieldType.STRING);
readerService.addSchemaField("siblings", RecordFieldType.ARRAY);
runner.addControllerService("reader", readerService);
runner.enableControllerService(readerService);
runner.setProperty("/name", "/siblings[0]/name");
runner.setProperty(UpdateRecord.REPLACEMENT_VALUE_STRATEGY, UpdateRecord.RECORD_PATH_VALUES.getValue());
runner.enqueue("", Collections.singletonMap("recordPath", "hello"));
readerService.addRecord("John Doe", null);
runner.run();
runner.assertAllFlowFilesTransferred(UpdateRecord.REL_SUCCESS, 1);
final MockFlowFile mff = runner.getFlowFilesForRelationship(UpdateRecord.REL_SUCCESS).get(0);
mff.assertContentEquals("header\n,\n");
}
use of org.apache.nifi.serialization.record.MockRecordParser in project nifi by apache.
the class TestUpdateRecord method setup.
@Before
public void setup() throws InitializationException {
readerService = new MockRecordParser();
writerService = new MockRecordWriter("header", false);
runner = TestRunners.newTestRunner(UpdateRecord.class);
runner.addControllerService("reader", readerService);
runner.enableControllerService(readerService);
runner.addControllerService("writer", writerService);
runner.enableControllerService(writerService);
runner.setProperty(UpdateRecord.RECORD_READER, "reader");
runner.setProperty(UpdateRecord.RECORD_WRITER, "writer");
readerService.addSchemaField("name", RecordFieldType.STRING);
readerService.addSchemaField("age", RecordFieldType.INT);
}
use of org.apache.nifi.serialization.record.MockRecordParser in project nifi by apache.
the class TestLookupRecord method setup.
@Before
public void setup() throws InitializationException {
recordReader = new MockRecordParser();
recordWriter = new MockRecordWriter(null, false);
lookupService = new MapLookup();
runner = TestRunners.newTestRunner(LookupRecord.class);
runner.addControllerService("reader", recordReader);
runner.enableControllerService(recordReader);
runner.addControllerService("writer", recordWriter);
runner.enableControllerService(recordWriter);
runner.addControllerService("lookup", lookupService);
runner.enableControllerService(lookupService);
runner.setProperty(LookupRecord.RECORD_READER, "reader");
runner.setProperty(LookupRecord.RECORD_WRITER, "writer");
runner.setProperty(LookupRecord.LOOKUP_SERVICE, "lookup");
runner.setProperty("lookup", "/name");
runner.setProperty(LookupRecord.RESULT_RECORD_PATH, "/sport");
runner.setProperty(LookupRecord.ROUTING_STRATEGY, LookupRecord.ROUTE_TO_MATCHED_UNMATCHED);
recordReader.addSchemaField("name", RecordFieldType.STRING);
recordReader.addSchemaField("age", RecordFieldType.INT);
recordReader.addSchemaField("sport", RecordFieldType.STRING);
recordReader.addRecord("John Doe", 48, null);
recordReader.addRecord("Jane Doe", 47, null);
recordReader.addRecord("Jimmy Doe", 14, null);
}
Aggregations