Search in sources :

Example 21 with TestingLongStateHandleHelper

use of org.apache.flink.runtime.persistence.TestingLongStateHandleHelper in project flink by apache.

the class ZooKeeperStateHandleStoreTest method testAddAndLockExistingNode.

@Test
public void testAddAndLockExistingNode() throws Exception {
    final TestingLongStateHandleHelper stateHandleProvider = new TestingLongStateHandleHelper();
    final CuratorFramework client = ZOOKEEPER.getClient();
    final ZooKeeperStateHandleStore<TestingLongStateHandleHelper.LongStateHandle> store = new ZooKeeperStateHandleStore<>(client, stateHandleProvider);
    final String path = "/test";
    final long firstState = 1337L;
    final long secondState = 7331L;
    store.addAndLock(path, new TestingLongStateHandleHelper.LongStateHandle(firstState));
    assertThrows(StateHandleStore.AlreadyExistException.class, () -> store.addAndLock(path, new TestingLongStateHandleHelper.LongStateHandle(secondState)));
    // There should be only single state handle from the first successful attempt.
    assertEquals(1, TestingLongStateHandleHelper.getGlobalStorageSize());
    assertEquals(firstState, TestingLongStateHandleHelper.getStateHandleValueByIndex(0));
    // No state should have been discarded.
    assertEquals(0, TestingLongStateHandleHelper.getDiscardCallCountForStateHandleByIndex(0));
    // Get state handle from zookeeper.
    assertEquals(firstState, store.getAndLock(path).retrieveState().getValue());
}
Also used : CuratorFramework(org.apache.flink.shaded.curator5.org.apache.curator.framework.CuratorFramework) StateHandleStore(org.apache.flink.runtime.persistence.StateHandleStore) TestingLongStateHandleHelper(org.apache.flink.runtime.persistence.TestingLongStateHandleHelper) Test(org.junit.Test)

Example 22 with TestingLongStateHandleHelper

use of org.apache.flink.runtime.persistence.TestingLongStateHandleHelper in project flink by apache.

the class ZooKeeperStateHandleStoreTest method testRelease.

/**
 * FLINK-6612
 *
 * <p>Tests that we can release a locked state handles in the ZooKeeperStateHandleStore.
 */
@Test
public void testRelease() throws Exception {
    final TestingLongStateHandleHelper longStateStorage = new TestingLongStateHandleHelper();
    ZooKeeperStateHandleStore<TestingLongStateHandleHelper.LongStateHandle> zkStore = new ZooKeeperStateHandleStore<>(ZOOKEEPER.getClient(), longStateStorage);
    final String path = "/state";
    zkStore.addAndLock(path, new TestingLongStateHandleHelper.LongStateHandle(42L));
    final String lockPath = zkStore.getLockPath(path);
    Stat stat = ZOOKEEPER.getClient().checkExists().forPath(lockPath);
    assertNotNull("Expected an existing lock", stat);
    zkStore.release(path);
    stat = ZOOKEEPER.getClient().checkExists().forPath(path);
    // release should have removed the lock child
    assertEquals("Expected no lock nodes as children", 0, stat.getNumChildren());
    zkStore.releaseAndTryRemove(path);
    stat = ZOOKEEPER.getClient().checkExists().forPath(path);
    assertNull("State node should have been removed.", stat);
}
Also used : Stat(org.apache.flink.shaded.zookeeper3.org.apache.zookeeper.data.Stat) TestingLongStateHandleHelper(org.apache.flink.runtime.persistence.TestingLongStateHandleHelper) Test(org.junit.Test)

Aggregations

TestingLongStateHandleHelper (org.apache.flink.runtime.persistence.TestingLongStateHandleHelper)22 Test (org.junit.Test)20 Stat (org.apache.flink.shaded.zookeeper3.org.apache.zookeeper.data.Stat)8 CuratorFramework (org.apache.flink.shaded.curator5.org.apache.curator.framework.CuratorFramework)6 IOException (java.io.IOException)4 HashSet (java.util.HashSet)4 PossibleInconsistentStateException (org.apache.flink.runtime.persistence.PossibleInconsistentStateException)4 Configuration (org.apache.flink.configuration.Configuration)3 RetrievableStateHandle (org.apache.flink.runtime.state.RetrievableStateHandle)3 KeeperException (org.apache.flink.shaded.zookeeper3.org.apache.zookeeper.KeeperException)3 Tuple2 (org.apache.flink.api.java.tuple.Tuple2)2 CuratorFrameworkWithUnhandledErrorListener (org.apache.flink.runtime.highavailability.zookeeper.CuratorFrameworkWithUnhandledErrorListener)2 StateHandleStore (org.apache.flink.runtime.persistence.StateHandleStore)2 TestLogger (org.apache.flink.util.TestLogger)2 Matchers.is (org.hamcrest.Matchers.is)2 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 Comparator (java.util.Comparator)1 List (java.util.List)1