use of org.apache.flink.runtime.checkpoint.channel.ChannelStateWriter.ChannelStateWriteResult 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.checkpoint.channel.ChannelStateWriter.ChannelStateWriteResult in project flink by apache.
the class ChannelStateCheckpointWriterTest method testEmptyState.
@Test
public void testEmptyState() throws Exception {
MemoryCheckpointOutputStream stream = new MemoryCheckpointOutputStream(1000) {
@Override
public StreamStateHandle closeAndGetHandle() {
fail("closeAndGetHandle shouldn't be called for empty channel state");
return null;
}
};
ChannelStateCheckpointWriter writer = createWriter(new ChannelStateWriteResult(), stream);
writer.completeOutput();
writer.completeInput();
assertTrue(stream.isClosed());
}
use of org.apache.flink.runtime.checkpoint.channel.ChannelStateWriter.ChannelStateWriteResult in project flink by apache.
the class ChannelStateCheckpointWriterTest method testRecordingOffsets.
@Test
public void testRecordingOffsets() throws Exception {
Map<InputChannelInfo, Integer> offsetCounts = new HashMap<>();
offsetCounts.put(new InputChannelInfo(1, 1), 1);
offsetCounts.put(new InputChannelInfo(1, 2), 2);
offsetCounts.put(new InputChannelInfo(1, 3), 5);
int numBytes = 100;
ChannelStateWriteResult result = new ChannelStateWriteResult();
ChannelStateCheckpointWriter writer = createWriter(result);
for (Map.Entry<InputChannelInfo, Integer> e : offsetCounts.entrySet()) {
for (int i = 0; i < e.getValue(); i++) {
write(writer, e.getKey(), getData(numBytes));
}
}
writer.completeInput();
writer.completeOutput();
for (InputChannelStateHandle handle : result.inputChannelStateHandles.get()) {
int headerSize = Integer.BYTES;
int lengthSize = Integer.BYTES;
assertEquals(singletonList((long) headerSize), handle.getOffsets());
assertEquals(headerSize + lengthSize + numBytes * offsetCounts.remove(handle.getInfo()), handle.getDelegate().getStateSize());
}
assertTrue(offsetCounts.isEmpty());
}
use of org.apache.flink.runtime.checkpoint.channel.ChannelStateWriter.ChannelStateWriteResult in project flink by apache.
the class ChannelStateCheckpointWriterTest method testFlush.
@Test
public void testFlush() throws Exception {
class FlushRecorder extends DataOutputStream {
private boolean flushed = false;
private FlushRecorder() {
super(new ByteArrayOutputStream());
}
@Override
public void flush() throws IOException {
flushed = true;
super.flush();
}
}
FlushRecorder dataStream = new FlushRecorder();
final ChannelStateCheckpointWriter writer = new ChannelStateCheckpointWriter("dummy task", 0, 1L, new ChannelStateWriteResult(), new ChannelStateSerializerImpl(), NO_OP_RUNNABLE, new MemoryCheckpointOutputStream(42), dataStream);
writer.completeInput();
writer.completeOutput();
assertTrue(dataStream.flushed);
}
use of org.apache.flink.runtime.checkpoint.channel.ChannelStateWriter.ChannelStateWriteResult in project flink by apache.
the class ChannelStateCheckpointWriterTest method testFileHandleSize.
@Test
public void testFileHandleSize() throws Exception {
int numChannels = 3;
int numWritesPerChannel = 4;
int numBytesPerWrite = 5;
ChannelStateWriteResult result = new ChannelStateWriteResult();
ChannelStateCheckpointWriter writer = createWriter(result, new FsCheckpointStreamFactory(getSharedInstance(), fromLocalFile(temporaryFolder.newFolder("checkpointsDir")), fromLocalFile(temporaryFolder.newFolder("sharedStateDir")), numBytesPerWrite - 1, numBytesPerWrite - 1).createCheckpointStateOutputStream(EXCLUSIVE));
InputChannelInfo[] channels = IntStream.range(0, numChannels).mapToObj(i -> new InputChannelInfo(0, i)).toArray(InputChannelInfo[]::new);
for (int call = 0; call < numWritesPerChannel; call++) {
for (int channel = 0; channel < numChannels; channel++) {
write(writer, channels[channel], getData(numBytesPerWrite));
}
}
writer.completeInput();
writer.completeOutput();
for (InputChannelStateHandle handle : result.inputChannelStateHandles.get()) {
assertEquals((Integer.BYTES + numBytesPerWrite) * numWritesPerChannel, handle.getStateSize());
}
}
Aggregations