Search in sources :

Example 1 with MemoryCheckpointOutputStream

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
    }
}
Also used : HashMap(java.util.HashMap) MemoryCheckpointOutputStream(org.apache.flink.runtime.state.memory.MemCheckpointStreamFactory.MemoryCheckpointOutputStream) CheckpointStateOutputStream(org.apache.flink.runtime.state.CheckpointStateOutputStream) IOException(java.io.IOException) ObjectOutputStream(java.io.ObjectOutputStream) Test(org.junit.Test)

Example 2 with MemoryCheckpointOutputStream

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());
}
Also used : MemoryCheckpointOutputStream(org.apache.flink.runtime.state.memory.MemCheckpointStreamFactory.MemoryCheckpointOutputStream) ChannelStateWriteResult(org.apache.flink.runtime.checkpoint.channel.ChannelStateWriter.ChannelStateWriteResult) Test(org.junit.Test)

Example 3 with MemoryCheckpointOutputStream

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);
}
Also used : DataOutputStream(java.io.DataOutputStream) MemoryCheckpointOutputStream(org.apache.flink.runtime.state.memory.MemCheckpointStreamFactory.MemoryCheckpointOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ChannelStateWriteResult(org.apache.flink.runtime.checkpoint.channel.ChannelStateWriter.ChannelStateWriteResult) Test(org.junit.Test)

Example 4 with MemoryCheckpointOutputStream

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);
    }
}
Also used : StreamStateHandle(org.apache.flink.runtime.state.StreamStateHandle) HashMap(java.util.HashMap) MemoryCheckpointOutputStream(org.apache.flink.runtime.state.memory.MemCheckpointStreamFactory.MemoryCheckpointOutputStream) CheckpointStateOutputStream(org.apache.flink.runtime.state.CheckpointStateOutputStream) ObjectOutputStream(java.io.ObjectOutputStream) ObjectInputStream(java.io.ObjectInputStream) Test(org.junit.Test)

Example 5 with MemoryCheckpointOutputStream

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());
    }
}
Also used : StreamStateHandle(org.apache.flink.runtime.state.StreamStateHandle) MemoryCheckpointOutputStream(org.apache.flink.runtime.state.memory.MemCheckpointStreamFactory.MemoryCheckpointOutputStream) CheckpointStateOutputStream(org.apache.flink.runtime.state.CheckpointStateOutputStream) ObjectOutputStream(java.io.ObjectOutputStream) JobID(org.apache.flink.api.common.JobID) ObjectInputStream(java.io.ObjectInputStream) Test(org.junit.Test)

Aggregations

MemoryCheckpointOutputStream (org.apache.flink.runtime.state.memory.MemCheckpointStreamFactory.MemoryCheckpointOutputStream)5 Test (org.junit.Test)5 ObjectOutputStream (java.io.ObjectOutputStream)3 CheckpointStateOutputStream (org.apache.flink.runtime.state.CheckpointStateOutputStream)3 ObjectInputStream (java.io.ObjectInputStream)2 HashMap (java.util.HashMap)2 ChannelStateWriteResult (org.apache.flink.runtime.checkpoint.channel.ChannelStateWriter.ChannelStateWriteResult)2 StreamStateHandle (org.apache.flink.runtime.state.StreamStateHandle)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 DataOutputStream (java.io.DataOutputStream)1 IOException (java.io.IOException)1 JobID (org.apache.flink.api.common.JobID)1