use of org.apache.flink.runtime.io.network.buffer.NetworkBuffer in project flink by apache.
the class SyncChannelStateWriteRequestExecutor method testBuffersRecycledOnClose.
@Test
public void testBuffersRecycledOnClose() throws Exception {
NetworkBuffer buffer = getBuffer();
runWithSyncWorker(writer -> {
callStart(writer);
callAddInputData(writer, buffer);
assertFalse(buffer.isRecycled());
});
assertTrue(buffer.isRecycled());
}
use of org.apache.flink.runtime.io.network.buffer.NetworkBuffer in project flink by apache.
the class SyncChannelStateWriteRequestExecutor method testAbort.
@Test
public void testAbort() throws Exception {
NetworkBuffer buffer = getBuffer();
runWithSyncWorker((writer, worker) -> {
callStart(writer);
ChannelStateWriteResult result = writer.getAndRemoveWriteResult(CHECKPOINT_ID);
callAddInputData(writer, buffer);
callAbort(writer);
worker.processAllRequests();
assertTrue(result.isDone());
assertTrue(buffer.isRecycled());
});
}
use of org.apache.flink.runtime.io.network.buffer.NetworkBuffer in project flink by apache.
the class SyncChannelStateWriteRequestExecutor method testAbortClearsResults.
@Test(expected = IllegalArgumentException.class)
public void testAbortClearsResults() throws Exception {
NetworkBuffer buffer = getBuffer();
runWithSyncWorker((writer, worker) -> {
callStart(writer);
writer.abort(CHECKPOINT_ID, new TestException(), true);
writer.getAndRemoveWriteResult(CHECKPOINT_ID);
});
}
use of org.apache.flink.runtime.io.network.buffer.NetworkBuffer in project flink by apache.
the class SequentialChannelStateReaderImplTest method write.
private <T> Map<T, List<Long>> write(DataOutputStream dataStream, List<Tuple2<byte[], T>> partsPermuted) throws IOException {
Map<T, List<Long>> offsets = new HashMap<>();
for (Tuple2<byte[], T> t2 : partsPermuted) {
offsets.computeIfAbsent(t2.f1, unused -> new ArrayList<>()).add((long) dataStream.size());
NetworkBuffer networkBuffer = null;
try {
final byte[] bytes = t2.f0;
networkBuffer = wrap(bytes);
serializer.writeData(dataStream, networkBuffer);
} finally {
if (networkBuffer != null) {
networkBuffer.recycleBuffer();
}
}
}
return offsets;
}
use of org.apache.flink.runtime.io.network.buffer.NetworkBuffer in project flink by apache.
the class ChannelStateChunkReaderTest method getStream.
private static FSDataInputStream getStream(ChannelStateSerializer serializer, int size) throws IOException {
try (ByteArrayOutputStream out = new ByteArrayOutputStream()) {
DataOutputStream dataStream = new DataOutputStream(out);
serializer.writeHeader(dataStream);
serializer.writeData(dataStream, new NetworkBuffer(MemorySegmentFactory.wrap(new byte[size]), FreeingBufferRecycler.INSTANCE, Buffer.DataType.DATA_BUFFER, size));
dataStream.flush();
return new ByteStreamStateHandle("", out.toByteArray()).openInputStream();
}
}
Aggregations