### Question:
LengthFieldBasedFrameDecoder extends FrameDecoder { private void fail(ChannelHandlerContext ctx, long frameLength) { if (frameLength > 0) { Channels.fireExceptionCaught( ctx.getChannel(), new TooLongFrameException( "Adjusted frame length exceeds " + maxFrameLength + ": " + frameLength + " - discarded")); } else { Channels.fireExceptionCaught( ctx.getChannel(), new TooLongFrameException( "Adjusted frame length exceeds " + maxFrameLength + " - discarding")); } } LengthFieldBasedFrameDecoder(
            int maxFrameLength,
            int lengthFieldOffset, int lengthFieldLength);  LengthFieldBasedFrameDecoder(
            int maxFrameLength,
            int lengthFieldOffset, int lengthFieldLength,
            int lengthAdjustment, int initialBytesToStrip);  LengthFieldBasedFrameDecoder(
            int maxFrameLength,
            int lengthFieldOffset, int lengthFieldLength,
            int lengthAdjustment, int initialBytesToStrip, boolean failFast);   }### Answer:
@Test public void testFailSlowTooLongFrameRecovery() throws Exception { DecoderEmbedder<ChannelBuffer> embedder = new DecoderEmbedder<ChannelBuffer>( new LengthFieldBasedFrameDecoder(5, 0, 4, 0, 4)); for (int i = 0; i < 2; i ++) { embedder.offer(ChannelBuffers.wrappedBuffer(new byte[] { 0, 0, 0, 2 })); try { embedder.offer(ChannelBuffers.wrappedBuffer(new byte[] { 0, 0 })); Assert.fail(CodecEmbedderException.class.getSimpleName() + " must be raised."); } catch (CodecEmbedderException e) { Assert.assertTrue(e.getCause() instanceof TooLongFrameException); } embedder.offer(ChannelBuffers.wrappedBuffer(new byte[] { 0, 0, 0, 1, 'A' })); ChannelBuffer buf = embedder.poll(); Assert.assertEquals("A", buf.toString(CharsetUtil.ISO_8859_1)); } }
@Test public void testFailFastTooLongFrameRecovery() throws Exception { DecoderEmbedder<ChannelBuffer> embedder = new DecoderEmbedder<ChannelBuffer>( new LengthFieldBasedFrameDecoder(5, 0, 4, 0, 4, true)); for (int i = 0; i < 2; i ++) { try { embedder.offer(ChannelBuffers.wrappedBuffer(new byte[] { 0, 0, 0, 2 })); Assert.fail(CodecEmbedderException.class.getSimpleName() + " must be raised."); } catch (CodecEmbedderException e) { Assert.assertTrue(e.getCause() instanceof TooLongFrameException); } embedder.offer(ChannelBuffers.wrappedBuffer(new byte[] { 0, 0, 0, 0, 0, 1, 'A' })); ChannelBuffer buf = embedder.poll(); Assert.assertEquals("A", buf.toString(CharsetUtil.ISO_8859_1)); } }