use of org.apache.flink.runtime.state.memory.MemCheckpointStreamFactory.MemoryCheckpointOutputStream in project flink by apache.
the class MemoryCheckpointOutputStreamTest method testOversizedState.
@Test
public void testOversizedState() throws Exception {
HashMap<String, Integer> state = new HashMap<>();
state.put("hey there", 2);
state.put("the crazy brown fox stumbles over a sentence that does not contain every letter", 77);
CheckpointStateOutputStream outStream = new MemoryCheckpointOutputStream(10);
ObjectOutputStream oos = new ObjectOutputStream(outStream);
oos.writeObject(state);
oos.flush();
try {
outStream.closeAndGetHandle();
fail("this should cause an exception");
} catch (IOException e) {
// that's what we expect
}
}
use of org.apache.flink.runtime.state.memory.MemCheckpointStreamFactory.MemoryCheckpointOutputStream 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.state.memory.MemCheckpointStreamFactory.MemoryCheckpointOutputStream 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.state.memory.MemCheckpointStreamFactory.MemoryCheckpointOutputStream in project flink by apache.
the class MemoryCheckpointOutputStreamTest method testStateStream.
@Test
public void testStateStream() throws Exception {
HashMap<String, Integer> state = new HashMap<>();
state.put("hey there", 2);
state.put("the crazy brown fox stumbles over a sentence that does not contain every letter", 77);
CheckpointStateOutputStream outStream = new MemoryCheckpointOutputStream(MemoryStateBackend.DEFAULT_MAX_STATE_SIZE);
ObjectOutputStream oos = new ObjectOutputStream(outStream);
oos.writeObject(state);
oos.flush();
StreamStateHandle handle = outStream.closeAndGetHandle();
assertNotNull(handle);
try (ObjectInputStream ois = new ObjectInputStream(handle.openInputStream())) {
assertEquals(state, ois.readObject());
assertTrue(ois.available() <= 0);
}
}
use of org.apache.flink.runtime.state.memory.MemCheckpointStreamFactory.MemoryCheckpointOutputStream in project flink by apache.
the class MemoryCheckpointStorageAccessTest method testTaskOwnedStateStream.
@Test
public void testTaskOwnedStateStream() throws Exception {
final List<String> state = Arrays.asList("Flopsy", "Mopsy", "Cotton Tail", "Peter");
final MemoryBackendCheckpointStorageAccess storage = new MemoryBackendCheckpointStorageAccess(new JobID(), null, null, DEFAULT_MAX_STATE_SIZE);
StreamStateHandle stateHandle;
try (CheckpointStateOutputStream stream = storage.createTaskOwnedStateStream()) {
assertTrue(stream instanceof MemoryCheckpointOutputStream);
new ObjectOutputStream(stream).writeObject(state);
stateHandle = stream.closeAndGetHandle();
}
try (ObjectInputStream in = new ObjectInputStream(stateHandle.openInputStream())) {
assertEquals(state, in.readObject());
}
}
Aggregations