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());
}
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);
}
Aggregations