Search in sources :

Example 1 with PingMessage

use of org.apache.nifi.cluster.protocol.message.PingMessage in project nifi by apache.

the class SocketProtocolListenerTest method testDelayedRequest.

@Test
public void testDelayedRequest() throws Exception {
    ProtocolMessage msg = new PingMessage();
    DelayedProtocolHandler handler = new DelayedProtocolHandler(2000);
    listener.addHandler(handler);
    // marshal message to output stream
    marshaller.marshal(msg, socket.getOutputStream());
    try {
        socket.getInputStream().read();
        fail("Socket timeout not received.");
    } catch (SocketTimeoutException ste) {
    }
    assertEquals(1, handler.getMessages().size());
    assertEquals(msg.getType(), handler.getMessages().get(0).getType());
}
Also used : SocketTimeoutException(java.net.SocketTimeoutException) DelayedProtocolHandler(org.apache.nifi.cluster.protocol.impl.testutils.DelayedProtocolHandler) ProtocolMessage(org.apache.nifi.cluster.protocol.message.ProtocolMessage) PingMessage(org.apache.nifi.cluster.protocol.message.PingMessage) Test(org.junit.Test)

Example 2 with PingMessage

use of org.apache.nifi.cluster.protocol.message.PingMessage in project nifi by apache.

the class SocketProtocolListenerTest method testRequest.

@Test
public void testRequest() throws Exception {
    ProtocolMessage msg = new PingMessage();
    ReflexiveProtocolHandler handler = new ReflexiveProtocolHandler();
    listener.addHandler(handler);
    // marshal message to output stream
    marshaller.marshal(msg, socket.getOutputStream());
    // unmarshall response and return
    ProtocolMessage response = unmarshaller.unmarshal(socket.getInputStream());
    assertEquals(msg.getType(), response.getType());
    assertEquals(1, handler.getMessages().size());
    assertEquals(msg.getType(), handler.getMessages().get(0).getType());
}
Also used : ReflexiveProtocolHandler(org.apache.nifi.cluster.protocol.impl.testutils.ReflexiveProtocolHandler) ProtocolMessage(org.apache.nifi.cluster.protocol.message.ProtocolMessage) PingMessage(org.apache.nifi.cluster.protocol.message.PingMessage) Test(org.junit.Test)

Aggregations

PingMessage (org.apache.nifi.cluster.protocol.message.PingMessage)2 ProtocolMessage (org.apache.nifi.cluster.protocol.message.ProtocolMessage)2 Test (org.junit.Test)2 SocketTimeoutException (java.net.SocketTimeoutException)1 DelayedProtocolHandler (org.apache.nifi.cluster.protocol.impl.testutils.DelayedProtocolHandler)1 ReflexiveProtocolHandler (org.apache.nifi.cluster.protocol.impl.testutils.ReflexiveProtocolHandler)1