private void fail(long frameLength) {
        if (frameLength > 0) {
            throw new TooLongFrameException(
                            "Adjusted frame length exceeds " + maxFrameLength +
                            ": " + frameLength + " - discarded");
        } else {
            throw new TooLongFrameException(
                            "Adjusted frame length exceeds " + maxFrameLength +
                            " - discarding");
        }
    }
@Test
    public void testDiscardTooLongFrame1() {
        ByteBuf buf = Unpooled.buffer();
        buf.writeInt(32);
        for (int i = 0; i < 32; i++) {
            buf.writeByte(i);
        }
        buf.writeInt(1);
        buf.writeByte('a');
        EmbeddedChannel channel = new EmbeddedChannel(new LengthFieldBasedFrameDecoder(16, 0, 4));
        try {
            channel.writeInbound(buf);
            fail();
        } catch (TooLongFrameException e) {
            // expected
        }
        assertTrue(channel.finish());

        ByteBuf b = channel.readInbound();
        assertEquals(5, b.readableBytes());
        assertEquals(1, b.readInt());
        assertEquals('a', b.readByte());
        b.release();

        assertNull(channel.readInbound());
        channel.finish();
    }