Search in sources :

Example 6 with StatePartitionStreamProvider

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

the class StreamTaskStateInitializerImplTest method testNoRestore.

@Test
public void testNoRestore() throws Exception {
    MemoryStateBackend stateBackend = spy(new MemoryStateBackend(1024));
    // No job manager provided state to restore
    StreamTaskStateInitializer streamTaskStateManager = streamTaskStateManager(stateBackend, null, true);
    OperatorID operatorID = new OperatorID(47L, 11L);
    AbstractStreamOperator<?> streamOperator = mock(AbstractStreamOperator.class);
    when(streamOperator.getOperatorID()).thenReturn(operatorID);
    TypeSerializer<?> typeSerializer = new IntSerializer();
    CloseableRegistry closeableRegistry = new CloseableRegistry();
    StreamOperatorStateContext stateContext = streamTaskStateManager.streamOperatorStateContext(streamOperator.getOperatorID(), streamOperator.getClass().getSimpleName(), new TestProcessingTimeService(), streamOperator, typeSerializer, closeableRegistry, new UnregisteredMetricsGroup(), 1.0, false);
    OperatorStateBackend operatorStateBackend = stateContext.operatorStateBackend();
    CheckpointableKeyedStateBackend<?> keyedStateBackend = stateContext.keyedStateBackend();
    InternalTimeServiceManager<?> timeServiceManager = stateContext.internalTimerServiceManager();
    CloseableIterable<KeyGroupStatePartitionStreamProvider> keyedStateInputs = stateContext.rawKeyedStateInputs();
    CloseableIterable<StatePartitionStreamProvider> operatorStateInputs = stateContext.rawOperatorStateInputs();
    Assert.assertFalse("Expected the context to NOT be restored", stateContext.isRestored());
    Assert.assertNotNull(operatorStateBackend);
    Assert.assertNotNull(keyedStateBackend);
    Assert.assertNotNull(timeServiceManager);
    Assert.assertNotNull(keyedStateInputs);
    Assert.assertNotNull(operatorStateInputs);
    checkCloseablesRegistered(closeableRegistry, operatorStateBackend, keyedStateBackend, keyedStateInputs, operatorStateInputs);
    Assert.assertFalse(keyedStateInputs.iterator().hasNext());
    Assert.assertFalse(operatorStateInputs.iterator().hasNext());
}
Also used : IntSerializer(org.apache.flink.api.common.typeutils.base.IntSerializer) UnregisteredMetricsGroup(org.apache.flink.metrics.groups.UnregisteredMetricsGroup) MemoryStateBackend(org.apache.flink.runtime.state.memory.MemoryStateBackend) OperatorID(org.apache.flink.runtime.jobgraph.OperatorID) CloseableRegistry(org.apache.flink.core.fs.CloseableRegistry) KeyGroupStatePartitionStreamProvider(org.apache.flink.runtime.state.KeyGroupStatePartitionStreamProvider) KeyGroupStatePartitionStreamProvider(org.apache.flink.runtime.state.KeyGroupStatePartitionStreamProvider) StatePartitionStreamProvider(org.apache.flink.runtime.state.StatePartitionStreamProvider) OperatorStateBackend(org.apache.flink.runtime.state.OperatorStateBackend) TestProcessingTimeService(org.apache.flink.streaming.runtime.tasks.TestProcessingTimeService) TaskStateManagerImplTest(org.apache.flink.runtime.state.TaskStateManagerImplTest) Test(org.junit.Test)

Example 7 with StatePartitionStreamProvider

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

the class StateInitializationContextImplTest method getOperatorStateStreams.

@Test
public void getOperatorStateStreams() throws Exception {
    int i = 0;
    int s = 0;
    for (StatePartitionStreamProvider streamProvider : initializationContext.getRawOperatorStateInputs()) {
        if (0 == i % 4) {
            ++i;
        }
        Assert.assertNotNull(streamProvider);
        try (InputStream is = streamProvider.getStream()) {
            DataInputView div = new DataInputViewStreamWrapper(is);
            int val = div.readInt();
            Assert.assertEquals(i * NUM_HANDLES + s, val);
        }
        ++s;
        if (s == i % 4) {
            s = 0;
            ++i;
        }
    }
}
Also used : KeyGroupStatePartitionStreamProvider(org.apache.flink.runtime.state.KeyGroupStatePartitionStreamProvider) StatePartitionStreamProvider(org.apache.flink.runtime.state.StatePartitionStreamProvider) FSDataInputStream(org.apache.flink.core.fs.FSDataInputStream) InputStream(java.io.InputStream) DataInputView(org.apache.flink.core.memory.DataInputView) DataInputViewStreamWrapper(org.apache.flink.core.memory.DataInputViewStreamWrapper) Test(org.junit.Test)

Aggregations

KeyGroupStatePartitionStreamProvider (org.apache.flink.runtime.state.KeyGroupStatePartitionStreamProvider)7 StatePartitionStreamProvider (org.apache.flink.runtime.state.StatePartitionStreamProvider)7 Test (org.junit.Test)4 CloseableRegistry (org.apache.flink.core.fs.CloseableRegistry)3 OperatorStateBackend (org.apache.flink.runtime.state.OperatorStateBackend)3 InputStream (java.io.InputStream)2 IntSerializer (org.apache.flink.api.common.typeutils.base.IntSerializer)2 FSDataInputStream (org.apache.flink.core.fs.FSDataInputStream)2 DataInputView (org.apache.flink.core.memory.DataInputView)2 DataInputViewStreamWrapper (org.apache.flink.core.memory.DataInputViewStreamWrapper)2 UnregisteredMetricsGroup (org.apache.flink.metrics.groups.UnregisteredMetricsGroup)2 OperatorID (org.apache.flink.runtime.jobgraph.OperatorID)2 OperatorStateHandle (org.apache.flink.runtime.state.OperatorStateHandle)2 TaskStateManagerImplTest (org.apache.flink.runtime.state.TaskStateManagerImplTest)2 MemoryStateBackend (org.apache.flink.runtime.state.memory.MemoryStateBackend)2 TestProcessingTimeService (org.apache.flink.streaming.runtime.tasks.TestProcessingTimeService)2 IOException (java.io.IOException)1 HashSet (java.util.HashSet)1 NoSuchElementException (java.util.NoSuchElementException)1 OptionalLong (java.util.OptionalLong)1