Search in sources :

Example 6 with TestingStreamStateHandle

use of org.apache.flink.runtime.state.TestingStreamStateHandle in project flink by apache.

the class PendingCheckpointTest method testAcknowledgedCoordinatorStates.

@Test
public void testAcknowledgedCoordinatorStates() throws Exception {
    final OperatorInfo coord1 = new TestingOperatorInfo();
    final OperatorInfo coord2 = new TestingOperatorInfo();
    final PendingCheckpoint checkpoint = createPendingCheckpointWithCoordinators(coord1, coord2);
    final TaskAcknowledgeResult ack1 = checkpoint.acknowledgeCoordinatorState(coord1, new TestingStreamStateHandle());
    final TaskAcknowledgeResult ack2 = checkpoint.acknowledgeCoordinatorState(coord2, null);
    assertEquals(TaskAcknowledgeResult.SUCCESS, ack1);
    assertEquals(TaskAcknowledgeResult.SUCCESS, ack2);
    assertEquals(0, checkpoint.getNumberOfNonAcknowledgedOperatorCoordinators());
    assertTrue(checkpoint.isFullyAcknowledged());
    assertThat(checkpoint.getOperatorStates().keySet(), containsInAnyOrder(OPERATOR_ID, coord1.operatorId(), coord2.operatorId()));
}
Also used : TestingStreamStateHandle(org.apache.flink.runtime.state.TestingStreamStateHandle) TaskAcknowledgeResult(org.apache.flink.runtime.checkpoint.PendingCheckpoint.TaskAcknowledgeResult) OperatorInfo(org.apache.flink.runtime.operators.coordination.OperatorInfo) TestingOperatorInfo(org.apache.flink.runtime.operators.coordination.TestingOperatorInfo) TestingOperatorInfo(org.apache.flink.runtime.operators.coordination.TestingOperatorInfo) Test(org.junit.Test)

Example 7 with TestingStreamStateHandle

use of org.apache.flink.runtime.state.TestingStreamStateHandle in project flink by apache.

the class DefaultCompletedCheckpointStoreTest method testShutdownShouldNotDiscardStateHandleWhenJobIsNotGloballyTerminalState.

@Test
public void testShutdownShouldNotDiscardStateHandleWhenJobIsNotGloballyTerminalState() throws Exception {
    final AtomicInteger removeCalledNum = new AtomicInteger(0);
    final CompletableFuture<Void> removeAllFuture = new CompletableFuture<>();
    final CompletableFuture<Void> releaseAllFuture = new CompletableFuture<>();
    final TestingStateHandleStore<CompletedCheckpoint> stateHandleStore = builder.setGetAllSupplier(() -> createStateHandles(3)).setRemoveFunction(ignore -> {
        removeCalledNum.incrementAndGet();
        return true;
    }).setReleaseAllHandlesRunnable(() -> releaseAllFuture.complete(null)).setClearEntriesRunnable(() -> removeAllFuture.complete(null)).build();
    final CompletedCheckpointStore completedCheckpointStore = createCompletedCheckpointStore(stateHandleStore);
    assertThat(completedCheckpointStore.getAllCheckpoints().size(), is(3));
    TestingStreamStateHandle streamStateHandle = registerState(completedCheckpointStore, 3L);
    completedCheckpointStore.shutdown(JobStatus.CANCELLING, new CheckpointsCleaner());
    try {
        removeAllFuture.get(timeout, TimeUnit.MILLISECONDS);
        fail("We should get an expected timeout because the job is not globally terminated.");
    } catch (TimeoutException ex) {
    // expected
    }
    assertThat(removeCalledNum.get(), is(0));
    assertThat(removeAllFuture.isDone(), is(false));
    assertThat(releaseAllFuture.isDone(), is(true));
    assertThat(completedCheckpointStore.getAllCheckpoints().size(), is(0));
    assertThat(streamStateHandle.isDisposed(), is(false));
}
Also used : FlinkException(org.apache.flink.util.FlinkException) SavepointFormatType(org.apache.flink.core.execution.SavepointFormatType) Tuple2(org.apache.flink.api.java.tuple.Tuple2) Assert.assertThrows(org.junit.Assert.assertThrows) FlinkMatchers(org.apache.flink.core.testutils.FlinkMatchers) TestCompletedCheckpointStorageLocation(org.apache.flink.runtime.state.testutils.TestCompletedCheckpointStorageLocation) SharedStateRegistry(org.apache.flink.runtime.state.SharedStateRegistry) TimeoutException(java.util.concurrent.TimeoutException) ExceptionUtils(org.apache.flink.util.ExceptionUtils) CompletableFuture(java.util.concurrent.CompletableFuture) JobStatus(org.apache.flink.api.common.JobStatus) NEVER_RETAIN_AFTER_TERMINATION(org.apache.flink.runtime.checkpoint.CheckpointRetentionPolicy.NEVER_RETAIN_AFTER_TERMINATION) ArrayList(java.util.ArrayList) Assert.assertThat(org.junit.Assert.assertThat) TestingRetrievableStateStorageHelper(org.apache.flink.runtime.persistence.TestingRetrievableStateStorageHelper) SharedStateRegistryKey(org.apache.flink.runtime.state.SharedStateRegistryKey) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Arrays.asList(java.util.Arrays.asList) After(org.junit.After) TestLogger(org.apache.flink.util.TestLogger) StateHandleStore(org.apache.flink.runtime.persistence.StateHandleStore) Assert.fail(org.junit.Assert.fail) ExecutorService(java.util.concurrent.ExecutorService) Before(org.junit.Before) RetrievableStateHandle(org.apache.flink.runtime.state.RetrievableStateHandle) ExecutorThreadFactory(org.apache.flink.util.concurrent.ExecutorThreadFactory) Collections.emptyList(java.util.Collections.emptyList) Test(org.junit.Test) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) TestingStreamStateHandle(org.apache.flink.runtime.state.TestingStreamStateHandle) Executors(java.util.concurrent.Executors) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) JobID(org.apache.flink.api.common.JobID) SharedStateRegistryImpl(org.apache.flink.runtime.state.SharedStateRegistryImpl) Matchers.contains(org.hamcrest.Matchers.contains) Matchers.is(org.hamcrest.Matchers.is) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) TestingStateHandleStore(org.apache.flink.runtime.persistence.TestingStateHandleStore) TestingStreamStateHandle(org.apache.flink.runtime.state.TestingStreamStateHandle) CompletableFuture(java.util.concurrent.CompletableFuture) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TimeoutException(java.util.concurrent.TimeoutException) Test(org.junit.Test)

