Search in sources :

Example 11 with TestCompletedCheckpointStorageLocation

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

the class CompletedCheckpointTest method testCompletedCheckpointStatsCallbacks.

/**
 * Tests that the stats callbacks happen if the callback is registered.
 */
@Test
public void testCompletedCheckpointStatsCallbacks() throws Exception {
    CompletedCheckpoint completed = new CompletedCheckpoint(new JobID(), 0, 0, 1, Collections.emptyMap(), Collections.emptyList(), CheckpointProperties.forCheckpoint(CheckpointRetentionPolicy.NEVER_RETAIN_AFTER_TERMINATION), new TestCompletedCheckpointStorageLocation());
    CompletedCheckpointStats.DiscardCallback callback = mock(CompletedCheckpointStats.DiscardCallback.class);
    completed.setDiscardCallback(callback);
    completed.discardOnShutdown(JobStatus.FINISHED);
    verify(callback, times(1)).notifyDiscardedCheckpoint();
}
Also used : TestCompletedCheckpointStorageLocation(org.apache.flink.runtime.state.testutils.TestCompletedCheckpointStorageLocation) JobID(org.apache.flink.api.common.JobID) Test(org.junit.Test)

Example 12 with TestCompletedCheckpointStorageLocation

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

the class CompletedCheckpointTest method testCompareCheckpointsWithSameOrder.

@Test
public void testCompareCheckpointsWithSameOrder() {
    CompletedCheckpoint checkpoint1 = new CompletedCheckpoint(new JobID(), 0, 0, 1, new HashMap<>(), Collections.emptyList(), CheckpointProperties.forCheckpoint(CheckpointRetentionPolicy.RETAIN_ON_FAILURE), new TestCompletedCheckpointStorageLocation());
    CompletedCheckpoint checkpoint2 = new CompletedCheckpoint(new JobID(), 1, 0, 1, new HashMap<>(), Collections.emptyList(), CheckpointProperties.forCheckpoint(CheckpointRetentionPolicy.RETAIN_ON_FAILURE), new TestCompletedCheckpointStorageLocation());
    List<CompletedCheckpoint> checkpoints1 = new ArrayList<>();
    checkpoints1.add(checkpoint1);
    checkpoints1.add(checkpoint2);
    checkpoints1.add(checkpoint1);
    List<CompletedCheckpoint> checkpoints2 = new ArrayList<>();
    checkpoints2.add(checkpoint1);
    checkpoints2.add(checkpoint2);
    checkpoints2.add(checkpoint1);
    assertTrue(CompletedCheckpoint.checkpointsMatch(checkpoints1, checkpoints2));
}
Also used : ArrayList(java.util.ArrayList) TestCompletedCheckpointStorageLocation(org.apache.flink.runtime.state.testutils.TestCompletedCheckpointStorageLocation) JobID(org.apache.flink.api.common.JobID) Test(org.junit.Test)

Example 13 with TestCompletedCheckpointStorageLocation

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

the class CompletedCheckpointTest method testRegisterStatesAtRegistry.

@Test
public void testRegisterStatesAtRegistry() {
    OperatorState state = mock(OperatorState.class);
    Map<OperatorID, OperatorState> operatorStates = new HashMap<>();
    operatorStates.put(new OperatorID(), state);
    CompletedCheckpoint checkpoint = new CompletedCheckpoint(new JobID(), 0, 0, 1, operatorStates, Collections.emptyList(), CheckpointProperties.forCheckpoint(CheckpointRetentionPolicy.RETAIN_ON_FAILURE), new TestCompletedCheckpointStorageLocation());
    SharedStateRegistry sharedStateRegistry = new SharedStateRegistryImpl();
    checkpoint.registerSharedStatesAfterRestored(sharedStateRegistry);
    verify(state, times(1)).registerSharedStates(sharedStateRegistry, 0L);
}
Also used : 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 14 with TestCompletedCheckpointStorageLocation

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

the class CompletedCheckpointTest method testCompareCheckpointsWithDifferentOrder.

@Test
public void testCompareCheckpointsWithDifferentOrder() {
    CompletedCheckpoint checkpoint1 = new CompletedCheckpoint(new JobID(), 0, 0, 1, new HashMap<>(), Collections.emptyList(), CheckpointProperties.forCheckpoint(CheckpointRetentionPolicy.RETAIN_ON_FAILURE), new TestCompletedCheckpointStorageLocation());
    CompletedCheckpoint checkpoint2 = new CompletedCheckpoint(new JobID(), 1, 0, 1, new HashMap<>(), Collections.emptyList(), CheckpointProperties.forCheckpoint(CheckpointRetentionPolicy.RETAIN_ON_FAILURE), new TestCompletedCheckpointStorageLocation());
    List<CompletedCheckpoint> checkpoints1 = new ArrayList<>();
    checkpoints1.add(checkpoint1);
    checkpoints1.add(checkpoint2);
    checkpoints1.add(checkpoint1);
    List<CompletedCheckpoint> checkpoints2 = new ArrayList<>();
    checkpoints2.add(checkpoint2);
    checkpoints2.add(checkpoint1);
    checkpoints2.add(checkpoint2);
    assertFalse(CompletedCheckpoint.checkpointsMatch(checkpoints1, checkpoints2));
}
Also used : ArrayList(java.util.ArrayList) TestCompletedCheckpointStorageLocation(org.apache.flink.runtime.state.testutils.TestCompletedCheckpointStorageLocation) JobID(org.apache.flink.api.common.JobID) Test(org.junit.Test)

Example 15 with TestCompletedCheckpointStorageLocation

use of org.apache.flink.runtime.state.testutils.TestCompletedCheckpointStorageLocation 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)

Aggregations

TestCompletedCheckpointStorageLocation (org.apache.flink.runtime.state.testutils.TestCompletedCheckpointStorageLocation)18 Test (org.junit.Test)15 JobID (org.apache.flink.api.common.JobID)14 OperatorID (org.apache.flink.runtime.jobgraph.OperatorID)8 HashMap (java.util.HashMap)7 ArrayList (java.util.ArrayList)6 JobVertexID (org.apache.flink.runtime.jobgraph.JobVertexID)6 ExecutionGraph (org.apache.flink.runtime.executiongraph.ExecutionGraph)5 CheckpointCoordinatorBuilder (org.apache.flink.runtime.checkpoint.CheckpointCoordinatorTestingUtils.CheckpointCoordinatorBuilder)4 ExecutionJobVertex (org.apache.flink.runtime.executiongraph.ExecutionJobVertex)4 SharedStateRegistry (org.apache.flink.runtime.state.SharedStateRegistry)4 HashSet (java.util.HashSet)3 OperatorIDPair (org.apache.flink.runtime.OperatorIDPair)3 ManuallyTriggeredScheduledExecutor (org.apache.flink.util.concurrent.ManuallyTriggeredScheduledExecutor)3 IOException (java.io.IOException)2 Collection (java.util.Collection)2 Collections.emptyList (java.util.Collections.emptyList)2 Collections.singletonList (java.util.Collections.singletonList)2 List (java.util.List)2 CountDownLatch (java.util.concurrent.CountDownLatch)2