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");
}
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");
}
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);
}
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);
}
Aggregations