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());
}
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());
}
}
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());
}
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());
}
Aggregations