Search in sources :

Example 1 with IntegerResourceVersion

use of org.apache.flink.runtime.persistence.IntegerResourceVersion 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()));
}
Also used : FlinkException(org.apache.flink.util.FlinkException) Arrays(java.util.Arrays) Tuple3(org.apache.flink.api.java.tuple.Tuple3) FlinkMatchers(org.apache.flink.core.testutils.FlinkMatchers) JobGraph(org.apache.flink.runtime.jobgraph.JobGraph) TimeoutException(java.util.concurrent.TimeoutException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) CompletableFuture(java.util.concurrent.CompletableFuture) Assert.assertThat(org.junit.Assert.assertThat) After(org.junit.After) Matchers.nullValue(org.hamcrest.Matchers.nullValue) JobGraphTestUtils(org.apache.flink.runtime.jobgraph.JobGraphTestUtils) TestLogger(org.apache.flink.util.TestLogger) StateHandleStore(org.apache.flink.runtime.persistence.StateHandleStore) Assert.fail(org.junit.Assert.fail) Before(org.junit.Before) RetrievableStateHandle(org.apache.flink.runtime.state.RetrievableStateHandle) Matchers.notNullValue(org.hamcrest.Matchers.notNullValue) AbstractID(org.apache.flink.util.AbstractID) Collection(java.util.Collection) Test(org.junit.Test) Collectors(java.util.stream.Collectors) TimeUnit(java.util.concurrent.TimeUnit) Executors(org.apache.flink.util.concurrent.Executors) List(java.util.List) JobID(org.apache.flink.api.common.JobID) TestingRetrievableStateStorageHelper(org.apache.flink.runtime.checkpoint.TestingRetrievableStateStorageHelper) Matchers.contains(org.hamcrest.Matchers.contains) Matchers.is(org.hamcrest.Matchers.is) IntegerResourceVersion(org.apache.flink.runtime.persistence.IntegerResourceVersion) TestingStateHandleStore(org.apache.flink.runtime.persistence.TestingStateHandleStore) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) CompletableFuture(java.util.concurrent.CompletableFuture) JobGraph(org.apache.flink.runtime.jobgraph.JobGraph) Tuple3(org.apache.flink.api.java.tuple.Tuple3) IntegerResourceVersion(org.apache.flink.runtime.persistence.IntegerResourceVersion) Test(org.junit.Test)

Aggregations

Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 List (java.util.List)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 TimeUnit (java.util.concurrent.TimeUnit)1 TimeoutException (java.util.concurrent.TimeoutException)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 Collectors (java.util.stream.Collectors)1 JobID (org.apache.flink.api.common.JobID)1 Tuple3 (org.apache.flink.api.java.tuple.Tuple3)1 FlinkMatchers (org.apache.flink.core.testutils.FlinkMatchers)1 TestingRetrievableStateStorageHelper (org.apache.flink.runtime.checkpoint.TestingRetrievableStateStorageHelper)1 JobGraph (org.apache.flink.runtime.jobgraph.JobGraph)1 JobGraphTestUtils (org.apache.flink.runtime.jobgraph.JobGraphTestUtils)1 IntegerResourceVersion (org.apache.flink.runtime.persistence.IntegerResourceVersion)1 StateHandleStore (org.apache.flink.runtime.persistence.StateHandleStore)1 TestingStateHandleStore (org.apache.flink.runtime.persistence.TestingStateHandleStore)1 RetrievableStateHandle (org.apache.flink.runtime.state.RetrievableStateHandle)1 AbstractID (org.apache.flink.util.AbstractID)1 FlinkException (org.apache.flink.util.FlinkException)1