Search in sources :

Example 11 with RELPFrame

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

the class TestRELPResponse method testResponseToFrame.

@Test
public void testResponseToFrame() throws IOException {
    final long txnr = 123456789;
    final int code = RELPResponse.OK;
    final String message = "this is a message";
    final String data = "this is some data";
    final RELPResponse response = new RELPResponse(txnr, code, message, data);
    final RELPFrame frame = response.toFrame(StandardCharsets.UTF_8);
    Assert.assertEquals(txnr, frame.getTxnr());
    Assert.assertEquals(RELPResponse.RSP_CMD, frame.getCommand());
    final String result = new String(frame.getData(), StandardCharsets.UTF_8);
    final String expected = code + " " + message + "\n" + data;
    Assert.assertEquals(expected, result);
    Assert.assertEquals(expected.length(), frame.getDataLength());
}
Also used : RELPFrame(org.apache.nifi.processors.standard.relp.frame.RELPFrame) Test(org.junit.Test)

Example 12 with RELPFrame

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

the class TestRELPResponse method testResponseToFrameNoDataNoMessage.

@Test
public void testResponseToFrameNoDataNoMessage() throws IOException {
    final long txnr = 123456789;
    final int code = RELPResponse.OK;
    final RELPResponse response = new RELPResponse(txnr, code);
    final RELPFrame frame = response.toFrame(StandardCharsets.UTF_8);
    Assert.assertEquals(txnr, frame.getTxnr());
    Assert.assertEquals(RELPResponse.RSP_CMD, frame.getCommand());
    final String result = new String(frame.getData(), StandardCharsets.UTF_8);
    final String expected = code + "";
    Assert.assertEquals(expected, result);
    Assert.assertEquals(expected.length(), frame.getDataLength());
}
Also used : RELPFrame(org.apache.nifi.processors.standard.relp.frame.RELPFrame) Test(org.junit.Test)

Example 13 with RELPFrame

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

the class TestRELPResponse method testCreateOpenResponse.

@Test
public void testCreateOpenResponse() {
    final long txnr = 123456789;
    final Map<String, String> offers = new HashMap<>();
    offers.put("key1", "val1");
    offers.put("key2", "val2");
    final RELPResponse openResponse = RELPResponse.open(txnr, offers);
    final RELPFrame frame = openResponse.toFrame(StandardCharsets.UTF_8);
    Assert.assertEquals(txnr, frame.getTxnr());
    Assert.assertEquals(RELPResponse.RSP_CMD, frame.getCommand());
    final String result = new String(frame.getData(), StandardCharsets.UTF_8);
    final String expected1 = RELPResponse.OK + " OK\n" + "key1=val1\nkey2=val2";
    final String expected2 = RELPResponse.OK + " OK\n" + "key2=val2\nkey1=val1";
    Assert.assertTrue(result.equals(expected1) || result.equals(expected2));
    Assert.assertEquals(expected1.length(), frame.getDataLength());
}
Also used : HashMap(java.util.HashMap) RELPFrame(org.apache.nifi.processors.standard.relp.frame.RELPFrame) Test(org.junit.Test)

Example 14 with RELPFrame

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

the class TestRELPResponse method testResponseToFrameNoMessage.

@Test
public void testResponseToFrameNoMessage() throws IOException {
    final long txnr = 123456789;
    final int code = RELPResponse.OK;
    final String data = "this is some data";
    final RELPResponse response = new RELPResponse(txnr, code, null, data);
    final RELPFrame frame = response.toFrame(StandardCharsets.UTF_8);
    Assert.assertEquals(txnr, frame.getTxnr());
    Assert.assertEquals(RELPResponse.RSP_CMD, frame.getCommand());
    final String result = new String(frame.getData(), StandardCharsets.UTF_8);
    final String expected = code + "\n" + data;
    Assert.assertEquals(expected, result);
    Assert.assertEquals(expected.length(), frame.getDataLength());
}
Also used : RELPFrame(org.apache.nifi.processors.standard.relp.frame.RELPFrame) Test(org.junit.Test)

Example 15 with RELPFrame

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

the class TestRELPResponse method testResponseToFrameNoData.

@Test
public void testResponseToFrameNoData() throws IOException {
    final long txnr = 123456789;
    final int code = RELPResponse.OK;
    final String message = "this is a message";
    final RELPResponse response = new RELPResponse(txnr, code, message, null);
    final RELPFrame frame = response.toFrame(StandardCharsets.UTF_8);
    Assert.assertEquals(txnr, frame.getTxnr());
    Assert.assertEquals(RELPResponse.RSP_CMD, frame.getCommand());
    final String result = new String(frame.getData(), StandardCharsets.UTF_8);
    final String expected = code + " " + message;
    Assert.assertEquals(expected, result);
    Assert.assertEquals(expected.length(), frame.getDataLength());
}
Also used : 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