Search in sources :

Example 66 with ByteBuf

use of org.apache.flink.shaded.netty4.io.netty.buffer.ByteBuf in project LogisticsPipes by RS485.

the class LPDataIOWrapperTest method testWriteBoolean.

@Test
@SuppressWarnings("ConstantConditions")
public void testWriteBoolean() throws Exception {
    boolean value = true;
    ByteBuf testBuffer = buffer(1);
    LPDataIOWrapper.writeData(testBuffer, output -> output.writeBoolean(value));
    ByteBuf compareBuffer = buffer(1);
    compareBuffer.writeBoolean(value);
    assertTrue(ByteBufUtil.equals(testBuffer, compareBuffer));
    testBuffer.release();
    compareBuffer.release();
}
Also used : ByteBuf(io.netty.buffer.ByteBuf) Test(org.junit.Test)

Example 67 with ByteBuf

use of org.apache.flink.shaded.netty4.io.netty.buffer.ByteBuf in project LogisticsPipes by RS485.

the class LPDataIOWrapperTest method testWriteByteArray.

@Test
public void testWriteByteArray() throws Exception {
    ByteBuf dataBuffer = buffer(Integer.BYTES * 2);
    byte[] arr = TestUtil.getBytesFromInteger(-1);
    LPDataIOWrapper.writeData(dataBuffer, dataOutput -> dataOutput.writeByteArray(arr));
    assertEquals(4, dataBuffer.readInt());
    assertEquals(-1, dataBuffer.readInt());
    assertEquals(BUFFER_EMPTY_MSG, 0, dataBuffer.readableBytes());
    dataBuffer.release();
}
Also used : ByteBuf(io.netty.buffer.ByteBuf) Test(org.junit.Test)

Example 68 with ByteBuf

use of org.apache.flink.shaded.netty4.io.netty.buffer.ByteBuf in project LogisticsPipes by RS485.

the class LPDataIOWrapperTest method testByteBuf.

@Test
public void testByteBuf() throws Exception {
    byte[] arr = TestUtil.getBytesFromInteger(741893247);
    ByteBuf testBuffer = buffer(arr.length);
    LPDataIOWrapper.writeData(testBuffer, output -> output.writeBytes(arr));
    // buffer in byte array
    byte[] data = LPDataIOWrapper.collectData(output -> output.writeByteBuf(testBuffer));
    LPDataIOWrapper.provideData(data, input -> {
        LPDataIOWrapper.provideData(input.readByteBuf(), bufferInput -> {
            assertArrayEquals(arr, bufferInput.readBytes(arr.length));
            assertEquals(BUFFER_EMPTY_MSG, 0, ((LPDataIOWrapper) bufferInput).localBuffer.readableBytes());
        });
        assertEquals(BUFFER_EMPTY_MSG, 0, ((LPDataIOWrapper) input).localBuffer.readableBytes());
    });
}
Also used : ByteBuf(io.netty.buffer.ByteBuf) Test(org.junit.Test)

Example 69 with ByteBuf

use of org.apache.flink.shaded.netty4.io.netty.buffer.ByteBuf in project LogisticsPipes by RS485.

the class LPDataIOWrapperTest method testWriteByte.

@Test
public void testWriteByte() throws Exception {
    byte value = 0x6f;
    ByteBuf testBuffer = buffer(Byte.BYTES);
    LPDataIOWrapper.writeData(testBuffer, output -> output.writeByte(value));
    ByteBuf compareBuffer = buffer(Byte.BYTES);
    compareBuffer.writeByte(value);
    assertTrue(ByteBufUtil.equals(testBuffer, compareBuffer));
    testBuffer.release();
    compareBuffer.release();
}
Also used : ByteBuf(io.netty.buffer.ByteBuf) Test(org.junit.Test)

Example 70 with ByteBuf

use of org.apache.flink.shaded.netty4.io.netty.buffer.ByteBuf in project LogisticsPipes by RS485.

the class LPDataIOWrapperTest method testReadLong.

@Test
public void testReadLong() throws Exception {
    long value = 1092347801374L;
    ByteBuf dataBuffer = buffer(Long.BYTES);
    dataBuffer.writeLong(value);
    LPDataIOWrapper.provideData(dataBuffer, input -> {
        assertEquals(value, input.readLong());
        assertEquals(BUFFER_EMPTY_MSG, 0, ((LPDataIOWrapper) input).localBuffer.readableBytes());
    });
}
Also used : ByteBuf(io.netty.buffer.ByteBuf) Test(org.junit.Test)

Aggregations

ByteBuf (io.netty.buffer.ByteBuf)5080 Test (org.junit.Test)1813 Test (org.junit.jupiter.api.Test)680 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)377 ArrayList (java.util.ArrayList)301 IOException (java.io.IOException)297 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)200 CompositeByteBuf (io.netty.buffer.CompositeByteBuf)182 ByteBuffer (java.nio.ByteBuffer)167 InetSocketAddress (java.net.InetSocketAddress)145 ByteBuf (org.apache.flink.shaded.netty4.io.netty.buffer.ByteBuf)144 Test (org.testng.annotations.Test)140 Channel (io.netty.channel.Channel)137 List (java.util.List)134 ChannelFuture (io.netty.channel.ChannelFuture)128 Map (java.util.Map)118 MatchEntryBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntryBuilder)107 Position (org.traccar.model.Position)105 DeviceSession (org.traccar.DeviceSession)100 NetworkMessage (org.traccar.NetworkMessage)93