ByteToMessageCodecTest Class — netty Architecture
Architecture documentation for the ByteToMessageCodecTest class in ByteToMessageCodecTest.java from the netty codebase.
Entity Profile
Dependency Diagram
graph TD 50026bb4_a91a_3459_adea_65a461d42761["ByteToMessageCodecTest"] 01532906_983a_c4a4_89dc_14359bd234c1["ByteToMessageCodecTest.java"] 50026bb4_a91a_3459_adea_65a461d42761 -->|defined in| 01532906_983a_c4a4_89dc_14359bd234c1 579f4c27_5dc0_3b23_5b43_ec59a255d3c0["testSharable()"] 50026bb4_a91a_3459_adea_65a461d42761 -->|method| 579f4c27_5dc0_3b23_5b43_ec59a255d3c0 86fc3fad_bf3d_eb88_0914_0e72783b1c03["testSharable2()"] 50026bb4_a91a_3459_adea_65a461d42761 -->|method| 86fc3fad_bf3d_eb88_0914_0e72783b1c03 d72df527_8e9d_88aa_bcc9_1dbc13f21533["testForwardPendingData()"] 50026bb4_a91a_3459_adea_65a461d42761 -->|method| d72df527_8e9d_88aa_bcc9_1dbc13f21533
Relationship Graph
Source Code
codec-base/src/test/java/io/netty/handler/codec/ByteToMessageCodecTest.java lines 33–113
public class ByteToMessageCodecTest {
@Test
public void testSharable() {
assertThrows(IllegalStateException.class, new Executable() {
@Override
public void execute() {
new InvalidByteToMessageCodec();
}
});
}
@Test
public void testSharable2() {
assertThrows(IllegalStateException.class, new Executable() {
@Override
public void execute() {
new InvalidByteToMessageCodec2();
}
});
}
@Test
public void testForwardPendingData() {
ByteToMessageCodec<Integer> codec = new ByteToMessageCodec<Integer>() {
@Override
protected void encode(ChannelHandlerContext ctx, Integer msg, ByteBuf out) {
out.writeInt(msg);
}
@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) {
if (in.readableBytes() >= 4) {
out.add(in.readInt());
}
}
};
ByteBuf buffer = Unpooled.buffer();
buffer.writeInt(1);
buffer.writeByte('0');
EmbeddedChannel ch = new EmbeddedChannel(codec);
assertTrue(ch.writeInbound(buffer));
ch.pipeline().remove(codec);
assertTrue(ch.finish());
assertEquals(1, (Integer) ch.readInbound());
ByteBuf buf = ch.readInbound();
assertEquals(Unpooled.wrappedBuffer(new byte[]{'0'}), buf);
buf.release();
assertNull(ch.readInbound());
assertNull(ch.readOutbound());
}
@ChannelHandler.Sharable
private static final class InvalidByteToMessageCodec extends ByteToMessageCodec<Integer> {
InvalidByteToMessageCodec() {
super(true);
}
@Override
protected void encode(ChannelHandlerContext ctx, Integer msg, ByteBuf out) throws Exception { }
@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception { }
}
@ChannelHandler.Sharable
private static final class InvalidByteToMessageCodec2 extends ByteToMessageCodec<Integer> {
InvalidByteToMessageCodec2() {
super(Integer.class, true);
}
@Override
protected void encode(ChannelHandlerContext ctx, Integer msg, ByteBuf out) throws Exception { }
@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception { }
}
}
Source
Frequently Asked Questions
What is the ByteToMessageCodecTest class?
ByteToMessageCodecTest is a class in the netty codebase, defined in codec-base/src/test/java/io/netty/handler/codec/ByteToMessageCodecTest.java.
Where is ByteToMessageCodecTest defined?
ByteToMessageCodecTest is defined in codec-base/src/test/java/io/netty/handler/codec/ByteToMessageCodecTest.java at line 33.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free