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();
}
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();
}
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());
});
}
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();
}
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());
});
}
Aggregations