use of org.apache.flink.runtime.persistence.TestingStateHandleStore in project flink by apache.
the class DefaultJobGraphStoreTest method testRecoverJobGraphWhenNotExist.
@Test
public void testRecoverJobGraphWhenNotExist() throws Exception {
final TestingStateHandleStore<JobGraph> stateHandleStore = builder.setGetFunction(ignore -> {
throw new StateHandleStore.NotExistException("Not exist exception.");
}).build();
final JobGraphStore jobGraphStore = createAndStartJobGraphStore(stateHandleStore);
final JobGraph recoveredJobGraph = jobGraphStore.recoverJobGraph(testingJobGraph.getJobID());
assertThat(recoveredJobGraph, is(nullValue()));
}
use of org.apache.flink.runtime.persistence.TestingStateHandleStore in project flink by apache.
the class DefaultJobGraphStoreTest method testGlobalCleanup.
@Test
public void testGlobalCleanup() throws Exception {
final CompletableFuture<JobID> removeFuture = new CompletableFuture<>();
final TestingStateHandleStore<JobGraph> stateHandleStore = builder.setAddFunction((ignore, state) -> jobGraphStorageHelper.store(state)).setRemoveFunction(name -> removeFuture.complete(JobID.fromHexString(name))).build();
final JobGraphStore jobGraphStore = createAndStartJobGraphStore(stateHandleStore);
jobGraphStore.putJobGraph(testingJobGraph);
jobGraphStore.globalCleanupAsync(testingJobGraph.getJobID(), Executors.directExecutor()).join();
final JobID actual = removeFuture.get(timeout, TimeUnit.MILLISECONDS);
assertThat(actual, is(testingJobGraph.getJobID()));
}
use of org.apache.flink.runtime.persistence.TestingStateHandleStore in project flink by apache.
the class DefaultJobGraphStoreTest method testOnAddedJobGraphShouldOnlyProcessUnknownJobGraphs.
@Test
public void testOnAddedJobGraphShouldOnlyProcessUnknownJobGraphs() throws Exception {
final RetrievableStateHandle<JobGraph> stateHandle = jobGraphStorageHelper.store(testingJobGraph);
final TestingStateHandleStore<JobGraph> stateHandleStore = builder.setGetFunction(ignore -> stateHandle).setAddFunction((ignore, state) -> jobGraphStorageHelper.store(state)).build();
final JobGraphStore jobGraphStore = createAndStartJobGraphStore(stateHandleStore);
jobGraphStore.recoverJobGraph(testingJobGraph.getJobID());
// Known recovered job
testingJobGraphStoreWatcher.addJobGraph(testingJobGraph.getJobID());
// Unknown job
final JobID unknownJobId = JobID.generate();
testingJobGraphStoreWatcher.addJobGraph(unknownJobId);
assertThat(testingJobGraphListener.getAddedJobGraphs().size(), is(1));
assertThat(testingJobGraphListener.getAddedJobGraphs(), contains(unknownJobId));
}
use of org.apache.flink.runtime.persistence.TestingStateHandleStore in project flink by apache.
the class DefaultJobGraphStoreTest method testPutJobGraphWhenNotExist.
@Test
public void testPutJobGraphWhenNotExist() throws Exception {
final CompletableFuture<JobGraph> addFuture = new CompletableFuture<>();
final TestingStateHandleStore<JobGraph> stateHandleStore = builder.setExistsFunction(ignore -> IntegerResourceVersion.notExisting()).setAddFunction((ignore, state) -> {
addFuture.complete(state);
return jobGraphStorageHelper.store(state);
}).build();
final JobGraphStore jobGraphStore = createAndStartJobGraphStore(stateHandleStore);
jobGraphStore.putJobGraph(testingJobGraph);
final JobGraph actual = addFuture.get(timeout, TimeUnit.MILLISECONDS);
assertThat(actual.getJobID(), is(testingJobGraph.getJobID()));
}
use of org.apache.flink.runtime.persistence.TestingStateHandleStore in project flink by apache.
the class DefaultJobGraphStoreTest method testPutJobGraphWhenAlreadyExist.
@Test
public void testPutJobGraphWhenAlreadyExist() throws Exception {
final CompletableFuture<Tuple3<String, IntegerResourceVersion, JobGraph>> replaceFuture = new CompletableFuture<>();
final int resourceVersion = 100;
final AtomicBoolean alreadyExist = new AtomicBoolean(false);
final TestingStateHandleStore<JobGraph> stateHandleStore = builder.setExistsFunction(ignore -> {
if (alreadyExist.get()) {
return IntegerResourceVersion.valueOf(resourceVersion);
} else {
alreadyExist.set(true);
return IntegerResourceVersion.notExisting();
}
}).setAddFunction((ignore, state) -> jobGraphStorageHelper.store(state)).setReplaceConsumer(replaceFuture::complete).build();
final JobGraphStore jobGraphStore = createAndStartJobGraphStore(stateHandleStore);
jobGraphStore.putJobGraph(testingJobGraph);
// Replace
jobGraphStore.putJobGraph(testingJobGraph);
final Tuple3<String, IntegerResourceVersion, JobGraph> actual = replaceFuture.get(timeout, TimeUnit.MILLISECONDS);
assertThat(actual.f0, is(testingJobGraph.getJobID().toString()));
assertThat(actual.f1, is(IntegerResourceVersion.valueOf(resourceVersion)));
assertThat(actual.f2.getJobID(), is(testingJobGraph.getJobID()));
}
Aggregations