use of org.apache.flink.shaded.netty4.io.netty.buffer.CompositeByteBuf in project netty by netty.
the class AbstractIntegrationTest method testIdentity.
protected void testIdentity(final byte[] data, boolean heapBuffer) {
initChannels();
final ByteBuf in = heapBuffer ? Unpooled.wrappedBuffer(data) : Unpooled.directBuffer(data.length).setBytes(0, data);
final CompositeByteBuf compressed = Unpooled.compositeBuffer();
final CompositeByteBuf decompressed = Unpooled.compositeBuffer();
try {
assertTrue(encoder.writeOutbound(in.retain()));
assertTrue(encoder.finish());
ByteBuf msg;
while ((msg = encoder.readOutbound()) != null) {
compressed.addComponent(true, msg);
}
assertThat(compressed, is(notNullValue()));
decoder.writeInbound(compressed.retain());
assertFalse(compressed.isReadable());
while ((msg = decoder.readInbound()) != null) {
decompressed.addComponent(true, msg);
}
in.readerIndex(0);
assertEquals(in, decompressed);
} finally {
compressed.release();
decompressed.release();
in.release();
closeChannels();
}
}
use of org.apache.flink.shaded.netty4.io.netty.buffer.CompositeByteBuf in project netty by netty.
the class LzmaFrameEncoderTest method testCompressionOfBatchedFlow.
@Override
protected void testCompressionOfBatchedFlow(final ByteBuf data) throws Exception {
List<Integer> originalLengths = new ArrayList<Integer>();
final int dataLength = data.readableBytes();
int written = 0, length = rand.nextInt(50);
while (written + length < dataLength) {
ByteBuf in = data.retainedSlice(written, length);
assertTrue(channel.writeOutbound(in));
written += length;
originalLengths.add(length);
length = rand.nextInt(50);
}
length = dataLength - written;
ByteBuf in = data.retainedSlice(written, dataLength - written);
originalLengths.add(length);
assertTrue(channel.writeOutbound(in));
assertTrue(channel.finish());
CompositeByteBuf decompressed = Unpooled.compositeBuffer();
ByteBuf msg;
int i = 0;
while ((msg = channel.readOutbound()) != null) {
ByteBuf decompressedMsg = decompress(msg, originalLengths.get(i++));
decompressed.addComponent(true, decompressedMsg);
}
assertEquals(originalLengths.size(), i);
assertEquals(data, decompressed);
decompressed.release();
data.release();
}
use of org.apache.flink.shaded.netty4.io.netty.buffer.CompositeByteBuf in project netty by netty.
the class BrotliDecoderTest method readDecompressed.
private static ByteBuf readDecompressed(final EmbeddedChannel channel) {
CompositeByteBuf decompressed = Unpooled.compositeBuffer();
ByteBuf msg;
while ((msg = channel.readInbound()) != null) {
decompressed.addComponent(true, msg);
}
return decompressed;
}
use of org.apache.flink.shaded.netty4.io.netty.buffer.CompositeByteBuf in project netty by netty.
the class ByteToMessageDecoderTest method releaseWhenCompositeCumulateThrows.
@Test
public void releaseWhenCompositeCumulateThrows() {
final Error error = new Error();
ByteBuf cumulation = new CompositeByteBuf(UnpooledByteBufAllocator.DEFAULT, false, 64) {
@Override
public CompositeByteBuf addComponent(boolean increaseWriterIndex, ByteBuf buffer) {
throw error;
}
@Override
public CompositeByteBuf addFlattenedComponents(boolean increaseWriterIndex, ByteBuf buffer) {
throw error;
}
}.writeZero(1);
ByteBuf in = Unpooled.buffer().writeZero(12);
try {
ByteToMessageDecoder.COMPOSITE_CUMULATOR.cumulate(UnpooledByteBufAllocator.DEFAULT, cumulation, in);
fail();
} catch (Error expected) {
assertSame(error, expected);
assertEquals(0, in.refCnt());
cumulation.release();
}
}
use of org.apache.flink.shaded.netty4.io.netty.buffer.CompositeByteBuf in project netty by netty.
the class UnixChannelUtilTest method assertCompositeByteBufIsBufferCopyNeededForWrite.
private static void assertCompositeByteBufIsBufferCopyNeededForWrite(ByteBufAllocator alloc, int numDirect, int numHeap, boolean expected) {
CompositeByteBuf comp = alloc.compositeBuffer(numDirect + numHeap);
List<ByteBuf> byteBufs = new LinkedList<ByteBuf>();
while (numDirect > 0) {
byteBufs.add(alloc.directBuffer(1));
numDirect--;
}
while (numHeap > 0) {
byteBufs.add(alloc.heapBuffer(1));
numHeap--;
}
Collections.shuffle(byteBufs);
for (ByteBuf byteBuf : byteBufs) {
comp.addComponent(byteBuf);
}
assertEquals(expected, isBufferCopyNeededForWrite(comp, IOV_MAX), byteBufs.toString());
assertTrue(comp.release());
}
Aggregations