org.apache.flink.runtime.state.memory.MemCheckpointStreamFactory.MemoryCheckpointOutputStream Java Examples

The following examples show how to use org.apache.flink.runtime.state.memory.MemCheckpointStreamFactory.MemoryCheckpointOutputStream. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MemoryCheckpointStorageTest.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Test
public void testTaskOwnedStateStream() throws Exception {
	final List<String> state = Arrays.asList("Flopsy", "Mopsy", "Cotton Tail", "Peter");

	final MemoryBackendCheckpointStorage storage = new MemoryBackendCheckpointStorage(
			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());
	}
}
 
Example #2
Source File: MemoryCheckpointOutputStreamTest.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@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
	}
}
 
Example #3
Source File: MemoryCheckpointOutputStreamTest.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@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);
	}
}
 
Example #4
Source File: MemoryCheckpointStorageTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testTaskOwnedStateStream() throws Exception {
	final List<String> state = Arrays.asList("Flopsy", "Mopsy", "Cotton Tail", "Peter");

	final MemoryBackendCheckpointStorage storage = new MemoryBackendCheckpointStorage(
			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());
	}
}
 
Example #5
Source File: MemoryCheckpointOutputStreamTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@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
	}
}
 
Example #6
Source File: MemoryCheckpointOutputStreamTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@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);
	}
}
 
Example #7
Source File: MemoryCheckpointStorageTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testTaskOwnedStateStream() throws Exception {
	final List<String> state = Arrays.asList("Flopsy", "Mopsy", "Cotton Tail", "Peter");

	final MemoryBackendCheckpointStorage storage = new MemoryBackendCheckpointStorage(
			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());
	}
}
 
Example #8
Source File: MemoryCheckpointOutputStreamTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@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
	}
}
 
Example #9
Source File: MemoryCheckpointOutputStreamTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@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);
	}
}
 
Example #10
Source File: ChannelStateCheckpointWriterTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@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());
}
 
Example #11
Source File: ChannelStateCheckpointWriterTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@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(
		1L,
		new ChannelStateWriteResult(),
		new ChannelStateSerializerImpl(),
		NO_OP_RUNNABLE,
		new MemoryCheckpointOutputStream(42),
		dataStream
	);

	writer.completeInput();
	writer.completeOutput();

	assertTrue(dataStream.flushed);
}
 
Example #12
Source File: MemoryBackendCheckpointStorage.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Override
public CheckpointStateOutputStream createTaskOwnedStateStream() throws IOException {
	return new MemoryCheckpointOutputStream(maxStateSize);
}
 
Example #13
Source File: MemoryBackendCheckpointStorage.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public CheckpointStateOutputStream createTaskOwnedStateStream() {
	return new MemoryCheckpointOutputStream(maxStateSize);
}
 
Example #14
Source File: MemoryBackendCheckpointStorage.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public CheckpointStateOutputStream createTaskOwnedStateStream() {
	return new MemoryCheckpointOutputStream(maxStateSize);
}
 
Example #15
Source File: ChannelStateCheckpointWriterTest.java    From flink with Apache License 2.0 4 votes vote down vote up
private ChannelStateCheckpointWriter createWriter(ChannelStateWriteResult result) throws Exception {
	return createWriter(result, new MemoryCheckpointOutputStream(1000));
}