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