Search in sources :

Example 1 with TestCheckpointStreamFactory

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);
    }
}
Also used : UnregisteredMetricsGroup(org.apache.flink.metrics.groups.UnregisteredMetricsGroup) SnapshotResult(org.apache.flink.runtime.state.SnapshotResult) MemoryStateBackend(org.apache.flink.runtime.state.memory.MemoryStateBackend) KeyGroupRange(org.apache.flink.runtime.state.KeyGroupRange) IOException(java.io.IOException) CloseableRegistry(org.apache.flink.core.fs.CloseableRegistry) TestCheckpointStreamFactory(org.apache.flink.runtime.state.testutils.TestCheckpointStreamFactory) MockEnvironment(org.apache.flink.runtime.operators.testutils.MockEnvironment) StreamMockEnvironment(org.apache.flink.streaming.runtime.tasks.StreamMockEnvironment) CheckpointStateOutputStream(org.apache.flink.runtime.state.CheckpointStateOutputStream) ExecutionException(java.util.concurrent.ExecutionException) JobID(org.apache.flink.api.common.JobID) Test(org.junit.Test)

Aggregations

IOException (java.io.IOException)1 ExecutionException (java.util.concurrent.ExecutionException)1 JobID (org.apache.flink.api.common.JobID)1 CloseableRegistry (org.apache.flink.core.fs.CloseableRegistry)1 UnregisteredMetricsGroup (org.apache.flink.metrics.groups.UnregisteredMetricsGroup)1 MockEnvironment (org.apache.flink.runtime.operators.testutils.MockEnvironment)1 CheckpointStateOutputStream (org.apache.flink.runtime.state.CheckpointStateOutputStream)1 KeyGroupRange (org.apache.flink.runtime.state.KeyGroupRange)1 SnapshotResult (org.apache.flink.runtime.state.SnapshotResult)1 MemoryStateBackend (org.apache.flink.runtime.state.memory.MemoryStateBackend)1 TestCheckpointStreamFactory (org.apache.flink.runtime.state.testutils.TestCheckpointStreamFactory)1 StreamMockEnvironment (org.apache.flink.streaming.runtime.tasks.StreamMockEnvironment)1 Test (org.junit.Test)1