Search in sources :

Example 1 with AbstractKeyedStateBackend

use of org.apache.flink.runtime.state.AbstractKeyedStateBackend in project flink by apache.

the class StreamingRuntimeContextTest method createListPlainMockOp.

@SuppressWarnings("unchecked")
private static AbstractStreamOperator<?> createListPlainMockOp() throws Exception {
    AbstractStreamOperator<?> operatorMock = mock(AbstractStreamOperator.class);
    ExecutionConfig config = new ExecutionConfig();
    KeyedStateBackend keyedStateBackend = mock(KeyedStateBackend.class);
    DefaultKeyedStateStore keyedStateStore = new DefaultKeyedStateStore(keyedStateBackend, config);
    when(operatorMock.getExecutionConfig()).thenReturn(config);
    doAnswer(new Answer<ListState<String>>() {

        @Override
        public ListState<String> answer(InvocationOnMock invocationOnMock) throws Throwable {
            ListStateDescriptor<String> descr = (ListStateDescriptor<String>) invocationOnMock.getArguments()[2];
            AbstractKeyedStateBackend<Integer> backend = new MemoryStateBackend().createKeyedStateBackend(new DummyEnvironment("test_task", 1, 0), new JobID(), "test_op", IntSerializer.INSTANCE, 1, new KeyGroupRange(0, 0), new KvStateRegistry().createTaskRegistry(new JobID(), new JobVertexID()));
            backend.setCurrentKey(0);
            return backend.getPartitionedState(VoidNamespace.INSTANCE, VoidNamespaceSerializer.INSTANCE, descr);
        }
    }).when(keyedStateBackend).getPartitionedState(Matchers.any(), any(TypeSerializer.class), any(ListStateDescriptor.class));
    when(operatorMock.getKeyedStateStore()).thenReturn(keyedStateStore);
    return operatorMock;
}
Also used : KeyedStateBackend(org.apache.flink.runtime.state.KeyedStateBackend) AbstractKeyedStateBackend(org.apache.flink.runtime.state.AbstractKeyedStateBackend) ListState(org.apache.flink.api.common.state.ListState) KvStateRegistry(org.apache.flink.runtime.query.KvStateRegistry) MemoryStateBackend(org.apache.flink.runtime.state.memory.MemoryStateBackend) JobVertexID(org.apache.flink.runtime.jobgraph.JobVertexID) ListStateDescriptor(org.apache.flink.api.common.state.ListStateDescriptor) KeyGroupRange(org.apache.flink.runtime.state.KeyGroupRange) DummyEnvironment(org.apache.flink.runtime.operators.testutils.DummyEnvironment) ExecutionConfig(org.apache.flink.api.common.ExecutionConfig) AbstractKeyedStateBackend(org.apache.flink.runtime.state.AbstractKeyedStateBackend) InvocationOnMock(org.mockito.invocation.InvocationOnMock) TypeSerializer(org.apache.flink.api.common.typeutils.TypeSerializer) JobID(org.apache.flink.api.common.JobID) DefaultKeyedStateStore(org.apache.flink.runtime.state.DefaultKeyedStateStore)

Example 2 with AbstractKeyedStateBackend

use of org.apache.flink.runtime.state.AbstractKeyedStateBackend in project flink by apache.

the class AbstractStreamOperator method setCurrentKey.

@SuppressWarnings({ "unchecked", "rawtypes" })
public void setCurrentKey(Object key) {
    if (keyedStateBackend != null) {
        try {
            // need to work around type restrictions
            @SuppressWarnings("unchecked,rawtypes") AbstractKeyedStateBackend rawBackend = (AbstractKeyedStateBackend) keyedStateBackend;
            rawBackend.setCurrentKey(key);
        } catch (Exception e) {
            throw new RuntimeException("Exception occurred while setting the current key context.", e);
        }
    }
}
Also used : AbstractKeyedStateBackend(org.apache.flink.runtime.state.AbstractKeyedStateBackend) ConcurrentModificationException(java.util.ConcurrentModificationException) IOException(java.io.IOException)

Example 3 with AbstractKeyedStateBackend

use of org.apache.flink.runtime.state.AbstractKeyedStateBackend in project flink by apache.

the class StreamingRuntimeContextTest method createMapPlainMockOp.

