Search in sources :

Example 1 with RELPEvent

use of org.apache.nifi.processors.standard.relp.event.RELPEvent in project nifi by apache.

the class TestRELPFrameHandler method testCommand.

@Test
public void testCommand() throws IOException, InterruptedException {
    final String data = "this is a syslog message";
    final RELPFrame openFrame = new RELPFrame.Builder().txnr(1).command("syslog").dataLength(data.length()).data(data.getBytes(charset)).build();
    final String sender = "sender1";
    final CapturingChannelResponder responder = new CapturingChannelResponder();
    // call the handler and verify respond() was called once with once response
    frameHandler.handle(openFrame, responder, sender);
    Assert.assertEquals(0, responder.responded);
    Assert.assertEquals(0, responder.responses.size());
    Assert.assertEquals(1, events.size());
    final RELPEvent event = events.poll();
    Assert.assertEquals(data, new String(event.getData(), charset));
}
Also used : RELPEvent(org.apache.nifi.processors.standard.relp.event.RELPEvent) RELPFrame(org.apache.nifi.processors.standard.relp.frame.RELPFrame) Test(org.junit.Test)

Example 2 with RELPEvent

use of org.apache.nifi.processors.standard.relp.event.RELPEvent in project nifi by apache.

the class TestListenRELP method testBatchingWithDifferentSenders.

@Test
public void testBatchingWithDifferentSenders() throws IOException, InterruptedException {
    final String sender1 = "sender1";
    final String sender2 = "sender2";
    final ChannelResponder<SocketChannel> responder = Mockito.mock(ChannelResponder.class);
    final List<RELPEvent> mockEvents = new ArrayList<>();
    mockEvents.add(new RELPEvent(sender1, SYSLOG_FRAME.getData(), responder, SYSLOG_FRAME.getTxnr(), SYSLOG_FRAME.getCommand()));
    mockEvents.add(new RELPEvent(sender1, SYSLOG_FRAME.getData(), responder, SYSLOG_FRAME.getTxnr(), SYSLOG_FRAME.getCommand()));
    mockEvents.add(new RELPEvent(sender2, SYSLOG_FRAME.getData(), responder, SYSLOG_FRAME.getTxnr(), SYSLOG_FRAME.getCommand()));
    mockEvents.add(new RELPEvent(sender2, SYSLOG_FRAME.getData(), responder, SYSLOG_FRAME.getTxnr(), SYSLOG_FRAME.getCommand()));
    MockListenRELP mockListenRELP = new MockListenRELP(mockEvents);
    runner = TestRunners.newTestRunner(mockListenRELP);
    runner.setProperty(ListenRELP.PORT, "1");
    runner.setProperty(ListenRELP.MAX_BATCH_SIZE, "10");
    runner.run();
    runner.assertAllFlowFilesTransferred(ListenRELP.REL_SUCCESS, 2);
}
Also used : SocketChannel(java.nio.channels.SocketChannel) ArrayList(java.util.ArrayList) RELPEvent(org.apache.nifi.processors.standard.relp.event.RELPEvent) Test(org.junit.Test)

Example 3 with RELPEvent

use of org.apache.nifi.processors.standard.relp.event.RELPEvent in project nifi by apache.

the class ListenRELP method createDispatcher.

@Override
protected ChannelDispatcher createDispatcher(final ProcessContext context, final BlockingQueue<RELPEvent> events) throws IOException {
    final EventFactory<RELPEvent> eventFactory = new RELPEventFactory();
    final ChannelHandlerFactory<RELPEvent, AsyncChannelDispatcher> handlerFactory = new RELPSocketChannelHandlerFactory<>();
    final int maxConnections = context.getProperty(MAX_CONNECTIONS).asInteger();
    final int bufferSize = context.getProperty(RECV_BUFFER_SIZE).asDataSize(DataUnit.B).intValue();
    final Charset charSet = Charset.forName(context.getProperty(CHARSET).getValue());
    // initialize the buffer pool based on max number of connections and the buffer size
    final BlockingQueue<ByteBuffer> bufferPool = createBufferPool(maxConnections, bufferSize);
    // if an SSLContextService was provided then create an SSLContext to pass down to the dispatcher
    SSLContext sslContext = null;
    SslContextFactory.ClientAuth clientAuth = null;
    final SSLContextService sslContextService = context.getProperty(SSL_CONTEXT_SERVICE).asControllerService(SSLContextService.class);
    if (sslContextService != null) {
        final String clientAuthValue = context.getProperty(CLIENT_AUTH).getValue();
        sslContext = sslContextService.createSSLContext(SSLContextService.ClientAuth.valueOf(clientAuthValue));
        clientAuth = SslContextFactory.ClientAuth.valueOf(clientAuthValue);
    }
    // if we decide to support SSL then get the context and pass it in here
    return new SocketChannelDispatcher<>(eventFactory, handlerFactory, bufferPool, events, getLogger(), maxConnections, sslContext, clientAuth, charSet);
}
Also used : RELPSocketChannelHandlerFactory(org.apache.nifi.processors.standard.relp.handler.RELPSocketChannelHandlerFactory) RELPEventFactory(org.apache.nifi.processors.standard.relp.event.RELPEventFactory) Charset(java.nio.charset.Charset) SSLContext(javax.net.ssl.SSLContext) ByteBuffer(java.nio.ByteBuffer) SslContextFactory(org.apache.nifi.security.util.SslContextFactory) AsyncChannelDispatcher(org.apache.nifi.processor.util.listen.dispatcher.AsyncChannelDispatcher) SSLContextService(org.apache.nifi.ssl.SSLContextService) RestrictedSSLContextService(org.apache.nifi.ssl.RestrictedSSLContextService) SocketChannelDispatcher(org.apache.nifi.processor.util.listen.dispatcher.SocketChannelDispatcher) RELPEvent(org.apache.nifi.processors.standard.relp.event.RELPEvent)

Aggregations

RELPEvent (org.apache.nifi.processors.standard.relp.event.RELPEvent)3 Test (org.junit.Test)2 ByteBuffer (java.nio.ByteBuffer)1 SocketChannel (java.nio.channels.SocketChannel)1 Charset (java.nio.charset.Charset)1 ArrayList (java.util.ArrayList)1 SSLContext (javax.net.ssl.SSLContext)1 AsyncChannelDispatcher (org.apache.nifi.processor.util.listen.dispatcher.AsyncChannelDispatcher)1 SocketChannelDispatcher (org.apache.nifi.processor.util.listen.dispatcher.SocketChannelDispatcher)1 RELPEventFactory (org.apache.nifi.processors.standard.relp.event.RELPEventFactory)1 RELPFrame (org.apache.nifi.processors.standard.relp.frame.RELPFrame)1 RELPSocketChannelHandlerFactory (org.apache.nifi.processors.standard.relp.handler.RELPSocketChannelHandlerFactory)1 SslContextFactory (org.apache.nifi.security.util.SslContextFactory)1 RestrictedSSLContextService (org.apache.nifi.ssl.RestrictedSSLContextService)1 SSLContextService (org.apache.nifi.ssl.SSLContextService)1