Search in sources :

Example 1 with EmptyStreamStateHandle

use of org.apache.flink.runtime.state.testutils.EmptyStreamStateHandle in project flink by apache.

the class CompletedCheckpointTest method testCleanUpOnSubsume.

/**
 * Tests that the garbage collection properties are respected when subsuming checkpoints.
 */
@Test
public void testCleanUpOnSubsume() throws Exception {
    OperatorState state = mock(OperatorState.class);
    Map<OperatorID, OperatorState> operatorStates = new HashMap<>();
    operatorStates.put(new OperatorID(), state);
    EmptyStreamStateHandle metadata = new EmptyStreamStateHandle();
    TestCompletedCheckpointStorageLocation location = new TestCompletedCheckpointStorageLocation(metadata, "ptr");
    CheckpointProperties props = new CheckpointProperties(false, CheckpointType.CHECKPOINT, true, false, false, false, false, false);
    CompletedCheckpoint checkpoint = new CompletedCheckpoint(new JobID(), 0, 0, 1, operatorStates, Collections.emptyList(), props, location);
    SharedStateRegistry sharedStateRegistry = new SharedStateRegistryImpl();
    checkpoint.registerSharedStatesAfterRestored(sharedStateRegistry);
    verify(state, times(1)).registerSharedStates(sharedStateRegistry, 0L);
    // Subsume
    checkpoint.discardOnSubsume();
    verify(state, times(1)).discardState();
    assertTrue(location.isDisposed());
    assertTrue(metadata.isDisposed());
}
Also used : EmptyStreamStateHandle(org.apache.flink.runtime.state.testutils.EmptyStreamStateHandle) HashMap(java.util.HashMap) SharedStateRegistryImpl(org.apache.flink.runtime.state.SharedStateRegistryImpl) TestCompletedCheckpointStorageLocation(org.apache.flink.runtime.state.testutils.TestCompletedCheckpointStorageLocation) OperatorID(org.apache.flink.runtime.jobgraph.OperatorID) JobID(org.apache.flink.api.common.JobID) SharedStateRegistry(org.apache.flink.runtime.state.SharedStateRegistry) Test(org.junit.Test)

Example 2 with EmptyStreamStateHandle

use of org.apache.flink.runtime.state.testutils.EmptyStreamStateHandle in project flink by apache.

the class CompletedCheckpointTest method testCleanUpOnShutdown.

/**
 * Tests that the garbage collection properties are respected when shutting down.
 */
@Test
public void testCleanUpOnShutdown() throws Exception {
    JobStatus[] terminalStates = new JobStatus[] { JobStatus.FINISHED, JobStatus.CANCELED, JobStatus.FAILED, JobStatus.SUSPENDED };
    for (JobStatus status : terminalStates) {
        OperatorState state = mock(OperatorState.class);
        Map<OperatorID, OperatorState> operatorStates = new HashMap<>();
        operatorStates.put(new OperatorID(), state);
        EmptyStreamStateHandle retainedHandle = new EmptyStreamStateHandle();
        TestCompletedCheckpointStorageLocation retainedLocation = new TestCompletedCheckpointStorageLocation(retainedHandle, "ptr");
        // Keep
        CheckpointProperties retainProps = new CheckpointProperties(false, CheckpointType.CHECKPOINT, false, false, false, false, false, false);
        CompletedCheckpoint checkpoint = new CompletedCheckpoint(new JobID(), 0, 0, 1, new HashMap<>(operatorStates), Collections.emptyList(), retainProps, retainedLocation);
        checkpoint.discardOnShutdown(status);
        verify(state, times(0)).discardState();
        assertFalse(retainedLocation.isDisposed());
        assertFalse(retainedHandle.isDisposed());
        // Discard
        EmptyStreamStateHandle discardHandle = new EmptyStreamStateHandle();
        TestCompletedCheckpointStorageLocation discardLocation = new TestCompletedCheckpointStorageLocation(discardHandle, "ptr");
        // Keep
        CheckpointProperties discardProps = new CheckpointProperties(false, CheckpointType.CHECKPOINT, true, true, true, true, true, false);
        checkpoint = new CompletedCheckpoint(new JobID(), 0, 0, 1, new HashMap<>(operatorStates), Collections.emptyList(), discardProps, discardLocation);
        checkpoint.discardOnShutdown(status);
        verify(state, times(1)).discardState();
        assertTrue(discardLocation.isDisposed());
        assertTrue(discardHandle.isDisposed());
    }
}
Also used : JobStatus(org.apache.flink.api.common.JobStatus) EmptyStreamStateHandle(org.apache.flink.runtime.state.testutils.EmptyStreamStateHandle) HashMap(java.util.HashMap) TestCompletedCheckpointStorageLocation(org.apache.flink.runtime.state.testutils.TestCompletedCheckpointStorageLocation) OperatorID(org.apache.flink.runtime.jobgraph.OperatorID) JobID(org.apache.flink.api.common.JobID) Test(org.junit.Test)

