use of org.apache.flink.runtime.io.network.buffer.NetworkBuffer in project flink by apache.
the class NettyMessageClientSideSerializationTest method testBufferResponse.
private void testBufferResponse(boolean testReadOnlyBuffer, boolean testCompressedBuffer) {
checkArgument(!(testReadOnlyBuffer & testCompressedBuffer), "There are no cases with both readonly slice and compression.");
NetworkBuffer buffer = new NetworkBuffer(MemorySegmentFactory.allocateUnpooledSegment(BUFFER_SIZE), FreeingBufferRecycler.INSTANCE);
for (int i = 0; i < BUFFER_SIZE; i += 8) {
buffer.writeLong(i);
}
Buffer testBuffer = buffer;
if (testReadOnlyBuffer) {
testBuffer = buffer.readOnlySlice();
} else if (testCompressedBuffer) {
testBuffer = COMPRESSOR.compressToOriginalBuffer(buffer);
}
BufferResponse expected = new BufferResponse(testBuffer, random.nextInt(Integer.MAX_VALUE), inputChannelId, random.nextInt(Integer.MAX_VALUE));
BufferResponse actual = encodeAndDecode(expected, channel);
assertTrue(buffer.isRecycled());
assertTrue(testBuffer.isRecycled());
assertNotNull("The request input channel should always have available buffers in this test.", actual.getBuffer());
Buffer decodedBuffer = actual.getBuffer();
if (testCompressedBuffer) {
assertTrue(actual.isCompressed);
decodedBuffer = decompress(decodedBuffer);
}
verifyBufferResponseHeader(expected, actual);
assertEquals(BUFFER_SIZE, decodedBuffer.readableBytes());
for (int i = 0; i < BUFFER_SIZE; i += 8) {
assertEquals(i, decodedBuffer.asByteBuf().readLong());
}
// Release the received message.
actual.releaseBuffer();
if (testCompressedBuffer) {
decodedBuffer.recycleBuffer();
}
assertTrue(actual.getBuffer().isRecycled());
}
use of org.apache.flink.runtime.io.network.buffer.NetworkBuffer in project flink by apache.
the class CompressedHeaderlessChannelWriterOutputView method writeCompressed.
private void writeCompressed(MemorySegment current, int size) throws IOException {
MemorySegment compressedBuffer;
try {
compressedBuffer = compressedBuffers.take();
} catch (InterruptedException e) {
throw new IOException(e);
}
int compressedLen = compressor.compress(current.getArray(), 0, size, compressedBuffer.getArray(), 0);
NetworkBuffer networkBuffer = new NetworkBuffer(compressedBuffer, this);
networkBuffer.setSize(compressedLen);
writer.writeBlock(networkBuffer);
blockCount++;
numBytes += size;
numCompressedBytes += compressedLen;
}
use of org.apache.flink.runtime.io.network.buffer.NetworkBuffer in project flink by apache.
the class ChannelStateCheckpointWriterTest method testRecyclingBuffers.
@Test
public void testRecyclingBuffers() throws Exception {
ChannelStateCheckpointWriter writer = createWriter(new ChannelStateWriteResult());
NetworkBuffer buffer = new NetworkBuffer(MemorySegmentFactory.allocateUnpooledSegment(10, null), FreeingBufferRecycler.INSTANCE);
writer.writeInput(new InputChannelInfo(1, 2), buffer);
assertTrue(buffer.isRecycled());
}
use of org.apache.flink.runtime.io.network.buffer.NetworkBuffer in project flink by apache.
the class ChannelStateSerializerImplTest method getBuffer.
private NetworkBuffer getBuffer(byte[] data) {
NetworkBuffer buffer = new NetworkBuffer(MemorySegmentFactory.allocateUnpooledSegment(data.length, null), FreeingBufferRecycler.INSTANCE);
buffer.writeBytes(data);
return buffer;
}
use of org.apache.flink.runtime.io.network.buffer.NetworkBuffer in project flink by apache.
the class ChannelStateSerializerImplTest method write.
private void write(byte[] data, ChannelStateSerializerImpl serializer, OutputStream baos) throws IOException {
DataOutputStream out = new DataOutputStream(baos);
serializer.writeHeader(out);
NetworkBuffer buffer = new NetworkBuffer(MemorySegmentFactory.allocateUnpooledSegment(data.length), FreeingBufferRecycler.INSTANCE);
try {
buffer.writeBytes(data);
serializer.writeData(out, buffer);
out.flush();
} finally {
buffer.release();
}
}
Aggregations