@SuppressWarnings("unchecked")
private static AbstractStreamOperator<?> createMapPlainMockOp() throws Exception {
    AbstractStreamOperator<?> operatorMock = mock(AbstractStreamOperator.class);
    ExecutionConfig config = new ExecutionConfig();
    KeyedStateBackend keyedStateBackend = mock(KeyedStateBackend.class);
    DefaultKeyedStateStore keyedStateStore = new DefaultKeyedStateStore(keyedStateBackend, config);
    when(operatorMock.getExecutionConfig()).thenReturn(config);
    doAnswer(new Answer<MapState<Integer, String>>() {

        @Override
        public MapState<Integer, String> answer(InvocationOnMock invocationOnMock) throws Throwable {
            MapStateDescriptor<Integer, String> descr = (MapStateDescriptor<Integer, String>) invocationOnMock.getArguments()[2];
            AbstractKeyedStateBackend<Integer> backend = new MemoryStateBackend().createKeyedStateBackend(new DummyEnvironment("test_task", 1, 0), new JobID(), "test_op", IntSerializer.INSTANCE, 1, new KeyGroupRange(0, 0), new KvStateRegistry().createTaskRegistry(new JobID(), new JobVertexID()));
            backend.setCurrentKey(0);
            return backend.getPartitionedState(VoidNamespace.INSTANCE, VoidNamespaceSerializer.INSTANCE, descr);
        }
    }).when(keyedStateBackend).getPartitionedState(Matchers.any(), any(TypeSerializer.class), any(MapStateDescriptor.class));
    when(operatorMock.getKeyedStateStore()).thenReturn(keyedStateStore);
    return operatorMock;
}
Also used : KeyedStateBackend(org.apache.flink.runtime.state.KeyedStateBackend) AbstractKeyedStateBackend(org.apache.flink.runtime.state.AbstractKeyedStateBackend) KvStateRegistry(org.apache.flink.runtime.query.KvStateRegistry) MapStateDescriptor(org.apache.flink.api.common.state.MapStateDescriptor) MemoryStateBackend(org.apache.flink.runtime.state.memory.MemoryStateBackend) JobVertexID(org.apache.flink.runtime.jobgraph.JobVertexID) MapState(org.apache.flink.api.common.state.MapState) KeyGroupRange(org.apache.flink.runtime.state.KeyGroupRange) DummyEnvironment(org.apache.flink.runtime.operators.testutils.DummyEnvironment) ExecutionConfig(org.apache.flink.api.common.ExecutionConfig) AbstractKeyedStateBackend(org.apache.flink.runtime.state.AbstractKeyedStateBackend) InvocationOnMock(org.mockito.invocation.InvocationOnMock) TypeSerializer(org.apache.flink.api.common.typeutils.TypeSerializer) JobID(org.apache.flink.api.common.JobID) DefaultKeyedStateStore(org.apache.flink.runtime.state.DefaultKeyedStateStore)

Aggregations

AbstractKeyedStateBackend (org.apache.flink.runtime.state.AbstractKeyedStateBackend)3 ExecutionConfig (org.apache.flink.api.common.ExecutionConfig)2 JobID (org.apache.flink.api.common.JobID)2 TypeSerializer (org.apache.flink.api.common.typeutils.TypeSerializer)2 JobVertexID (org.apache.flink.runtime.jobgraph.JobVertexID)2 DummyEnvironment (org.apache.flink.runtime.operators.testutils.DummyEnvironment)2 KvStateRegistry (org.apache.flink.runtime.query.KvStateRegistry)2 DefaultKeyedStateStore (org.apache.flink.runtime.state.DefaultKeyedStateStore)2 KeyGroupRange (org.apache.flink.runtime.state.KeyGroupRange)2 KeyedStateBackend (org.apache.flink.runtime.state.KeyedStateBackend)2 MemoryStateBackend (org.apache.flink.runtime.state.memory.MemoryStateBackend)2 InvocationOnMock (org.mockito.invocation.InvocationOnMock)2 IOException (java.io.IOException)1 ConcurrentModificationException (java.util.ConcurrentModificationException)1 ListState (org.apache.flink.api.common.state.ListState)1 ListStateDescriptor (org.apache.flink.api.common.state.ListStateDescriptor)1 MapState (org.apache.flink.api.common.state.MapState)1 MapStateDescriptor (org.apache.flink.api.common.state.MapStateDescriptor)1