Search in sources :

Example 16 with RELPFrame

use of org.apache.nifi.processors.standard.relp.frame.RELPFrame in project nifi by apache.

the class TestListenRELP method testBatching.

@Test
public void testBatching() throws IOException, InterruptedException {
    runner.setProperty(ListenRELP.MAX_BATCH_SIZE, "5");
    final List<RELPFrame> frames = new ArrayList<>();
    frames.add(OPEN_FRAME);
    frames.add(SYSLOG_FRAME);
    frames.add(SYSLOG_FRAME);
    frames.add(SYSLOG_FRAME);
    frames.add(CLOSE_FRAME);
    // one syslog frame should be transferred since we are batching, but three responses should be sent
    run(frames, 1, 3, null);
    final List<ProvenanceEventRecord> events = runner.getProvenanceEvents();
    Assert.assertNotNull(events);
    Assert.assertEquals(1, events.size());
    final ProvenanceEventRecord event = events.get(0);
    Assert.assertEquals(ProvenanceEventType.RECEIVE, event.getEventType());
    Assert.assertTrue("transit uri must be set and start with proper protocol", event.getTransitUri().toLowerCase().startsWith("relp"));
    final List<MockFlowFile> mockFlowFiles = runner.getFlowFilesForRelationship(ListenRELP.REL_SUCCESS);
    Assert.assertEquals(1, mockFlowFiles.size());
    final MockFlowFile mockFlowFile = mockFlowFiles.get(0);
    Assert.assertEquals(SYSLOG_FRAME.getCommand(), mockFlowFile.getAttribute(ListenRELP.RELPAttributes.COMMAND.key()));
    Assert.assertTrue(!StringUtils.isBlank(mockFlowFile.getAttribute(ListenRELP.RELPAttributes.PORT.key())));
    Assert.assertTrue(!StringUtils.isBlank(mockFlowFile.getAttribute(ListenRELP.RELPAttributes.SENDER.key())));
}
Also used : MockFlowFile(org.apache.nifi.util.MockFlowFile) ProvenanceEventRecord(org.apache.nifi.provenance.ProvenanceEventRecord) ArrayList(java.util.ArrayList) RELPFrame(org.apache.nifi.processors.standard.relp.frame.RELPFrame) Test(org.junit.Test)

Example 17 with RELPFrame

use of org.apache.nifi.processors.standard.relp.frame.RELPFrame in project nifi by apache.

the class TestListenRELP method testListenRELP.

@Test
public void testListenRELP() throws IOException, InterruptedException {
    final List<RELPFrame> frames = new ArrayList<>();
    frames.add(OPEN_FRAME);
    frames.add(SYSLOG_FRAME);
    frames.add(SYSLOG_FRAME);
    frames.add(SYSLOG_FRAME);
    frames.add(CLOSE_FRAME);
    // three syslog frames should be transferred and three responses should be sent
    run(frames, 3, 3, null);
    final List<ProvenanceEventRecord> events = runner.getProvenanceEvents();
    Assert.assertNotNull(events);
    Assert.assertEquals(3, events.size());
    final ProvenanceEventRecord event = events.get(0);
    Assert.assertEquals(ProvenanceEventType.RECEIVE, event.getEventType());
    Assert.assertTrue("transit uri must be set and start with proper protocol", event.getTransitUri().toLowerCase().startsWith("relp"));
    final List<MockFlowFile> mockFlowFiles = runner.getFlowFilesForRelationship(ListenRELP.REL_SUCCESS);
    Assert.assertEquals(3, mockFlowFiles.size());
    final MockFlowFile mockFlowFile = mockFlowFiles.get(0);
    Assert.assertEquals(String.valueOf(SYSLOG_FRAME.getTxnr()), mockFlowFile.getAttribute(ListenRELP.RELPAttributes.TXNR.key()));
    Assert.assertEquals(SYSLOG_FRAME.getCommand(), mockFlowFile.getAttribute(ListenRELP.RELPAttributes.COMMAND.key()));
    Assert.assertTrue(!StringUtils.isBlank(mockFlowFile.getAttribute(ListenRELP.RELPAttributes.PORT.key())));
    Assert.assertTrue(!StringUtils.isBlank(mockFlowFile.getAttribute(ListenRELP.RELPAttributes.SENDER.key())));
}
Also used : MockFlowFile(org.apache.nifi.util.MockFlowFile) ProvenanceEventRecord(org.apache.nifi.provenance.ProvenanceEventRecord) ArrayList(java.util.ArrayList) RELPFrame(org.apache.nifi.processors.standard.relp.frame.RELPFrame) Test(org.junit.Test)

