Search in sources :

Example 11 with RetrievableStateHandle

use of org.apache.flink.runtime.state.RetrievableStateHandle 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()));
}
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) Test(org.junit.Test)

Example 12 with RetrievableStateHandle

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

the class ZooKeeperStateHandleStoreTest method testCorruptedData.

/**
 * Tests that the ZooKeeperStateHandleStore can handle corrupted data by releasing and trying to
 * remove the respective ZooKeeper ZNodes.
 */
@Test
public void testCorruptedData() throws Exception {
    final TestingLongStateHandleHelper stateStorage = new TestingLongStateHandleHelper();
    ZooKeeperStateHandleStore<TestingLongStateHandleHelper.LongStateHandle> store = new ZooKeeperStateHandleStore<>(ZOOKEEPER.getClient(), stateStorage);
    final Collection<Long> input = new HashSet<>();
    input.add(1L);
    input.add(2L);
    input.add(3L);
    for (Long aLong : input) {
        store.addAndLock("/" + aLong, new TestingLongStateHandleHelper.LongStateHandle(aLong));
    }
    // corrupt one of the entries
    ZOOKEEPER.getClient().setData().forPath("/" + 2, new byte[2]);
    List<Tuple2<RetrievableStateHandle<TestingLongStateHandleHelper.LongStateHandle>, String>> allEntries = store.getAllAndLock();
    Collection<Long> expected = new HashSet<>(input);
    expected.remove(2L);
    Collection<Long> actual = new HashSet<>(expected.size());
    for (Tuple2<RetrievableStateHandle<TestingLongStateHandleHelper.LongStateHandle>, String> entry : allEntries) {
        actual.add(entry.f0.retrieveState().getValue());
    }
    assertEquals(expected, actual);
}
Also used : TestingLongStateHandleHelper(org.apache.flink.runtime.persistence.TestingLongStateHandleHelper) Tuple2(org.apache.flink.api.java.tuple.Tuple2) RetrievableStateHandle(org.apache.flink.runtime.state.RetrievableStateHandle) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 13 with RetrievableStateHandle

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

the class ZooKeeperStateHandleStoreTest method testGetAll.

/**
 * Tests that all added state is returned.
 */
@Test
public void testGetAll() throws Exception {
    // Setup
    final TestingLongStateHandleHelper stateHandleProvider = new TestingLongStateHandleHelper();
    ZooKeeperStateHandleStore<TestingLongStateHandleHelper.LongStateHandle> store = new ZooKeeperStateHandleStore<>(ZOOKEEPER.getClient(), stateHandleProvider);
    // Config
    final String pathInZooKeeper = "/testGetAll";
    final Set<Long> expected = new HashSet<>();
    expected.add(311222268470898L);
    expected.add(132812888L);
    expected.add(27255442L);
    expected.add(11122233124L);
    // Test
    for (long val : expected) {
        store.addAndLock(pathInZooKeeper + val, new TestingLongStateHandleHelper.LongStateHandle(val));
    }
    for (Tuple2<RetrievableStateHandle<TestingLongStateHandleHelper.LongStateHandle>, String> val : store.getAllAndLock()) {
        assertTrue(expected.remove(val.f0.retrieveState().getValue()));
    }
    assertEquals(0, expected.size());
}
Also used : TestingLongStateHandleHelper(org.apache.flink.runtime.persistence.TestingLongStateHandleHelper) RetrievableStateHandle(org.apache.flink.runtime.state.RetrievableStateHandle) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

RetrievableStateHandle (org.apache.flink.runtime.state.RetrievableStateHandle)13 Test (org.junit.Test)10 List (java.util.List)7 Collection (java.util.Collection)6 Tuple2 (org.apache.flink.api.java.tuple.Tuple2)6 StateHandleStore (org.apache.flink.runtime.persistence.StateHandleStore)6 Collections (java.util.Collections)5 Collectors (java.util.stream.Collectors)5 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 PossibleInconsistentStateException (org.apache.flink.runtime.persistence.PossibleInconsistentStateException)4 RetrievableStateStorageHelper (org.apache.flink.runtime.persistence.RetrievableStateStorageHelper)4 Serializable (java.io.Serializable)3 Arrays (java.util.Arrays)3 Base64 (java.util.Base64)3 HashMap (java.util.HashMap)3 HashSet (java.util.HashSet)3 Map (java.util.Map)3 Optional (java.util.Optional)3 TestLogger (org.apache.flink.util.TestLogger)3