Search in sources :

Example 16 with OperatorStateStore

use of org.apache.flink.api.common.state.OperatorStateStore in project flink by apache.

the class SourceOperatorTestContext method createStateContext.

public StateInitializationContext createStateContext() throws Exception {
    // Create a mock split.
    byte[] serializedSplitWithVersion = SimpleVersionedSerialization.writeVersionAndSerialize(new MockSourceSplitSerializer(), MOCK_SPLIT);
    // Crate the state context.
    OperatorStateStore operatorStateStore = createOperatorStateStore();
    StateInitializationContext stateContext = new StateInitializationContextImpl(null, operatorStateStore, null, null, null);
    // Update the context.
    stateContext.getOperatorStateStore().getListState(SourceOperator.SPLITS_STATE_DESC).update(Collections.singletonList(serializedSplitWithVersion));
    return stateContext;
}
Also used : OperatorStateStore(org.apache.flink.api.common.state.OperatorStateStore) StateInitializationContext(org.apache.flink.runtime.state.StateInitializationContext) StateInitializationContextImpl(org.apache.flink.runtime.state.StateInitializationContextImpl) MockSourceSplitSerializer(org.apache.flink.api.connector.source.mocks.MockSourceSplitSerializer)

Example 17 with OperatorStateStore

use of org.apache.flink.api.common.state.OperatorStateStore in project beam by apache.

the class ImpulseSourceFunctionTest method getInitializationContext.

private static <T> FunctionInitializationContext getInitializationContext(ListState<T> listState) throws Exception {
    FunctionInitializationContext mock = Mockito.mock(FunctionInitializationContext.class);
    OperatorStateStore mockOperatorState = getMockOperatorState(listState);
    when(mock.getOperatorStateStore()).thenReturn(mockOperatorState);
    return mock;
}
Also used : OperatorStateStore(org.apache.flink.api.common.state.OperatorStateStore) FunctionInitializationContext(org.apache.flink.runtime.state.FunctionInitializationContext)

Aggregations

OperatorStateStore (org.apache.flink.api.common.state.OperatorStateStore)17 ListStateDescriptor (org.apache.flink.api.common.state.ListStateDescriptor)10 StateInitializationContext (org.apache.flink.runtime.state.StateInitializationContext)10 ArrayList (java.util.ArrayList)8 Configuration (org.apache.flink.configuration.Configuration)8 Test (org.junit.Test)8 Properties (java.util.Properties)6 Tuple2 (org.apache.flink.api.java.tuple.Tuple2)6 SentinelSequenceNumber (org.apache.flink.streaming.connectors.kinesis.model.SentinelSequenceNumber)6 SequenceNumber (org.apache.flink.streaming.connectors.kinesis.model.SequenceNumber)6 StreamShardHandle (org.apache.flink.streaming.connectors.kinesis.model.StreamShardHandle)6 TestableFlinkKinesisConsumer (org.apache.flink.streaming.connectors.kinesis.testutils.TestableFlinkKinesisConsumer)6 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)6 HashMap (java.util.HashMap)5 KinesisDataFetcher (org.apache.flink.streaming.connectors.kinesis.internals.KinesisDataFetcher)5 Map (java.util.Map)4 KinesisStreamShardState (org.apache.flink.streaming.connectors.kinesis.model.KinesisStreamShardState)4 CollectingSourceContext (org.apache.flink.streaming.util.CollectingSourceContext)4 Shard (com.amazonaws.services.kinesis.model.Shard)3 KinesisStreamShard (org.apache.flink.streaming.connectors.kinesis.model.KinesisStreamShard)3