Search in sources :

Example 31 with LengthFieldPrepender

use of io.netty.handler.codec.LengthFieldPrepender in project netty by netty.

the class LengthFieldPrependerTest method testPrependLengthInLittleEndian.

@Test
public void testPrependLengthInLittleEndian() throws Exception {
    final EmbeddedChannel ch = new EmbeddedChannel(new LengthFieldPrepender(ByteOrder.LITTLE_ENDIAN, 4, 0, false));
    ch.writeOutbound(msg);
    ByteBuf buf = ch.readOutbound();
    assertEquals(4, buf.readableBytes());
    byte[] writtenBytes = new byte[buf.readableBytes()];
    buf.getBytes(0, writtenBytes);
    assertEquals(1, writtenBytes[0]);
    assertEquals(0, writtenBytes[1]);
    assertEquals(0, writtenBytes[2]);
    assertEquals(0, writtenBytes[3]);
    buf.release();
    buf = ch.readOutbound();
    assertSame(buf, msg);
    buf.release();
    assertFalse(ch.finish(), "The channel must have been completely read");
}
Also used : EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) LengthFieldPrepender(io.netty.handler.codec.LengthFieldPrepender) ByteBuf(io.netty.buffer.ByteBuf) Test(org.junit.jupiter.api.Test)

Example 32 with LengthFieldPrepender

use of io.netty.handler.codec.LengthFieldPrepender in project netty by netty.

the class LengthFieldPrependerTest method testPrependLength.

@Test
public void testPrependLength() throws Exception {
    final EmbeddedChannel ch = new EmbeddedChannel(new LengthFieldPrepender(4));
    ch.writeOutbound(msg);
    ByteBuf buf = ch.readOutbound();
    assertEquals(4, buf.readableBytes());
    assertEquals(msg.readableBytes(), buf.readInt());
    buf.release();
    buf = ch.readOutbound();
    assertSame(buf, msg);
    buf.release();
}
Also used : EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) LengthFieldPrepender(io.netty.handler.codec.LengthFieldPrepender) ByteBuf(io.netty.buffer.ByteBuf) Test(org.junit.jupiter.api.Test)

Example 33 with LengthFieldPrepender

use of io.netty.handler.codec.LengthFieldPrepender in project netty by netty.

the class LengthFieldPrependerTest method testPrependLengthIncludesLengthFieldLength.

@Test
public void testPrependLengthIncludesLengthFieldLength() throws Exception {
    final EmbeddedChannel ch = new EmbeddedChannel(new LengthFieldPrepender(4, true));
    ch.writeOutbound(msg);
    ByteBuf buf = ch.readOutbound();
    assertEquals(4, buf.readableBytes());
    assertEquals(5, buf.readInt());
    buf.release();
    buf = ch.readOutbound();
    assertSame(buf, msg);
    buf.release();
}
Also used : EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) LengthFieldPrepender(io.netty.handler.codec.LengthFieldPrepender) ByteBuf(io.netty.buffer.ByteBuf) Test(org.junit.jupiter.api.Test)

Example 34 with LengthFieldPrepender

use of io.netty.handler.codec.LengthFieldPrepender in project netty by netty.

the class LengthFieldPrependerTest method testPrependAdjustedLength.

@Test
public void testPrependAdjustedLength() throws Exception {
    final EmbeddedChannel ch = new EmbeddedChannel(new LengthFieldPrepender(4, -1));
    ch.writeOutbound(msg);
    ByteBuf buf = ch.readOutbound();
    assertEquals(4, buf.readableBytes());
    assertEquals(msg.readableBytes() - 1, buf.readInt());
    buf.release();
    buf = ch.readOutbound();
    assertSame(buf, msg);
    buf.release();
}
Also used : EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) LengthFieldPrepender(io.netty.handler.codec.LengthFieldPrepender) ByteBuf(io.netty.buffer.ByteBuf) Test(org.junit.jupiter.api.Test)

Aggregations

LengthFieldPrepender (io.netty.handler.codec.LengthFieldPrepender)34 LengthFieldBasedFrameDecoder (io.netty.handler.codec.LengthFieldBasedFrameDecoder)27 SocketChannel (io.netty.channel.socket.SocketChannel)14 ChannelPipeline (io.netty.channel.ChannelPipeline)13 NioEventLoopGroup (io.netty.channel.nio.NioEventLoopGroup)13 Bootstrap (io.netty.bootstrap.Bootstrap)10 NioSocketChannel (io.netty.channel.socket.nio.NioSocketChannel)10 ServerBootstrap (io.netty.bootstrap.ServerBootstrap)9 NioServerSocketChannel (io.netty.channel.socket.nio.NioServerSocketChannel)9 StringDecoder (io.netty.handler.codec.string.StringDecoder)9 StringEncoder (io.netty.handler.codec.string.StringEncoder)9 ChannelFuture (io.netty.channel.ChannelFuture)8 Channel (io.netty.channel.Channel)7 EventLoopGroup (io.netty.channel.EventLoopGroup)5 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)5 Test (org.junit.jupiter.api.Test)5 ByteBuf (io.netty.buffer.ByteBuf)4 EpollEventLoopGroup (io.netty.channel.epoll.EpollEventLoopGroup)4 IOException (java.io.IOException)4 VersionPrepender (org.neo4j.causalclustering.VersionPrepender)4