Search in sources :

Example 11 with MockStreamingRuntimeContext

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();
}
Also used : MockStreamingRuntimeContext(org.apache.flink.streaming.util.MockStreamingRuntimeContext) Configuration(org.apache.flink.configuration.Configuration) PrintSinkFunction(org.apache.flink.streaming.api.functions.sink.PrintSinkFunction) Test(org.junit.Test)

Example 12 with MockStreamingRuntimeContext

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();
}
Also used : MockStreamingRuntimeContext(org.apache.flink.streaming.util.MockStreamingRuntimeContext) Configuration(org.apache.flink.configuration.Configuration) PrintSinkFunction(org.apache.flink.streaming.api.functions.sink.PrintSinkFunction) Test(org.junit.Test)

Example 13 with MockStreamingRuntimeContext

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();
}
Also used : MockStreamingRuntimeContext(org.apache.flink.streaming.util.MockStreamingRuntimeContext) Configuration(org.apache.flink.configuration.Configuration) PrintSinkFunction(org.apache.flink.streaming.api.functions.sink.PrintSinkFunction) Test(org.junit.Test)

Example 14 with MockStreamingRuntimeContext

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);
}
Also used : MockStreamingRuntimeContext(org.apache.flink.streaming.util.MockStreamingRuntimeContext) Configuration(org.apache.flink.configuration.Configuration) PrioritizedOperatorSubtaskState(org.apache.flink.runtime.checkpoint.PrioritizedOperatorSubtaskState) CustomStateBackendFactory(org.apache.flink.state.api.utils.CustomStateBackendFactory) PrioritizedOperatorSubtaskStateInputSplit(org.apache.flink.state.api.input.splits.PrioritizedOperatorSubtaskStateInputSplit) OperatorID(org.apache.flink.runtime.jobgraph.OperatorID) CloseableRegistry(org.apache.flink.core.fs.CloseableRegistry) OperatorState(org.apache.flink.runtime.checkpoint.OperatorState) Test(org.junit.Test)

Example 15 with MockStreamingRuntimeContext

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;
}
Also used : KeyGroupRangeInputSplit(org.apache.flink.state.api.input.splits.KeyGroupRangeInputSplit) MockStreamingRuntimeContext(org.apache.flink.streaming.util.MockStreamingRuntimeContext) ArrayList(java.util.ArrayList) Nonnull(javax.annotation.Nonnull)

Aggregations

MockStreamingRuntimeContext (org.apache.flink.streaming.util.MockStreamingRuntimeContext)22 Configuration (org.apache.flink.configuration.Configuration)19 Test (org.junit.Test)15 OperatorState (org.apache.flink.runtime.checkpoint.OperatorState)5 PrintSinkFunction (org.apache.flink.streaming.api.functions.sink.PrintSinkFunction)5 ArrayList (java.util.ArrayList)4 OperatorSubtaskState (org.apache.flink.runtime.checkpoint.OperatorSubtaskState)4 HashMap (java.util.HashMap)3 OperatorStateInputSplit (org.apache.flink.state.api.input.splits.OperatorStateInputSplit)3 Nonnull (javax.annotation.Nonnull)2 GenericJdbcSinkFunction (org.apache.flink.connector.jdbc.internal.GenericJdbcSinkFunction)2 OperatorID (org.apache.flink.runtime.jobgraph.OperatorID)2 StateSnapshotContextSynchronousImpl (org.apache.flink.runtime.state.StateSnapshotContextSynchronousImpl)2 KeyGroupRangeInputSplit (org.apache.flink.state.api.input.splits.KeyGroupRangeInputSplit)2 ResolvedSchema (org.apache.flink.table.catalog.ResolvedSchema)2 DynamicTableSink (org.apache.flink.table.connector.sink.DynamicTableSink)2 SinkFunctionProvider (org.apache.flink.table.connector.sink.SinkFunctionProvider)2 Channel (com.rabbitmq.client.Channel)1 Connection (com.rabbitmq.client.Connection)1 IOException (java.io.IOException)1