Search in sources :

Example 1 with StateHandleStore

use of org.apache.flink.runtime.persistence.StateHandleStore 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()));
}
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) JobGraph(org.apache.flink.runtime.jobgraph.JobGraph) StateHandleStore(org.apache.flink.runtime.persistence.StateHandleStore) TestingStateHandleStore(org.apache.flink.runtime.persistence.TestingStateHandleStore) Test(org.junit.Test)

Example 2 with StateHandleStore

use of org.apache.flink.runtime.persistence.StateHandleStore 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()));
}
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) CompletableFuture(java.util.concurrent.CompletableFuture) JobGraph(org.apache.flink.runtime.jobgraph.JobGraph) JobID(org.apache.flink.api.common.JobID) Test(org.junit.Test)

Example 3 with StateHandleStore

use of org.apache.flink.runtime.persistence.StateHandleStore 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));
}
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) JobGraph(org.apache.flink.runtime.jobgraph.JobGraph) JobID(org.apache.flink.api.common.JobID) Test(org.junit.Test)

Example 4 with StateHandleStore

use of org.apache.flink.runtime.persistence.StateHandleStore 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()));
}
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) JobGraph(org.apache.flink.runtime.jobgraph.JobGraph) CompletableFuture(java.util.concurrent.CompletableFuture) Test(org.junit.Test)

Example 5 with StateHandleStore

use of org.apache.flink.runtime.persistence.StateHandleStore 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

List (java.util.List)9 CompletableFuture (java.util.concurrent.CompletableFuture)9 TimeUnit (java.util.concurrent.TimeUnit)9 TimeoutException (java.util.concurrent.TimeoutException)9 Collectors (java.util.stream.Collectors)9 JobID (org.apache.flink.api.common.JobID)9 FlinkMatchers (org.apache.flink.core.testutils.FlinkMatchers)9 StateHandleStore (org.apache.flink.runtime.persistence.StateHandleStore)9 TestingStateHandleStore (org.apache.flink.runtime.persistence.TestingStateHandleStore)9 RetrievableStateHandle (org.apache.flink.runtime.state.RetrievableStateHandle)9 FlinkException (org.apache.flink.util.FlinkException)9 TestLogger (org.apache.flink.util.TestLogger)9 Matchers.contains (org.hamcrest.Matchers.contains)9 Matchers.is (org.hamcrest.Matchers.is)9 After (org.junit.After)9 Assert.assertThat (org.junit.Assert.assertThat)9 Assert.fail (org.junit.Assert.fail)9 Before (org.junit.Before)9 Test (org.junit.Test)9 Arrays (java.util.Arrays)4