Search in sources :

Example 6 with StandardEvent

use of org.apache.nifi.processor.util.listen.event.StandardEvent in project nifi by apache.

the class TestListenUDPRecord method testSuccessWithBatchSizeGreaterThanAvailableRecords.

@Test
public void testSuccessWithBatchSizeGreaterThanAvailableRecords() {
    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, 1);
    final MockFlowFile flowFile = runner.getFlowFilesForRelationship(ListenUDPRecord.REL_SUCCESS).get(0);
    flowFile.assertAttributeEquals(ListenUDPRecord.RECORD_COUNT_ATTR, "3");
}
Also used : MockFlowFile(org.apache.nifi.util.MockFlowFile) StandardEvent(org.apache.nifi.processor.util.listen.event.StandardEvent) Test(org.junit.Test)

Example 7 with StandardEvent

use of org.apache.nifi.processor.util.listen.event.StandardEvent in project nifi by apache.

the class TestListenUDPRecord method testMultipleRecordsPerDatagram.

@Test
public void testMultipleRecordsPerDatagram() {
    final String sender = "foo";
    final StandardEvent event1 = new StandardEvent(sender, MULTI_DATAGRAM_1.getBytes(StandardCharsets.UTF_8), null);
    proc.addEvent(event1);
    final StandardEvent event2 = new StandardEvent(sender, MULTI_DATAGRAM_2.getBytes(StandardCharsets.UTF_8), null);
    proc.addEvent(event2);
    runner.run();
    runner.assertAllFlowFilesTransferred(ListenUDPRecord.REL_SUCCESS, 1);
    final MockFlowFile flowFile = runner.getFlowFilesForRelationship(ListenUDPRecord.REL_SUCCESS).get(0);
    flowFile.assertAttributeEquals(ListenUDPRecord.RECORD_COUNT_ATTR, "6");
}
Also used : MockFlowFile(org.apache.nifi.util.MockFlowFile) StandardEvent(org.apache.nifi.processor.util.listen.event.StandardEvent) Test(org.junit.Test)

Example 8 with StandardEvent

use of org.apache.nifi.processor.util.listen.event.StandardEvent 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 9 with StandardEvent

use of org.apache.nifi.processor.util.listen.event.StandardEvent in project nifi by apache.

the class TestListenUDPRecord method testSuccessWithBatchLessThanAvailableRecords.

@Test
public void testSuccessWithBatchLessThanAvailableRecords() {
    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.setProperty(ListenUDPRecord.BATCH_SIZE, "1");
    // batch 1
    runner.run();
    runner.assertAllFlowFilesTransferred(ListenUDPRecord.REL_SUCCESS, 1);
    MockFlowFile flowFile = runner.getFlowFilesForRelationship(ListenUDPRecord.REL_SUCCESS).get(0);
    flowFile.assertAttributeEquals(ListenUDPRecord.RECORD_COUNT_ATTR, "1");
    // batch 2
    runner.clearTransferState();
    runner.run();
    runner.assertAllFlowFilesTransferred(ListenUDPRecord.REL_SUCCESS, 1);
    flowFile = runner.getFlowFilesForRelationship(ListenUDPRecord.REL_SUCCESS).get(0);
    flowFile.assertAttributeEquals(ListenUDPRecord.RECORD_COUNT_ATTR, "1");
    // batch 3
    runner.clearTransferState();
    runner.run();
    runner.assertAllFlowFilesTransferred(ListenUDPRecord.REL_SUCCESS, 1);
    flowFile = runner.getFlowFilesForRelationship(ListenUDPRecord.REL_SUCCESS).get(0);
    flowFile.assertAttributeEquals(ListenUDPRecord.RECORD_COUNT_ATTR, "1");
    // no more left
    runner.clearTransferState();
    runner.run();
    runner.assertAllFlowFilesTransferred(ListenUDPRecord.REL_SUCCESS, 0);
}
Also used : MockFlowFile(org.apache.nifi.util.MockFlowFile) StandardEvent(org.apache.nifi.processor.util.listen.event.StandardEvent) Test(org.junit.Test)

Aggregations

StandardEvent (org.apache.nifi.processor.util.listen.event.StandardEvent)9 Test (org.junit.Test)5 ArrayList (java.util.ArrayList)3 MockFlowFile (org.apache.nifi.util.MockFlowFile)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 OutputStream (java.io.OutputStream)2 UnknownHostException (java.net.UnknownHostException)2 ByteBuffer (java.nio.ByteBuffer)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 FlowFile (org.apache.nifi.flowfile.FlowFile)2 ProcessException (org.apache.nifi.processor.exception.ProcessException)2 StandardEventFactory (org.apache.nifi.processor.util.listen.event.StandardEventFactory)2 InetAddress (java.net.InetAddress)1 Charset (java.nio.charset.Charset)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1