Example 3 with EmptyStreamStateHandle

use of org.apache.flink.runtime.state.testutils.EmptyStreamStateHandle in project flink by apache.

the class StopWithSavepointTerminationHandlerImplTest method testHappyPath.

@Test
public void testHappyPath() throws ExecutionException, InterruptedException {
    final StopWithSavepointTerminationHandlerImpl testInstance = createTestInstanceFailingOnGlobalFailOver();
    final EmptyStreamStateHandle streamStateHandle = new EmptyStreamStateHandle();
    final CompletedCheckpoint completedSavepoint = createCompletedSavepoint(streamStateHandle);
    testInstance.handleSavepointCreation(completedSavepoint, null);
    testInstance.handleExecutionsTermination(Collections.singleton(ExecutionState.FINISHED));
    assertThat(testInstance.getSavepointPath().get(), is(completedSavepoint.getExternalPointer()));
    assertFalse("The savepoint should not have been discarded.", streamStateHandle.isDisposed());
    assertFalse("Checkpoint scheduling should be disabled.", checkpointScheduling.isEnabled());
}
Also used : EmptyStreamStateHandle(org.apache.flink.runtime.state.testutils.EmptyStreamStateHandle) CompletedCheckpoint(org.apache.flink.runtime.checkpoint.CompletedCheckpoint) Test(org.junit.Test)

Example 4 with EmptyStreamStateHandle

use of org.apache.flink.runtime.state.testutils.EmptyStreamStateHandle in project flink by apache.

the class StopWithSavepointTerminationHandlerImplTest method testFailedTerminationHandling.

@Test
public void testFailedTerminationHandling() throws ExecutionException, InterruptedException {
    final CompletableFuture<Throwable> globalFailOverTriggered = new CompletableFuture<>();
    final StopWithSavepointTerminationHandlerImpl testInstance = createTestInstance(globalFailOverTriggered::complete);
    final ExecutionState expectedNonFinishedState = ExecutionState.FAILED;
    final String expectedErrorMessage = String.format("Inconsistent execution state after stopping with savepoint. At least one execution is still in one of the following states: %s. A global fail-over is triggered to recover the job %s.", expectedNonFinishedState, JOB_ID);
    final EmptyStreamStateHandle streamStateHandle = new EmptyStreamStateHandle();
    final CompletedCheckpoint completedSavepoint = createCompletedSavepoint(streamStateHandle);
    testInstance.handleSavepointCreation(completedSavepoint, null);
    testInstance.handleExecutionsTermination(Collections.singletonList(expectedNonFinishedState));
    try {
        testInstance.getSavepointPath().get();
        fail("An ExecutionException is expected.");
    } catch (Throwable e) {
        final Optional<FlinkException> actualFlinkException = ExceptionUtils.findThrowable(e, FlinkException.class);
        assertTrue("A FlinkException should have been thrown.", actualFlinkException.isPresent());
        assertThat(actualFlinkException.get(), FlinkMatchers.containsMessage(expectedErrorMessage));
    }
    assertTrue("Global fail-over was not triggered.", globalFailOverTriggered.isDone());
    assertThat(globalFailOverTriggered.get(), FlinkMatchers.containsMessage(expectedErrorMessage));
    assertFalse("Savepoint should not be discarded.", streamStateHandle.isDisposed());
    assertFalse("Checkpoint scheduling should not be enabled in case of failure.", checkpointScheduling.isEnabled());
}
Also used : EmptyStreamStateHandle(org.apache.flink.runtime.state.testutils.EmptyStreamStateHandle) CompletedCheckpoint(org.apache.flink.runtime.checkpoint.CompletedCheckpoint) ExecutionState(org.apache.flink.runtime.execution.ExecutionState) CompletableFuture(java.util.concurrent.CompletableFuture) Optional(java.util.Optional) FlinkException(org.apache.flink.util.FlinkException) Test(org.junit.Test)

Aggregations

EmptyStreamStateHandle (org.apache.flink.runtime.state.testutils.EmptyStreamStateHandle)4 Test (org.junit.Test)4 HashMap (java.util.HashMap)2 JobID (org.apache.flink.api.common.JobID)2 CompletedCheckpoint (org.apache.flink.runtime.checkpoint.CompletedCheckpoint)2 OperatorID (org.apache.flink.runtime.jobgraph.OperatorID)2 TestCompletedCheckpointStorageLocation (org.apache.flink.runtime.state.testutils.TestCompletedCheckpointStorageLocation)2 Optional (java.util.Optional)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 JobStatus (org.apache.flink.api.common.JobStatus)1 ExecutionState (org.apache.flink.runtime.execution.ExecutionState)1 SharedStateRegistry (org.apache.flink.runtime.state.SharedStateRegistry)1 SharedStateRegistryImpl (org.apache.flink.runtime.state.SharedStateRegistryImpl)1 FlinkException (org.apache.flink.util.FlinkException)1