Search in sources :

Example 16 with MockRecordWriter

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);
}
Also used : MockRecordWriter(org.apache.nifi.serialization.record.MockRecordWriter) MockRecordParser(org.apache.nifi.serialization.record.MockRecordParser) Before(org.junit.Before)

Example 17 with MockRecordWriter

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);
}
Also used : RecordSetWriterFactory(org.apache.nifi.serialization.RecordSetWriterFactory) JsonTreeReader(org.apache.nifi.json.JsonTreeReader) MockRecordWriter(org.apache.nifi.serialization.record.MockRecordWriter) RecordReaderFactory(org.apache.nifi.serialization.RecordReaderFactory) Before(org.junit.Before)

Example 18 with MockRecordWriter

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);
}
Also used : StandardEvent(org.apache.nifi.processor.util.listen.event.StandardEvent) MockRecordWriter(org.apache.nifi.serialization.record.MockRecordWriter) Test(org.junit.Test)

Example 19 with MockRecordWriter

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);
}
Also used : JsonTreeReader(org.apache.nifi.json.JsonTreeReader) MockRecordWriter(org.apache.nifi.serialization.record.MockRecordWriter) RecordReaderFactory(org.apache.nifi.serialization.RecordReaderFactory) Before(org.junit.Before)

Example 20 with MockRecordWriter

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);
}
Also used : MockRecordWriter(org.apache.nifi.serialization.record.MockRecordWriter) MockRecordParser(org.apache.nifi.serialization.record.MockRecordParser) Before(org.junit.Before)

Aggregations

MockRecordWriter (org.apache.nifi.serialization.record.MockRecordWriter)21 MockRecordParser (org.apache.nifi.serialization.record.MockRecordParser)16 Test (org.junit.Test)13 TestRunner (org.apache.nifi.util.TestRunner)12 MockFlowFile (org.apache.nifi.util.MockFlowFile)11 Before (org.junit.Before)7 JsonTreeReader (org.apache.nifi.json.JsonTreeReader)2 RecordReaderFactory (org.apache.nifi.serialization.RecordReaderFactory)2 RecordSetWriterFactory (org.apache.nifi.serialization.RecordSetWriterFactory)2 List (java.util.List)1 MockDruidTranquilityController (org.apache.nifi.controller.druid.MockDruidTranquilityController)1 StandardEvent (org.apache.nifi.processor.util.listen.event.StandardEvent)1 InitializationException (org.apache.nifi.reporting.InitializationException)1 CommaSeparatedRecordReader (org.apache.nifi.serialization.record.CommaSeparatedRecordReader)1 RecordFieldType (org.apache.nifi.serialization.record.RecordFieldType)1 TestRunners (org.apache.nifi.util.TestRunners)1 Assert.assertEquals (org.junit.Assert.assertEquals)1 Assert.assertTrue (org.junit.Assert.assertTrue)1