use of org.apache.flink.streaming.util.MockStreamingRuntimeContext in project flink by apache.
the class PrintSinkFunctionTest method testPrintSinkStdOut.
@Test
public void testPrintSinkStdOut() throws Exception {
PrintSinkFunction<String> printSink = new PrintSinkFunction<>();
printSink.setRuntimeContext(new MockStreamingRuntimeContext(false, 1, 0));
printSink.open(new Configuration());
printSink.invoke("hello world!", SinkContextUtil.forTimestamp(0));
assertEquals("Print to System.out", printSink.toString());
assertEquals("hello world!" + line, arrayOutputStream.toString());
printSink.close();
}
use of org.apache.flink.streaming.util.MockStreamingRuntimeContext in project flink by apache.
the class PrintSinkFunctionTest method testPrintSinkWithPrefix.
@Test
public void testPrintSinkWithPrefix() throws Exception {
PrintSinkFunction<String> printSink = new PrintSinkFunction<>();
printSink.setRuntimeContext(new MockStreamingRuntimeContext(false, 2, 1));
printSink.open(new Configuration());
printSink.invoke("hello world!", SinkContextUtil.forTimestamp(0));
assertEquals("Print to System.out", printSink.toString());
assertEquals("2> hello world!" + line, arrayOutputStream.toString());
printSink.close();
}
use of org.apache.flink.streaming.util.MockStreamingRuntimeContext in project flink by apache.
the class PrintSinkFunctionTest method testPrintSinkStdErr.
@Test
public void testPrintSinkStdErr() throws Exception {
PrintSinkFunction<String> printSink = new PrintSinkFunction<>(true);
printSink.setRuntimeContext(new MockStreamingRuntimeContext(false, 1, 0));
printSink.open(new Configuration());
printSink.invoke("hello world!", SinkContextUtil.forTimestamp(0));
assertEquals("Print to System.err", printSink.toString());
assertEquals("hello world!" + line, arrayErrorStream.toString());
printSink.close();
}
use of org.apache.flink.streaming.util.MockStreamingRuntimeContext in project flink by apache.
the class StreamOperatorContextBuilderTest method testStateBackendLoading.
@Test(expected = CustomStateBackendFactory.ExpectedException.class)
public void testStateBackendLoading() throws Exception {
Configuration configuration = new Configuration();
configuration.set(StateBackendOptions.STATE_BACKEND, CustomStateBackendFactory.class.getCanonicalName());
StreamOperatorContextBuilder builder = new StreamOperatorContextBuilder(new MockStreamingRuntimeContext(true, 1, 0), configuration, new OperatorState(new OperatorID(), 1, 128), new PrioritizedOperatorSubtaskStateInputSplit() {
@Override
public PrioritizedOperatorSubtaskState getPrioritizedOperatorSubtaskState() {
return PrioritizedOperatorSubtaskState.emptyNotRestored();
}
@Override
public int getSplitNumber() {
return 0;
}
}, new CloseableRegistry(), null);
builder.build(LOG);
}
use of org.apache.flink.streaming.util.MockStreamingRuntimeContext 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;
}
Aggregations