Example 8 with TestingStreamStateHandle

use of org.apache.flink.runtime.state.TestingStreamStateHandle in project flink by apache.

the class PendingCheckpointTest method testDisposeDisposesCoordinatorStates.

@Test
public void testDisposeDisposesCoordinatorStates() throws Exception {
    final TestingStreamStateHandle handle1 = new TestingStreamStateHandle();
    final TestingStreamStateHandle handle2 = new TestingStreamStateHandle();
    final PendingCheckpoint checkpoint = createPendingCheckpointWithAcknowledgedCoordinators(handle1, handle2);
    abort(checkpoint, CheckpointFailureReason.CHECKPOINT_EXPIRED);
    assertTrue(handle1.isDisposed());
    assertTrue(handle2.isDisposed());
}
Also used : TestingStreamStateHandle(org.apache.flink.runtime.state.TestingStreamStateHandle) Test(org.junit.Test)

Example 9 with TestingStreamStateHandle

use of org.apache.flink.runtime.state.TestingStreamStateHandle in project flink by apache.

the class DefaultCheckpointPlanTest method testFulfillFullyFinishedStatesWithCoordinator.

@Test
public void testFulfillFullyFinishedStatesWithCoordinator() throws Exception {
    JobVertexID finishedJobVertexID = new JobVertexID();
    OperatorID finishedOperatorID = new OperatorID();
    ExecutionGraph executionGraph = new CheckpointCoordinatorTestingUtils.CheckpointExecutionGraphBuilder().addJobVertex(finishedJobVertexID, 1, 256, Collections.singletonList(OperatorIDPair.generatedIDOnly(finishedOperatorID)), true).build();
    executionGraph.getJobVertex(finishedJobVertexID).getTaskVertices()[0].getCurrentExecutionAttempt().markFinished();
    CheckpointPlan checkpointPlan = createCheckpointPlan(executionGraph);
    Map<OperatorID, OperatorState> operatorStates = new HashMap<>();
    OperatorState operatorState = new OperatorState(finishedOperatorID, 1, 256);
    operatorState.setCoordinatorState(new TestingStreamStateHandle());
    operatorStates.put(finishedOperatorID, operatorState);
    checkpointPlan.fulfillFinishedTaskStatus(operatorStates);
    assertEquals(1, operatorStates.size());
    assertTrue(operatorStates.get(finishedOperatorID).isFullyFinished());
}
Also used : TestingStreamStateHandle(org.apache.flink.runtime.state.TestingStreamStateHandle) HashMap(java.util.HashMap) JobVertexID(org.apache.flink.runtime.jobgraph.JobVertexID) ExecutionGraph(org.apache.flink.runtime.executiongraph.ExecutionGraph) OperatorID(org.apache.flink.runtime.jobgraph.OperatorID) Test(org.junit.Test)

Aggregations

TestingStreamStateHandle (org.apache.flink.runtime.state.TestingStreamStateHandle)9 Test (org.junit.Test)7 HashMap (java.util.HashMap)2 CompletableFuture (java.util.concurrent.CompletableFuture)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 TaskAcknowledgeResult (org.apache.flink.runtime.checkpoint.PendingCheckpoint.TaskAcknowledgeResult)2 ExecutionGraph (org.apache.flink.runtime.executiongraph.ExecutionGraph)2 JobVertexID (org.apache.flink.runtime.jobgraph.JobVertexID)2 OperatorID (org.apache.flink.runtime.jobgraph.OperatorID)2 OperatorInfo (org.apache.flink.runtime.operators.coordination.OperatorInfo)2 TestingOperatorInfo (org.apache.flink.runtime.operators.coordination.TestingOperatorInfo)2 SharedStateRegistryKey (org.apache.flink.runtime.state.SharedStateRegistryKey)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Arrays.asList (java.util.Arrays.asList)1 Collections (java.util.Collections)1 Collections.emptyList (java.util.Collections.emptyList)1 List (java.util.List)1 ExecutorService (java.util.concurrent.ExecutorService)1 Executors (java.util.concurrent.Executors)1