use of org.apache.nifi.serialization.record.MockRecordWriter 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.MockRecordWriter in project nifi by apache.
the class TestListenTCPRecord method setup.
@Before
public void setup() throws InitializationException {
proc = new ListenTCPRecord();
runner = TestRunners.newTestRunner(proc);
runner.setProperty(ListenTCPRecord.PORT, "0");
final String readerId = "record-reader";
final RecordReaderFactory readerFactory = new JsonTreeReader();
runner.addControllerService(readerId, readerFactory);
runner.setProperty(readerFactory, SchemaAccessUtils.SCHEMA_ACCESS_STRATEGY, SchemaAccessUtils.SCHEMA_TEXT_PROPERTY.getValue());
runner.setProperty(readerFactory, SchemaAccessUtils.SCHEMA_TEXT, SCHEMA_TEXT);
runner.enableControllerService(readerFactory);
final String writerId = "record-writer";
final RecordSetWriterFactory writerFactory = new MockRecordWriter("timestamp, logsource, message");
runner.addControllerService(writerId, writerFactory);
runner.enableControllerService(writerFactory);
runner.setProperty(ListenTCPRecord.RECORD_READER, readerId);
runner.setProperty(ListenTCPRecord.RECORD_WRITER, writerId);
}
use of org.apache.nifi.serialization.record.MockRecordWriter in project nifi by apache.
the class TestListenUDPRecord method testWriterFailure.
@Test
public void testWriterFailure() throws InitializationException {
// re-create the writer to set fail-after 2 attempts
final String writerId = "record-writer";
mockRecordWriter = new MockRecordWriter("timestamp, logsource, message", false, 2);
runner.addControllerService(writerId, mockRecordWriter);
runner.enableControllerService(mockRecordWriter);
runner.setProperty(ListenUDPRecord.RECORD_WRITER, writerId);
final String sender = "foo";
final StandardEvent event1 = new StandardEvent(sender, DATAGRAM_1.getBytes(StandardCharsets.UTF_8), null);
proc.addEvent(event1);
final StandardEvent event2 = new StandardEvent(sender, DATAGRAM_2.getBytes(StandardCharsets.UTF_8), null);
proc.addEvent(event2);
final StandardEvent event3 = new StandardEvent(sender, DATAGRAM_3.getBytes(StandardCharsets.UTF_8), null);
proc.addEvent(event3);
runner.run();
runner.assertAllFlowFilesTransferred(ListenUDPRecord.REL_SUCCESS, 0);
runner.assertAllFlowFilesTransferred(ListenUDPRecord.REL_PARSE_FAILURE, 0);
}
use of org.apache.nifi.serialization.record.MockRecordWriter in project nifi by apache.
the class TestListenUDPRecord method setup.
@Before
public void setup() throws InitializationException {
proc = new TestableListenUDPRecord();
runner = TestRunners.newTestRunner(proc);
runner.setProperty(ListenUDP.PORT, "1");
final String readerId = "record-reader";
final RecordReaderFactory readerFactory = new JsonTreeReader();
runner.addControllerService(readerId, readerFactory);
runner.setProperty(readerFactory, SchemaAccessUtils.SCHEMA_ACCESS_STRATEGY, SchemaAccessUtils.SCHEMA_TEXT_PROPERTY.getValue());
runner.setProperty(readerFactory, SchemaAccessUtils.SCHEMA_TEXT, SCHEMA_TEXT);
runner.enableControllerService(readerFactory);
final String writerId = "record-writer";
mockRecordWriter = new MockRecordWriter("timestamp, logsource, message");
runner.addControllerService(writerId, mockRecordWriter);
runner.enableControllerService(mockRecordWriter);
runner.setProperty(ListenUDPRecord.RECORD_READER, readerId);
runner.setProperty(ListenUDPRecord.RECORD_WRITER, writerId);
}
use of org.apache.nifi.serialization.record.MockRecordWriter 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