That is because the EmbeddedChannel not really support running scheduled tasks 
by itself as everything is just done in the calling thread. Just call  
`runPendingTasks()` after the sleep and it should have the effect you expect.

> On 27. Mar 2017, at 09:20, 'Roger Varley' via Netty discussions 
> <[email protected]> wrote:
> 
> 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] 
> <mailto:[email protected]>.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/netty/d2f160ee-37a7-4af8-a205-ab5787ab0dff%40googlegroups.com
>  
> <https://groups.google.com/d/msgid/netty/d2f160ee-37a7-4af8-a205-ab5787ab0dff%40googlegroups.com?utm_medium=email&utm_source=footer>.
> For more options, visit https://groups.google.com/d/optout 
> <https://groups.google.com/d/optout>.

-- 
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/7D1EAB61-AB6C-435C-B0F9-0B91AE700F1D%40googlemail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to