Search in sources :

Example 11 with StateObjectCollection

use of org.apache.flink.runtime.checkpoint.StateObjectCollection in project flink by apache.

the class BackendRestorerProcedureTest method testCanBeCanceledViaRegistry.

/**
 * Test that the restore can be stopped via the provided closeable registry.
 */
@Test
public void testCanBeCanceledViaRegistry() throws Exception {
    CloseableRegistry closeableRegistry = new CloseableRegistry();
    OneShotLatch waitForBlock = new OneShotLatch();
    OneShotLatch unblock = new OneShotLatch();
    OperatorStateHandle blockingRestoreHandle = mock(OperatorStateHandle.class);
    when(blockingRestoreHandle.openInputStream()).thenReturn(new BlockingFSDataInputStream(waitForBlock, unblock));
    List<StateObjectCollection<OperatorStateHandle>> sortedRestoreOptions = Collections.singletonList(new StateObjectCollection<>(Collections.singletonList(blockingRestoreHandle)));
    BackendRestorerProcedure<OperatorStateBackend, OperatorStateHandle> restorerProcedure = new BackendRestorerProcedure<>(backendSupplier, closeableRegistry, "test op state backend");
    AtomicReference<Exception> exceptionReference = new AtomicReference<>(null);
    Thread restoreThread = new Thread(() -> {
        try {
            restorerProcedure.createAndRestore(sortedRestoreOptions);
        } catch (Exception e) {
            exceptionReference.set(e);
        }
    });
    restoreThread.start();
    waitForBlock.await();
    closeableRegistry.close();
    unblock.trigger();
    restoreThread.join();
    Exception exception = exceptionReference.get();
    Assert.assertTrue(exception instanceof FlinkException);
}
Also used : BlockingFSDataInputStream(org.apache.flink.runtime.util.BlockingFSDataInputStream) AtomicReference(java.util.concurrent.atomic.AtomicReference) CloseableRegistry(org.apache.flink.core.fs.CloseableRegistry) FlinkException(org.apache.flink.util.FlinkException) FunctionWithException(org.apache.flink.util.function.FunctionWithException) FlinkException(org.apache.flink.util.FlinkException) StateObjectCollection(org.apache.flink.runtime.checkpoint.StateObjectCollection) OperatorStateBackend(org.apache.flink.runtime.state.OperatorStateBackend) OneShotLatch(org.apache.flink.core.testutils.OneShotLatch) OperatorStateHandle(org.apache.flink.runtime.state.OperatorStateHandle) Test(org.junit.Test)

Aggregations

StateObjectCollection (org.apache.flink.runtime.checkpoint.StateObjectCollection)11 OperatorStateHandle (org.apache.flink.runtime.state.OperatorStateHandle)10 KeyedStateHandle (org.apache.flink.runtime.state.KeyedStateHandle)7 Test (org.junit.Test)6 OperatorSubtaskState (org.apache.flink.runtime.checkpoint.OperatorSubtaskState)5 CloseableRegistry (org.apache.flink.core.fs.CloseableRegistry)4 KeyGroupRange (org.apache.flink.runtime.state.KeyGroupRange)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 JobID (org.apache.flink.api.common.JobID)3 JobManagerTaskRestore (org.apache.flink.runtime.checkpoint.JobManagerTaskRestore)3 TaskStateSnapshot (org.apache.flink.runtime.checkpoint.TaskStateSnapshot)3 ExecutionAttemptID (org.apache.flink.runtime.executiongraph.ExecutionAttemptID)3 OperatorID (org.apache.flink.runtime.jobgraph.OperatorID)3 InputChannelStateHandle (org.apache.flink.runtime.state.InputChannelStateHandle)3 ResultSubpartitionStateHandle (org.apache.flink.runtime.state.ResultSubpartitionStateHandle)3 SnapshotResult (org.apache.flink.runtime.state.SnapshotResult)3 KeyGroupRangeOffsets (org.apache.flink.runtime.state.KeyGroupRangeOffsets)2 KeyGroupsStateHandle (org.apache.flink.runtime.state.KeyGroupsStateHandle)2 OperatorStateBackend (org.apache.flink.runtime.state.OperatorStateBackend)2