Search in sources :

Example 6 with ChannelResponder

use of org.apache.nifi.processor.util.listen.response.ChannelResponder in project nifi by apache.

the class TestListenUDP method testBatchingWithDifferentSenders.

@Test
public void testBatchingWithDifferentSenders() throws IOException, InterruptedException {
    final String sender1 = "sender1";
    final String sender2 = "sender2";
    final ChannelResponder responder = Mockito.mock(ChannelResponder.class);
    final byte[] message = "test message".getBytes(StandardCharsets.UTF_8);
    final List<StandardEvent> mockEvents = new ArrayList<>();
    mockEvents.add(new StandardEvent(sender1, message, responder));
    mockEvents.add(new StandardEvent(sender1, message, responder));
    mockEvents.add(new StandardEvent(sender2, message, responder));
    mockEvents.add(new StandardEvent(sender2, message, responder));
    MockListenUDP mockListenUDP = new MockListenUDP(mockEvents);
    runner = TestRunners.newTestRunner(mockListenUDP);
    runner.setProperty(ListenRELP.PORT, "1");
    runner.setProperty(ListenRELP.MAX_BATCH_SIZE, "10");
    // sending 4 messages with a batch size of 10, but should get 2 FlowFiles because of different senders
    runner.run();
    runner.assertAllFlowFilesTransferred(ListenRELP.REL_SUCCESS, 2);
    verifyProvenance(2);
}
Also used : ChannelResponder(org.apache.nifi.processor.util.listen.response.ChannelResponder) StandardEvent(org.apache.nifi.processor.util.listen.event.StandardEvent) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 7 with ChannelResponder

use of org.apache.nifi.processor.util.listen.response.ChannelResponder in project nifi by apache.

the class TestBeatsEventFactory method testCreateLumberJackEvent.

@Test
public void testCreateLumberJackEvent() {
    final String sender = "testsender1";
    final byte[] data = "this is a test line".getBytes();
    final int seqNumber = 1;
    final String fields = "{\"file\":\"test\"}";
    final Map<String, String> metadata = new HashMap<>();
    metadata.put(EventFactory.SENDER_KEY, sender);
    metadata.put(BeatsMetadata.SEQNUMBER_KEY, String.valueOf(seqNumber));
    final ChannelResponder responder = new SocketChannelResponder(null);
    final EventFactory<BeatsEvent> factory = new BeatsEventFactory();
    final BeatsEvent event = factory.create(data, metadata, responder);
    Assert.assertEquals(sender, event.getSender());
    Assert.assertEquals(seqNumber, event.getSeqNumber());
    Assert.assertEquals(data, event.getData());
}
Also used : SocketChannelResponder(org.apache.nifi.processor.util.listen.response.socket.SocketChannelResponder) ChannelResponder(org.apache.nifi.processor.util.listen.response.ChannelResponder) SocketChannelResponder(org.apache.nifi.processor.util.listen.response.socket.SocketChannelResponder) HashMap(java.util.HashMap) Test(org.junit.Test)

Aggregations

ChannelResponder (org.apache.nifi.processor.util.listen.response.ChannelResponder)7 Test (org.junit.Test)4 IOException (java.io.IOException)3 HashMap (java.util.HashMap)3 ChannelResponse (org.apache.nifi.processor.util.listen.response.ChannelResponse)3 SocketChannelResponder (org.apache.nifi.processor.util.listen.response.socket.SocketChannelResponder)3 ArrayList (java.util.ArrayList)1 StandardEvent (org.apache.nifi.processor.util.listen.event.StandardEvent)1 BeatsChannelResponse (org.apache.nifi.processors.beats.response.BeatsChannelResponse)1 LumberjackChannelResponse (org.apache.nifi.processors.lumberjack.response.LumberjackChannelResponse)1 RELPChannelResponse (org.apache.nifi.processors.standard.relp.response.RELPChannelResponse)1