use of org.apache.flink.state.api.input.splits.KeyGroupRangeInputSplit in project flink by apache.
the class KeyedStateInputFormatTest method testReadMultipleOutputPerKey.
@Test
public void testReadMultipleOutputPerKey() 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 split = format.createInputSplits(1)[0];
KeyedStateReaderFunction<Integer, Integer> userFunction = new DoubleReaderFunction();
List<Integer> data = readInputSplit(split, userFunction);
Assert.assertEquals("Incorrect data read from input split", Arrays.asList(1, 1, 2, 2, 3, 3), data);
}
use of org.apache.flink.state.api.input.splits.KeyGroupRangeInputSplit in project flink by apache.
the class WindowReaderTest method readState.
@Nonnull
private <OUT> List<OUT> readState(KeyedStateInputFormat<Integer, TimeWindow, OUT> format) throws IOException {
KeyGroupRangeInputSplit split = format.createInputSplits(1)[0];
List<OUT> data = new ArrayList<>();
format.setRuntimeContext(new MockStreamingRuntimeContext(false, 1, 0));
format.openInputFormat();
format.open(split);
while (!format.reachedEnd()) {
data.add(format.nextRecord(null));
}
format.close();
format.closeInputFormat();
return data;
}
use of org.apache.flink.state.api.input.splits.KeyGroupRangeInputSplit in project flink by apache.
the class KeyedStateInputFormatTest method testCreatePartitionedInputSplits.
@Test
public void testCreatePartitionedInputSplits() 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(4);
Assert.assertEquals("Failed to properly partition operator state into input splits", 4, splits.length);
}
Aggregations