Search in sources :

Example 1 with BlockingFSDataInputStream

use of org.apache.flink.runtime.util.BlockingFSDataInputStream 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

AtomicReference (java.util.concurrent.atomic.AtomicReference)1 CloseableRegistry (org.apache.flink.core.fs.CloseableRegistry)1 OneShotLatch (org.apache.flink.core.testutils.OneShotLatch)1 StateObjectCollection (org.apache.flink.runtime.checkpoint.StateObjectCollection)1 OperatorStateBackend (org.apache.flink.runtime.state.OperatorStateBackend)1 OperatorStateHandle (org.apache.flink.runtime.state.OperatorStateHandle)1 BlockingFSDataInputStream (org.apache.flink.runtime.util.BlockingFSDataInputStream)1 FlinkException (org.apache.flink.util.FlinkException)1 FunctionWithException (org.apache.flink.util.function.FunctionWithException)1 Test (org.junit.Test)1