Search in sources :

Example 21 with MockRecordParser

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

Example 22 with MockRecordParser

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");
}
Also used : MockFlowFile(org.apache.nifi.util.MockFlowFile) MockRecordParser(org.apache.nifi.serialization.record.MockRecordParser) Test(org.junit.Test)

Example 23 with MockRecordParser

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");
}
Also used : MockFlowFile(org.apache.nifi.util.MockFlowFile) MockRecordParser(org.apache.nifi.serialization.record.MockRecordParser) Test(org.junit.Test)

Example 24 with MockRecordParser

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

Example 25 with MockRecordParser

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

Aggregations

MockRecordParser (org.apache.nifi.serialization.record.MockRecordParser)28 Test (org.junit.Test)18 MockRecordWriter (org.apache.nifi.serialization.record.MockRecordWriter)16 MockFlowFile (org.apache.nifi.util.MockFlowFile)16 TestRunner (org.apache.nifi.util.TestRunner)13 Before (org.junit.Before)6 ArrayList (java.util.ArrayList)4 RecordField (org.apache.nifi.serialization.record.RecordField)4 RecordSchema (org.apache.nifi.serialization.record.RecordSchema)4 InitializationException (org.apache.nifi.reporting.InitializationException)3 SimpleRecordSchema (org.apache.nifi.serialization.SimpleRecordSchema)3 MapRecord (org.apache.nifi.serialization.record.MapRecord)3 Record (org.apache.nifi.serialization.record.Record)3 IOException (java.io.IOException)2 List (java.util.List)1 MockDruidTranquilityController (org.apache.nifi.controller.druid.MockDruidTranquilityController)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