Search in sources :

Example 1 with DelayedProtocolHandler

use of org.apache.nifi.cluster.protocol.impl.testutils.DelayedProtocolHandler 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 DelayedProtocolHandler

use of org.apache.nifi.cluster.protocol.impl.testutils.DelayedProtocolHandler in project nifi by apache.

the class SocketProtocolListenerTest method testBadRequest.

@Test
public void testBadRequest() throws Exception {
    DelayedProtocolHandler handler = new DelayedProtocolHandler(0);
    listener.addHandler(handler);
    socket.getOutputStream().write(5);
    Thread.sleep(250);
    assertEquals(0, handler.getMessages().size());
}
Also used : DelayedProtocolHandler(org.apache.nifi.cluster.protocol.impl.testutils.DelayedProtocolHandler) Test(org.junit.Test)

Aggregations

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