Search in sources :

Example 16 with MockStreamingRuntimeContext

use of org.apache.flink.streaming.util.MockStreamingRuntimeContext in project flink by apache.

the class RMQSinkTest method createRMQSinkWithOptionsAndReturnHandler.

private RMQSink<String> createRMQSinkWithOptionsAndReturnHandler(boolean mandatory, boolean immediate) throws Exception {
    publishOptions = new DummyPublishOptions(mandatory, immediate);
    returnListener = new DummyReturnHandler();
    RMQSink<String> rmqSink = new RMQSink<>(rmqConnectionConfig, serializationSchema, publishOptions, returnListener);
    rmqSink.setRuntimeContext(new MockStreamingRuntimeContext(false, 1, 0));
    rmqSink.open(new Configuration());
    return rmqSink;
}
Also used : MockStreamingRuntimeContext(org.apache.flink.streaming.util.MockStreamingRuntimeContext) Configuration(org.apache.flink.configuration.Configuration)

Example 17 with MockStreamingRuntimeContext

use of org.apache.flink.streaming.util.MockStreamingRuntimeContext in project flink by apache.

the class RMQSinkTest method createRMQSinkWithOptions.

private RMQSink<String> createRMQSinkWithOptions(boolean mandatory, boolean immediate) throws Exception {
    publishOptions = new DummyPublishOptions(mandatory, immediate);
    RMQSink<String> rmqSink = new RMQSink<>(rmqConnectionConfig, serializationSchema, publishOptions);
    rmqSink.setRuntimeContext(new MockStreamingRuntimeContext(false, 1, 0));
    rmqSink.open(new Configuration());
    return rmqSink;
}
Also used : MockStreamingRuntimeContext(org.apache.flink.streaming.util.MockStreamingRuntimeContext) Configuration(org.apache.flink.configuration.Configuration)

Example 18 with MockStreamingRuntimeContext

use of org.apache.flink.streaming.util.MockStreamingRuntimeContext in project flink by apache.

the class PubSubConsumingTest method createSourceThread.

private Thread createSourceThread(PubSubSource<String> pubSubSource, Object lock, ConcurrentLinkedQueue<String> results) {
    return new Thread(() -> {
        try {
            pubSubSource.setRuntimeContext(new MockStreamingRuntimeContext(true, 1, 0));
            pubSubSource.open(new Configuration());
            pubSubSource.run(new CollectingSourceContext<>(lock, results));
        } catch (InterruptedException e) {
        // expected on cancel
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    });
}
Also used : MockStreamingRuntimeContext(org.apache.flink.streaming.util.MockStreamingRuntimeContext) Configuration(org.apache.flink.configuration.Configuration)

Example 19 with MockStreamingRuntimeContext

use of org.apache.flink.streaming.util.MockStreamingRuntimeContext in project flink by apache.

the class OracleTableSinkITCase method testFlushBufferWhenCheckpoint.

@Test
public void testFlushBufferWhenCheckpoint() throws Exception {
    Map<String, String> options = new HashMap<>();
    options.put("connector", "jdbc");
    options.put("url", containerUrl);
    options.put("table-name", OUTPUT_TABLE5);
    options.put("sink.buffer-flush.interval", "0");
    ResolvedSchema schema = ResolvedSchema.of(Column.physical("id", DataTypes.BIGINT().notNull()));
    DynamicTableSink tableSink = createTableSink(schema, options);
    SinkRuntimeProviderContext context = new SinkRuntimeProviderContext(false);
    SinkFunctionProvider sinkProvider = (SinkFunctionProvider) tableSink.getSinkRuntimeProvider(context);
    GenericJdbcSinkFunction<RowData> sinkFunction = (GenericJdbcSinkFunction<RowData>) sinkProvider.createSinkFunction();
    sinkFunction.setRuntimeContext(new MockStreamingRuntimeContext(true, 1, 0));
    sinkFunction.open(new Configuration());
    sinkFunction.invoke(GenericRowData.of(1L), SinkContextUtil.forTimestamp(1));
    sinkFunction.invoke(GenericRowData.of(2L), SinkContextUtil.forTimestamp(1));
    check(new Row[] {}, containerUrl, OUTPUT_TABLE5, new String[] { "id" });
    sinkFunction.snapshotState(new StateSnapshotContextSynchronousImpl(1, 1));
    check(new Row[] { Row.of(1L), Row.of(2L) }, containerUrl, OUTPUT_TABLE5, new String[] { "id" });
    sinkFunction.close();
}
Also used : SinkRuntimeProviderContext(org.apache.flink.table.runtime.connector.sink.SinkRuntimeProviderContext) MockStreamingRuntimeContext(org.apache.flink.streaming.util.MockStreamingRuntimeContext) Configuration(org.apache.flink.configuration.Configuration) HashMap(java.util.HashMap) StateSnapshotContextSynchronousImpl(org.apache.flink.runtime.state.StateSnapshotContextSynchronousImpl) DynamicTableSink(org.apache.flink.table.connector.sink.DynamicTableSink) SinkFunctionProvider(org.apache.flink.table.connector.sink.SinkFunctionProvider) GenericRowData(org.apache.flink.table.data.GenericRowData) RowData(org.apache.flink.table.data.RowData) GenericJdbcSinkFunction(org.apache.flink.connector.jdbc.internal.GenericJdbcSinkFunction) ResolvedSchema(org.apache.flink.table.catalog.ResolvedSchema) Test(org.junit.Test)

Example 20 with MockStreamingRuntimeContext

use of org.apache.flink.streaming.util.MockStreamingRuntimeContext in project flink by apache.

the class FlinkKafkaConsumerBaseTest method setupConsumer.

@SuppressWarnings("unchecked")
private static <T, S> void setupConsumer(FlinkKafkaConsumerBase<T> consumer, boolean isRestored, ListState<S> restoredListState, boolean isCheckpointingEnabled, int subtaskIndex, int totalNumSubtasks) throws Exception {
    // run setup procedure in operator life cycle
    consumer.setRuntimeContext(new MockStreamingRuntimeContext(isCheckpointingEnabled, totalNumSubtasks, subtaskIndex));
    consumer.initializeState(new MockFunctionInitializationContext(isRestored, new MockOperatorStateStore(restoredListState)));
    consumer.open(new Configuration());
}
Also used : MockStreamingRuntimeContext(org.apache.flink.streaming.util.MockStreamingRuntimeContext) Configuration(org.apache.flink.configuration.Configuration)

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