use of org.apache.flink.runtime.checkpoint.OperatorState in project flink by apache.
the class WindowReaderTest method testReducingWindow.
@Test
public void testReducingWindow() throws Exception {
WindowOperator<Integer, Integer, ?, Void, ?> operator = getWindowOperator(stream -> stream.window(TumblingEventTimeWindows.of(Time.milliseconds(1))).reduce(new ReduceSum()));
OperatorState operatorState = getOperatorState(operator);
KeyedStateInputFormat<Integer, TimeWindow, Integer> format = new KeyedStateInputFormat<>(operatorState, new MemoryStateBackend(), new Configuration(), WindowReaderOperator.reduce(new ReduceSum(), new PassThroughReader<>(), Types.INT, new TimeWindow.Serializer(), Types.INT));
List<Integer> list = readState(format);
Assert.assertEquals(Arrays.asList(1, 1), list);
}
use of org.apache.flink.runtime.checkpoint.OperatorState in project flink by apache.
the class WindowReaderTest method testProcessReader.
@Test
public void testProcessReader() throws Exception {
WindowOperator<Integer, Integer, ?, Void, ?> operator = getWindowOperator(stream -> stream.window(TumblingEventTimeWindows.of(Time.milliseconds(1))).process(mockProcessWindowFunction(), Types.INT));
OperatorState operatorState = getOperatorState(operator);
KeyedStateInputFormat<Integer, TimeWindow, Integer> format = new KeyedStateInputFormat<>(operatorState, new MemoryStateBackend(), new Configuration(), WindowReaderOperator.process(new PassThroughReader<>(), Types.INT, new TimeWindow.Serializer(), Types.INT));
List<Integer> list = readState(format);
Assert.assertEquals(Arrays.asList(1, 1), list);
}
use of org.apache.flink.runtime.checkpoint.OperatorState in project flink by apache.
the class OperatorCoordinatorSchedulerTest method createOperatorState.
private static OperatorState createOperatorState(OperatorID id, byte[] coordinatorState) {
final OperatorState state = new OperatorState(id, 10, 16384);
state.setCoordinatorState(new ByteStreamStateHandle("name", coordinatorState));
return state;
}
use of org.apache.flink.runtime.checkpoint.OperatorState in project flink by apache.
the class OperatorCoordinatorSchedulerTest method serializeAsCheckpointMetadata.
private static byte[] serializeAsCheckpointMetadata(OperatorID id, byte[] coordinatorState) throws IOException {
final OperatorState state = createOperatorState(id, coordinatorState);
final CheckpointMetadata metadata = new CheckpointMetadata(1337L, Collections.singletonList(state), Collections.emptyList());
final ByteArrayOutputStream out = new ByteArrayOutputStream();
Checkpoints.storeCheckpointMetadata(metadata, out);
return out.toByteArray();
}
use of org.apache.flink.runtime.checkpoint.OperatorState in project flink by apache.
the class KeyedStateInputFormatTest method testMaxParallelismRespected.
@Test
public void testMaxParallelismRespected() throws Exception {
OperatorID operatorID = OperatorIDGenerator.fromUid("uid");
OperatorSubtaskState state = createOperatorSubtaskState(new StreamFlatMap<>(new StatefulFunction()));
OperatorState operatorState = new OperatorState(operatorID, 1, 128);
operatorState.putState(0, state);
KeyedStateInputFormat<?, ?, ?> format = new KeyedStateInputFormat<>(operatorState, new MemoryStateBackend(), new Configuration(), new KeyedStateReaderOperator<>(new ReaderFunction(), Types.INT));
KeyGroupRangeInputSplit[] splits = format.createInputSplits(129);
Assert.assertEquals("Failed to properly partition operator state into input splits", 128, splits.length);
}
Aggregations