Example 18 with RELPFrame

use of org.apache.nifi.processors.standard.relp.frame.RELPFrame in project nifi by apache.

the class TestListenRELP method testTLS.

@Test
public void testTLS() throws InitializationException, IOException, InterruptedException {
    final SSLContextService sslContextService = new StandardSSLContextService();
    runner.addControllerService("ssl-context", sslContextService);
    runner.setProperty(sslContextService, StandardSSLContextService.TRUSTSTORE, "src/test/resources/localhost-ts.jks");
    runner.setProperty(sslContextService, StandardSSLContextService.TRUSTSTORE_PASSWORD, "localtest");
    runner.setProperty(sslContextService, StandardSSLContextService.TRUSTSTORE_TYPE, "JKS");
    runner.setProperty(sslContextService, StandardSSLContextService.KEYSTORE, "src/test/resources/localhost-ks.jks");
    runner.setProperty(sslContextService, StandardSSLContextService.KEYSTORE_PASSWORD, "localtest");
    runner.setProperty(sslContextService, StandardSSLContextService.KEYSTORE_TYPE, "JKS");
    runner.enableControllerService(sslContextService);
    runner.setProperty(PostHTTP.SSL_CONTEXT_SERVICE, "ssl-context");
    final List<RELPFrame> frames = new ArrayList<>();
    frames.add(OPEN_FRAME);
    frames.add(SYSLOG_FRAME);
    frames.add(SYSLOG_FRAME);
    frames.add(SYSLOG_FRAME);
    frames.add(SYSLOG_FRAME);
    frames.add(SYSLOG_FRAME);
    frames.add(CLOSE_FRAME);
    // three syslog frames should be transferred and three responses should be sent
    run(frames, 5, 5, sslContextService);
}
Also used : StandardSSLContextService(org.apache.nifi.ssl.StandardSSLContextService) SSLContextService(org.apache.nifi.ssl.SSLContextService) StandardSSLContextService(org.apache.nifi.ssl.StandardSSLContextService) ArrayList(java.util.ArrayList) RELPFrame(org.apache.nifi.processors.standard.relp.frame.RELPFrame) Test(org.junit.Test)

Aggregations

RELPFrame (org.apache.nifi.processors.standard.relp.frame.RELPFrame)18 Test (org.junit.Test)14 ArrayList (java.util.ArrayList)3 InetAddress (java.net.InetAddress)2 HashMap (java.util.HashMap)2 ChannelResponse (org.apache.nifi.processor.util.listen.response.ChannelResponse)2 RELPFrameException (org.apache.nifi.processors.standard.relp.frame.RELPFrameException)2 ProvenanceEventRecord (org.apache.nifi.provenance.ProvenanceEventRecord)2 MockFlowFile (org.apache.nifi.util.MockFlowFile)2 BufferedOutputStream (java.io.BufferedOutputStream)1 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 Socket (java.net.Socket)1 SSLSocketChannelResponder (org.apache.nifi.processor.util.listen.response.socket.SSLSocketChannelResponder)1 SocketChannelResponder (org.apache.nifi.processor.util.listen.response.socket.SocketChannelResponder)1 RELPEvent (org.apache.nifi.processors.standard.relp.event.RELPEvent)1 RELPEncoder (org.apache.nifi.processors.standard.relp.frame.RELPEncoder)1 SSLContextService (org.apache.nifi.ssl.SSLContextService)1 StandardSSLContextService (org.apache.nifi.ssl.StandardSSLContextService)1