use of org.apache.flink.streaming.util.MockStreamingRuntimeContext in project flink by apache.
the class ListStateInputFormatTest method testReadListOperatorState.
@Test
public void testReadListOperatorState() throws Exception {
try (OneInputStreamOperatorTestHarness<Integer, Void> testHarness = getTestHarness()) {
testHarness.open();
testHarness.processElement(1, 0);
testHarness.processElement(2, 0);
testHarness.processElement(3, 0);
OperatorSubtaskState subtaskState = testHarness.snapshot(0, 0);
OperatorState state = new OperatorState(OperatorIDGenerator.fromUid("uid"), 1, 4);
state.putState(0, subtaskState);
OperatorStateInputSplit split = new OperatorStateInputSplit(subtaskState.getManagedOperatorState(), 0);
ListStateInputFormat<Integer> format = new ListStateInputFormat<>(state, new Configuration(), null, descriptor);
format.setRuntimeContext(new MockStreamingRuntimeContext(false, 1, 0));
format.open(split);
List<Integer> results = new ArrayList<>();
while (!format.reachedEnd()) {
results.add(format.nextRecord(0));
}
results.sort(Comparator.naturalOrder());
Assert.assertEquals("Failed to read correct list state from state backend", Arrays.asList(1, 2, 3), results);
}
}
use of org.apache.flink.streaming.util.MockStreamingRuntimeContext in project flink by apache.
the class KeyedStateInputFormatTest method readInputSplit.
@Nonnull
private List<Integer> readInputSplit(KeyGroupRangeInputSplit split, KeyedStateReaderFunction<Integer, Integer> userFunction) throws IOException {
KeyedStateInputFormat<Integer, VoidNamespace, Integer> format = new KeyedStateInputFormat<>(new OperatorState(OperatorIDGenerator.fromUid("uid"), 1, 4), new MemoryStateBackend(), new Configuration(), new KeyedStateReaderOperator<>(userFunction, Types.INT));
List<Integer> data = new ArrayList<>();
format.setRuntimeContext(new MockStreamingRuntimeContext(false, 1, 0));
format.openInputFormat();
format.open(split);
while (!format.reachedEnd()) {
data.add(format.nextRecord(0));
}
format.close();
format.closeInputFormat();
data.sort(Comparator.comparingInt(id -> id));
return data;
}
use of org.apache.flink.streaming.util.MockStreamingRuntimeContext in project flink by apache.
the class UnionStateInputFormatTest method testReadUnionOperatorState.
@Test
public void testReadUnionOperatorState() throws Exception {
try (OneInputStreamOperatorTestHarness<Integer, Void> testHarness = getTestHarness()) {
testHarness.open();
testHarness.processElement(1, 0);
testHarness.processElement(2, 0);
testHarness.processElement(3, 0);
OperatorSubtaskState subtaskState = testHarness.snapshot(0, 0);
OperatorState state = new OperatorState(OperatorIDGenerator.fromUid("uid"), 1, 4);
state.putState(0, subtaskState);
OperatorStateInputSplit split = new OperatorStateInputSplit(subtaskState.getManagedOperatorState(), 0);
UnionStateInputFormat<Integer> format = new UnionStateInputFormat<>(state, new Configuration(), null, descriptor);
format.setRuntimeContext(new MockStreamingRuntimeContext(false, 1, 0));
format.open(split);
List<Integer> results = new ArrayList<>();
while (!format.reachedEnd()) {
results.add(format.nextRecord(0));
}
results.sort(Comparator.naturalOrder());
Assert.assertEquals("Failed to read correct list state from state backend", Arrays.asList(1, 2, 3), results);
}
}
use of org.apache.flink.streaming.util.MockStreamingRuntimeContext in project flink by apache.
the class SavepointOutputFormatTest method createSavepointOutputFormat.
private SavepointOutputFormat createSavepointOutputFormat(Path path) throws Exception {
RuntimeContext ctx = new MockStreamingRuntimeContext(false, 1, 0);
SavepointOutputFormat format = new SavepointOutputFormat(path);
format.setRuntimeContext(ctx);
return format;
}
use of org.apache.flink.streaming.util.MockStreamingRuntimeContext in project flink by apache.
the class AsyncLookupJoinHarnessTest method testCloseAsyncLookupJoinRunner.
@Test
public void testCloseAsyncLookupJoinRunner() throws Exception {
final AsyncLookupJoinRunner joinRunner = new AsyncLookupJoinRunner(new GeneratedFunctionWrapper(new TestingFetcherFunction()), fetcherConverter, new GeneratedResultFutureWrapper<>(new TestingFetcherResultFuture()), rightRowSerializer, true, 100);
assertNull(joinRunner.getAllResultFutures());
closeAsyncLookupJoinRunner(joinRunner);
joinRunner.setRuntimeContext(new MockStreamingRuntimeContext(false, 1, 0));
joinRunner.open(new Configuration());
assertNotNull(joinRunner.getAllResultFutures());
closeAsyncLookupJoinRunner(joinRunner);
joinRunner.open(new Configuration());
joinRunner.asyncInvoke(row(1, "a"), new TestingFetcherResultFuture());
assertNotNull(joinRunner.getAllResultFutures());
closeAsyncLookupJoinRunner(joinRunner);
}
Aggregations