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());
}
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;
}
}
}
Aggregations