use of org.apache.flink.runtime.persistence.StateHandleStore in project flink by apache.
the class DefaultJobGraphStoreTest method testRecoverJobGraph.
@Test
public void testRecoverJobGraph() throws Exception {
final RetrievableStateHandle<JobGraph> stateHandle = jobGraphStorageHelper.store(testingJobGraph);
final TestingStateHandleStore<JobGraph> stateHandleStore = builder.setGetFunction(ignore -> stateHandle).build();
final JobGraphStore jobGraphStore = createAndStartJobGraphStore(stateHandleStore);
final JobGraph recoveredJobGraph = jobGraphStore.recoverJobGraph(testingJobGraph.getJobID());
assertThat(recoveredJobGraph, is(notNullValue()));
assertThat(recoveredJobGraph.getJobID(), is(testingJobGraph.getJobID()));
}
use of org.apache.flink.runtime.persistence.StateHandleStore 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));
}
use of org.apache.flink.runtime.persistence.StateHandleStore in project flink by apache.
the class DefaultCompletedCheckpointStoreTest method testAddCheckpointFailedShouldNotRemoveOldOnes.
@Test
public void testAddCheckpointFailedShouldNotRemoveOldOnes() throws Exception {
final int num = 1;
final String errMsg = "Add to state handle failed.";
final TestingStateHandleStore<CompletedCheckpoint> stateHandleStore = builder.setGetAllSupplier(() -> createStateHandles(num)).setAddFunction((ignore, ckp) -> {
throw new FlinkException(errMsg);
}).build();
final CompletedCheckpointStore completedCheckpointStore = createCompletedCheckpointStore(stateHandleStore);
assertThat(completedCheckpointStore.getAllCheckpoints().size(), is(num));
assertThat(completedCheckpointStore.getAllCheckpoints().get(0).getCheckpointID(), is(1L));
final long ckpId = 100L;
final CompletedCheckpoint ckp = CompletedCheckpointStoreTest.createCheckpoint(ckpId, new SharedStateRegistryImpl());
try {
completedCheckpointStore.addCheckpointAndSubsumeOldestOne(ckp, new CheckpointsCleaner(), () -> {
});
fail("We should get an exception when add checkpoint to failed..");
} catch (FlinkException ex) {
assertThat(ex, FlinkMatchers.containsMessage(errMsg));
}
// Check the old checkpoint still exists.
assertThat(completedCheckpointStore.getAllCheckpoints().size(), is(num));
assertThat(completedCheckpointStore.getAllCheckpoints().get(0).getCheckpointID(), is(1L));
}
use of org.apache.flink.runtime.persistence.StateHandleStore in project flink by apache.
the class DefaultCompletedCheckpointStoreTest method testAddCheckpointSuccessfullyShouldRemoveOldOnes.
@Test
public void testAddCheckpointSuccessfullyShouldRemoveOldOnes() throws Exception {
final int num = 1;
final CompletableFuture<CompletedCheckpoint> addFuture = new CompletableFuture<>();
final TestingStateHandleStore<CompletedCheckpoint> stateHandleStore = builder.setGetAllSupplier(() -> createStateHandles(num)).setAddFunction((ignore, ckp) -> {
addFuture.complete(ckp);
return null;
}).build();
final CompletedCheckpointStore completedCheckpointStore = createCompletedCheckpointStore(stateHandleStore);
assertThat(completedCheckpointStore.getAllCheckpoints().size(), is(num));
assertThat(completedCheckpointStore.getAllCheckpoints().get(0).getCheckpointID(), is(1L));
final long ckpId = 100L;
final CompletedCheckpoint ckp = CompletedCheckpointStoreTest.createCheckpoint(ckpId, new SharedStateRegistryImpl());
completedCheckpointStore.addCheckpointAndSubsumeOldestOne(ckp, new CheckpointsCleaner(), () -> {
});
// We should persist the completed checkpoint to state handle store.
final CompletedCheckpoint addedCkp = addFuture.get(timeout, TimeUnit.MILLISECONDS);
assertThat(addedCkp.getCheckpointID(), is(ckpId));
// Check the old checkpoint is removed and new one is added.
assertThat(completedCheckpointStore.getAllCheckpoints().size(), is(num));
assertThat(completedCheckpointStore.getAllCheckpoints().get(0).getCheckpointID(), is(ckpId));
}
Aggregations