Search in sources :

Example 6 with MockStreamingRuntimeContext

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);
    }
}
Also used : MockStreamingRuntimeContext(org.apache.flink.streaming.util.MockStreamingRuntimeContext) OperatorStateInputSplit(org.apache.flink.state.api.input.splits.OperatorStateInputSplit) Configuration(org.apache.flink.configuration.Configuration) ArrayList(java.util.ArrayList) OperatorState(org.apache.flink.runtime.checkpoint.OperatorState) OperatorSubtaskState(org.apache.flink.runtime.checkpoint.OperatorSubtaskState) Test(org.junit.Test)

Example 7 with MockStreamingRuntimeContext

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;
}
Also used : RichFlatMapFunction(org.apache.flink.api.common.functions.RichFlatMapFunction) VoidNamespace(org.apache.flink.runtime.state.VoidNamespace) Arrays(java.util.Arrays) OperatorState(org.apache.flink.runtime.checkpoint.OperatorState) KeyedOneInputStreamOperatorTestHarness(org.apache.flink.streaming.util.KeyedOneInputStreamOperatorTestHarness) KeyedStateReaderOperator(org.apache.flink.state.api.input.operator.KeyedStateReaderOperator) KeyedProcessFunction(org.apache.flink.streaming.api.functions.KeyedProcessFunction) KeyedStateReaderFunction(org.apache.flink.state.api.functions.KeyedStateReaderFunction) ArrayList(java.util.ArrayList) MockStreamingRuntimeContext(org.apache.flink.streaming.util.MockStreamingRuntimeContext) KeyGroupRangeInputSplit(org.apache.flink.state.api.input.splits.KeyGroupRangeInputSplit) KeyedProcessOperator(org.apache.flink.streaming.api.operators.KeyedProcessOperator) Collector(org.apache.flink.util.Collector) Nonnull(javax.annotation.Nonnull) Types(org.apache.flink.api.common.typeinfo.Types) ValueStateDescriptor(org.apache.flink.api.common.state.ValueStateDescriptor) StreamFlatMap(org.apache.flink.streaming.api.operators.StreamFlatMap) Configuration(org.apache.flink.configuration.Configuration) Set(java.util.Set) Test(org.junit.Test) IOException(java.io.IOException) OperatorSubtaskState(org.apache.flink.runtime.checkpoint.OperatorSubtaskState) MemoryStateBackend(org.apache.flink.runtime.state.memory.MemoryStateBackend) List(java.util.List) ValueState(org.apache.flink.api.common.state.ValueState) VoidSerializer(org.apache.flink.api.common.typeutils.base.VoidSerializer) OperatorID(org.apache.flink.runtime.jobgraph.OperatorID) OneInputStreamOperator(org.apache.flink.streaming.api.operators.OneInputStreamOperator) Assert(org.junit.Assert) Comparator(java.util.Comparator) OperatorIDGenerator(org.apache.flink.state.api.runtime.OperatorIDGenerator) MockStreamingRuntimeContext(org.apache.flink.streaming.util.MockStreamingRuntimeContext) Configuration(org.apache.flink.configuration.Configuration) MemoryStateBackend(org.apache.flink.runtime.state.memory.MemoryStateBackend) ArrayList(java.util.ArrayList) VoidNamespace(org.apache.flink.runtime.state.VoidNamespace) OperatorState(org.apache.flink.runtime.checkpoint.OperatorState) Nonnull(javax.annotation.Nonnull)

Example 8 with MockStreamingRuntimeContext

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);
    }
}
Also used : MockStreamingRuntimeContext(org.apache.flink.streaming.util.MockStreamingRuntimeContext) OperatorStateInputSplit(org.apache.flink.state.api.input.splits.OperatorStateInputSplit) Configuration(org.apache.flink.configuration.Configuration) ArrayList(java.util.ArrayList) OperatorState(org.apache.flink.runtime.checkpoint.OperatorState) OperatorSubtaskState(org.apache.flink.runtime.checkpoint.OperatorSubtaskState) Test(org.junit.Test)

Example 9 with MockStreamingRuntimeContext

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;
}
Also used : MockStreamingRuntimeContext(org.apache.flink.streaming.util.MockStreamingRuntimeContext) RuntimeContext(org.apache.flink.api.common.functions.RuntimeContext) MockStreamingRuntimeContext(org.apache.flink.streaming.util.MockStreamingRuntimeContext)

Example 10 with MockStreamingRuntimeContext

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);
}
Also used : AsyncLookupJoinRunner(org.apache.flink.table.runtime.operators.join.lookup.AsyncLookupJoinRunner) MockStreamingRuntimeContext(org.apache.flink.streaming.util.MockStreamingRuntimeContext) Configuration(org.apache.flink.configuration.Configuration) GeneratedFunctionWrapper(org.apache.flink.table.runtime.generated.GeneratedFunctionWrapper) Test(org.junit.Test)

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