Search in sources :

Example 36 with LengthFieldPrepender

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

the class LengthFieldPrependerTest method testAdjustedLengthLessThanZero.

@Test
public void testAdjustedLengthLessThanZero() throws Exception {
    final EmbeddedChannel ch = new EmbeddedChannel(new LengthFieldPrepender(4, -2));
    try {
        ch.writeOutbound(msg);
        fail(EncoderException.class.getSimpleName() + " must be raised.");
    } catch (EncoderException e) {
    // Expected
    }
}
Also used : EncoderException(io.netty.handler.codec.EncoderException) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) LengthFieldPrepender(io.netty.handler.codec.LengthFieldPrepender) Test(org.junit.jupiter.api.Test)

Example 37 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 38 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 39 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 40 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)44 LengthFieldBasedFrameDecoder (io.netty.handler.codec.LengthFieldBasedFrameDecoder)37 ChannelPipeline (io.netty.channel.ChannelPipeline)22 SocketChannel (io.netty.channel.socket.SocketChannel)18 Bootstrap (io.netty.bootstrap.Bootstrap)14 NioEventLoopGroup (io.netty.channel.nio.NioEventLoopGroup)14 StringDecoder (io.netty.handler.codec.string.StringDecoder)13 StringEncoder (io.netty.handler.codec.string.StringEncoder)13 ServerBootstrap (io.netty.bootstrap.ServerBootstrap)11 Channel (io.netty.channel.Channel)11 ChannelFuture (io.netty.channel.ChannelFuture)11 NioSocketChannel (io.netty.channel.socket.nio.NioSocketChannel)11 NioServerSocketChannel (io.netty.channel.socket.nio.NioServerSocketChannel)10 IOException (java.io.IOException)8 EventLoopGroup (io.netty.channel.EventLoopGroup)7 EpollEventLoopGroup (io.netty.channel.epoll.EpollEventLoopGroup)6 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)5 Test (org.junit.jupiter.api.Test)5 ByteBuf (io.netty.buffer.ByteBuf)4 VersionPrepender (org.neo4j.causalclustering.VersionPrepender)4