Hi

I am new to Netty (using 4.0.24-Final) so I am probably missing something 
vital. I am trying to write a JUnit test to check that I can handle a 
client that simply dies in mid-transmission. I am simulating this by 
sending a short message that never completes. I was expecting the 
ReadTimeoutHandler to fire and the ExceptionHandler would close the 
connection. However, I can see through debug that the ReadTimeoutHandler 
never fires and the ExceptionHandler is never called.




This is my unit test

        @Test
        public void 
ifMessageDataLengthIsLessThanLengthDeclaredThenConnectionIsClosed() {
       
        int MAX_EXPECTED_MESSAGE_LENGTH_IN_BYTES = 20;
        int TIME_OUT_IN_SECS = 4;
        byte[] bytes = new byte[] {0x09, 0x01, 0x02, 0x03, 0x04, 0x05};
        
        EmbeddedChannel channel = new EmbeddedChannel(new 
ReadTimeoutHandler(TIME_OUT_IN_SECS)
                                        , new 
LengthFieldBasedFrameDecoder(MAX_EXPECTED_MESSAGE_LENGTH_IN_BYTES,0,1,0,1)
                                        , new ExceptionHandler());
        
        channel.writeInbound(Unpooled.wrappedBuffer(bytes));
        
        assertTrue(channel.isOpen());
        
        sleepForMilliSecs((TIME_OUT_IN_SECS + 2) * 1000);
        
        assertTrue(!channel.isOpen());
    }
    
    
    private void sleepForMilliSecs(int millis) {
        try {
            Thread.sleep(millis);
        } catch (InterruptedException e) {
           
        }
        
    }

and my ExceptionHandler

    public class ExceptionHandler extends ChannelInboundHandlerAdapter {
    
    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) 
throws Exception {
        System.out.println("Exception handler is called with " + cause);
        ctx.close();
    }

}

-- 
You received this message because you are subscribed to the Google Groups 
"Netty discussions" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/netty/d2f160ee-37a7-4af8-a205-ab5787ab0dff%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to