Search in sources :

Example 6 with MockRecordParser

use of org.apache.nifi.processors.kafka.pubsub.util.MockRecordParser in project nifi by apache.

the class TestConsumeKafkaRecord_0_11 method setup.

@Before
public void setup() throws InitializationException {
    mockLease = mock(ConsumerLease.class);
    mockConsumerPool = mock(ConsumerPool.class);
    ConsumeKafkaRecord_0_11 proc = new ConsumeKafkaRecord_0_11() {

        @Override
        protected ConsumerPool createConsumerPool(final ProcessContext context, final ComponentLog log) {
            return mockConsumerPool;
        }
    };
    runner = TestRunners.newTestRunner(proc);
    runner.setProperty(KafkaProcessorUtils.BOOTSTRAP_SERVERS, "okeydokey:1234");
    final String readerId = "record-reader";
    final MockRecordParser readerService = new MockRecordParser();
    readerService.addSchemaField("name", RecordFieldType.STRING);
    readerService.addSchemaField("age", RecordFieldType.INT);
    runner.addControllerService(readerId, readerService);
    runner.enableControllerService(readerService);
    final String writerId = "record-writer";
    final RecordSetWriterFactory writerService = new MockRecordWriter("name, age");
    runner.addControllerService(writerId, writerService);
    runner.enableControllerService(writerService);
    runner.setProperty(ConsumeKafkaRecord_0_11.RECORD_READER, readerId);
    runner.setProperty(ConsumeKafkaRecord_0_11.RECORD_WRITER, writerId);
}
Also used : RecordSetWriterFactory(org.apache.nifi.serialization.RecordSetWriterFactory) MockRecordWriter(org.apache.nifi.processors.kafka.pubsub.util.MockRecordWriter) ComponentLog(org.apache.nifi.logging.ComponentLog) ProcessContext(org.apache.nifi.processor.ProcessContext) MockRecordParser(org.apache.nifi.processors.kafka.pubsub.util.MockRecordParser) Before(org.junit.Before)

Example 7 with MockRecordParser

use of org.apache.nifi.processors.kafka.pubsub.util.MockRecordParser in project nifi by apache.

the class TestPublishKafkaRecord_0_11 method setup.

@Before
public void setup() throws InitializationException, IOException {
    mockPool = mock(PublisherPool.class);
    mockLease = mock(PublisherLease.class);
    Mockito.doCallRealMethod().when(mockLease).publish(any(FlowFile.class), any(RecordSet.class), any(RecordSetWriterFactory.class), any(RecordSchema.class), any(String.class), any(String.class));
    when(mockPool.obtainPublisher()).thenReturn(mockLease);
    runner = TestRunners.newTestRunner(new PublishKafkaRecord_0_11() {

        @Override
        protected PublisherPool createPublisherPool(final ProcessContext context) {
            return mockPool;
        }
    });
    runner.setProperty(PublishKafkaRecord_0_11.TOPIC, TOPIC_NAME);
    final String readerId = "record-reader";
    final MockRecordParser readerService = new MockRecordParser();
    readerService.addSchemaField("name", RecordFieldType.STRING);
    readerService.addSchemaField("age", RecordFieldType.INT);
    runner.addControllerService(readerId, readerService);
    runner.enableControllerService(readerService);
    final String writerId = "record-writer";
    final RecordSetWriterFactory writerService = new MockRecordWriter("name, age");
    runner.addControllerService(writerId, writerService);
    runner.enableControllerService(writerService);
    runner.setProperty(PublishKafkaRecord_0_11.RECORD_READER, readerId);
    runner.setProperty(PublishKafkaRecord_0_11.RECORD_WRITER, writerId);
    runner.setProperty(PublishKafka_0_11.DELIVERY_GUARANTEE, PublishKafka_0_11.DELIVERY_REPLICATED);
}
Also used : FlowFile(org.apache.nifi.flowfile.FlowFile) MockFlowFile(org.apache.nifi.util.MockFlowFile) RecordSetWriterFactory(org.apache.nifi.serialization.RecordSetWriterFactory) RecordSet(org.apache.nifi.serialization.record.RecordSet) MockRecordWriter(org.apache.nifi.processors.kafka.pubsub.util.MockRecordWriter) RecordSchema(org.apache.nifi.serialization.record.RecordSchema) ProcessContext(org.apache.nifi.processor.ProcessContext) MockRecordParser(org.apache.nifi.processors.kafka.pubsub.util.MockRecordParser) Before(org.junit.Before)

Aggregations

MockRecordParser (org.apache.nifi.processors.kafka.pubsub.util.MockRecordParser)7 RecordSetWriterFactory (org.apache.nifi.serialization.RecordSetWriterFactory)7 ProcessContext (org.apache.nifi.processor.ProcessContext)6 MockRecordWriter (org.apache.nifi.processors.kafka.pubsub.util.MockRecordWriter)6 Before (org.junit.Before)6 FlowFile (org.apache.nifi.flowfile.FlowFile)4 RecordSchema (org.apache.nifi.serialization.record.RecordSchema)4 RecordSet (org.apache.nifi.serialization.record.RecordSet)4 MockFlowFile (org.apache.nifi.util.MockFlowFile)4 ComponentLog (org.apache.nifi.logging.ComponentLog)3 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ProducerRecord (org.apache.kafka.clients.producer.ProducerRecord)1 RecordReader (org.apache.nifi.serialization.RecordReader)1 RecordSetWriter (org.apache.nifi.serialization.RecordSetWriter)1 Record (org.apache.nifi.serialization.record.Record)1 Test (org.junit.Test)1