use of org.apache.flink.runtime.state.testutils.TestCheckpointStreamFactory in project flink by apache.
the class RocksDBAsyncSnapshotTest method testCleanupOfSnapshotsInFailureCase.
/**
* Test that the snapshot files are cleaned up in case of a failure during the snapshot
* procedure.
*/
@Test
public void testCleanupOfSnapshotsInFailureCase() throws Exception {
long checkpointId = 1L;
long timestamp = 42L;
MockEnvironment env = MockEnvironment.builder().build();
final IOException testException = new IOException("Test exception");
CheckpointStateOutputStream outputStream = spy(new FailingStream(testException));
RocksDBStateBackend backend = new RocksDBStateBackend((StateBackend) new MemoryStateBackend());
backend.setDbStoragePath(temporaryFolder.newFolder().toURI().toString());
AbstractKeyedStateBackend<Void> keyedStateBackend = backend.createKeyedStateBackend(env, new JobID(), "test operator", VoidSerializer.INSTANCE, 1, new KeyGroupRange(0, 0), null, TtlTimeProvider.DEFAULT, new UnregisteredMetricsGroup(), Collections.emptyList(), new CloseableRegistry());
try {
// register a state so that the state backend has to checkpoint something
keyedStateBackend.getPartitionedState("namespace", StringSerializer.INSTANCE, new ValueStateDescriptor<>("foobar", String.class));
RunnableFuture<SnapshotResult<KeyedStateHandle>> snapshotFuture = keyedStateBackend.snapshot(checkpointId, timestamp, new TestCheckpointStreamFactory(() -> outputStream), CheckpointOptions.forCheckpointWithDefaultLocation());
try {
FutureUtils.runIfNotDoneAndGet(snapshotFuture);
fail("Expected an exception to be thrown here.");
} catch (ExecutionException e) {
Assert.assertEquals(testException, e.getCause());
}
verify(outputStream).close();
} finally {
IOUtils.closeQuietly(keyedStateBackend);
keyedStateBackend.dispose();
IOUtils.closeQuietly(env);
}
}
Aggregations