Search in sources :

Example 11 with StateSnapshotContextSynchronousImpl

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

the class AbstractStreamOperatorTest method testFailingSnapshotMethod.

/**
	 * Tests that the created StateSnapshotContextSynchronousImpl is closed in case of a failing
	 * Operator#snapshotState(StaetSnapshotContextSynchronousImpl) call.
	 */
@Test
public void testFailingSnapshotMethod() throws Exception {
    final long checkpointId = 42L;
    final long timestamp = 1L;
    final Exception failingException = new Exception("Test exception");
    final CloseableRegistry closeableRegistry = new CloseableRegistry();
    StateSnapshotContextSynchronousImpl context = mock(StateSnapshotContextSynchronousImpl.class);
    whenNew(StateSnapshotContextSynchronousImpl.class).withAnyArguments().thenReturn(context);
    StreamTask<Void, AbstractStreamOperator<Void>> containingTask = mock(StreamTask.class);
    when(containingTask.getCancelables()).thenReturn(closeableRegistry);
    AbstractStreamOperator<Void> operator = mock(AbstractStreamOperator.class);
    when(operator.snapshotState(anyLong(), anyLong(), any(CheckpointOptions.class))).thenCallRealMethod();
    doReturn(containingTask).when(operator).getContainingTask();
    // lets fail when calling the actual snapshotState method
    doThrow(failingException).when(operator).snapshotState(eq(context));
    try {
        operator.snapshotState(checkpointId, timestamp, CheckpointOptions.forFullCheckpoint());
        fail("Exception expected.");
    } catch (Exception e) {
        assertEquals(failingException, e.getCause());
    }
    verify(context).close();
}
Also used : StateSnapshotContextSynchronousImpl(org.apache.flink.runtime.state.StateSnapshotContextSynchronousImpl) CheckpointOptions(org.apache.flink.runtime.checkpoint.CheckpointOptions) CloseableRegistry(org.apache.flink.core.fs.CloseableRegistry) IOException(java.io.IOException) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

StateSnapshotContextSynchronousImpl (org.apache.flink.runtime.state.StateSnapshotContextSynchronousImpl)11 Test (org.junit.Test)9 LinkedMap (org.apache.commons.collections.map.LinkedMap)5 OperatorStateStore (org.apache.flink.api.common.state.OperatorStateStore)5 Serializable (java.io.Serializable)4 Configuration (org.apache.flink.configuration.Configuration)4 CloseableRegistry (org.apache.flink.core.fs.CloseableRegistry)4 CheckpointStreamFactory (org.apache.flink.runtime.state.CheckpointStreamFactory)4 StateInitializationContext (org.apache.flink.runtime.state.StateInitializationContext)4 IOException (java.io.IOException)3 ListStateDescriptor (org.apache.flink.api.common.state.ListStateDescriptor)3 Tuple2 (org.apache.flink.api.java.tuple.Tuple2)3 CheckpointOptions (org.apache.flink.runtime.checkpoint.CheckpointOptions)3 KeyGroupRange (org.apache.flink.runtime.state.KeyGroupRange)3 KafkaTopicPartition (org.apache.flink.streaming.connectors.kafka.internals.KafkaTopicPartition)3 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)3 HashMap (java.util.HashMap)2 MemCheckpointStreamFactory (org.apache.flink.runtime.state.memory.MemCheckpointStreamFactory)2 StreamingRuntimeContext (org.apache.flink.streaming.api.operators.StreamingRuntimeContext)2 ConcurrentModificationException (java.util.ConcurrentModificationException)1