use of org.apache.flink.runtime.persistence.TestingLongStateHandleHelper in project flink by apache.
the class ZooKeeperStateHandleStoreTest method testAddAndLock.
/**
* Tests add operation with lock.
*/
@Test
public void testAddAndLock() throws Exception {
final TestingLongStateHandleHelper longStateStorage = new TestingLongStateHandleHelper();
ZooKeeperStateHandleStore<TestingLongStateHandleHelper.LongStateHandle> store = new ZooKeeperStateHandleStore<>(ZOOKEEPER.getClient(), longStateStorage);
// Config
final String pathInZooKeeper = "/testAdd";
final long state = 1239712317L;
// Test
store.addAndLock(pathInZooKeeper, new TestingLongStateHandleHelper.LongStateHandle(state));
// Verify
// State handle created
assertEquals(1, store.getAllAndLock().size());
assertEquals(state, store.getAndLock(pathInZooKeeper).retrieveState().getValue());
// Path created and is persistent
Stat stat = ZOOKEEPER.getClient().checkExists().forPath(pathInZooKeeper);
assertNotNull(stat);
assertEquals(0, stat.getEphemeralOwner());
List<String> children = ZOOKEEPER.getClient().getChildren().forPath(pathInZooKeeper);
// there should be one child which is the lock
assertEquals(1, children.size());
stat = ZOOKEEPER.getClient().checkExists().forPath(pathInZooKeeper + '/' + children.get(0));
assertNotNull(stat);
// check that the child is an ephemeral node
assertNotEquals(0, stat.getEphemeralOwner());
// Data is equal
@SuppressWarnings("unchecked") final long actual = ((RetrievableStateHandle<TestingLongStateHandleHelper.LongStateHandle>) InstantiationUtil.deserializeObject(ZOOKEEPER.getClient().getData().forPath(pathInZooKeeper), ClassLoader.getSystemClassLoader())).retrieveState().getValue();
assertEquals(state, actual);
}
use of org.apache.flink.runtime.persistence.TestingLongStateHandleHelper in project flink by apache.
the class ZooKeeperStateHandleStoreTest method testGetAndExists.
/**
* Tests get operation.
*/
@Test
public void testGetAndExists() throws Exception {
// Setup
final TestingLongStateHandleHelper stateHandleProvider = new TestingLongStateHandleHelper();
ZooKeeperStateHandleStore<TestingLongStateHandleHelper.LongStateHandle> store = new ZooKeeperStateHandleStore<>(ZOOKEEPER.getClient(), stateHandleProvider);
// Config
final String pathInZooKeeper = "/testGetAndExists";
final long state = 311222268470898L;
// Test
assertThat(store.exists(pathInZooKeeper).isExisting(), is(false));
store.addAndLock(pathInZooKeeper, new TestingLongStateHandleHelper.LongStateHandle(state));
RetrievableStateHandle<TestingLongStateHandleHelper.LongStateHandle> actual = store.getAndLock(pathInZooKeeper);
// Verify
assertEquals(state, actual.retrieveState().getValue());
assertTrue(store.exists(pathInZooKeeper).getValue() >= 0);
}
use of org.apache.flink.runtime.persistence.TestingLongStateHandleHelper in project flink by apache.
the class ZooKeeperStateHandleStoreTest method testReleaseAndTryRemoveAll.
/**
* Tests that all state handles are correctly discarded.
*/
@Test
public void testReleaseAndTryRemoveAll() throws Exception {
// Setup
final TestingLongStateHandleHelper stateHandleProvider = new TestingLongStateHandleHelper();
ZooKeeperStateHandleStore<TestingLongStateHandleHelper.LongStateHandle> store = new ZooKeeperStateHandleStore<>(ZOOKEEPER.getClient(), stateHandleProvider);
// Config
final String pathInZooKeeper = "/testDiscardAll";
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));
}
store.releaseAndTryRemoveAll();
// Verify all discarded
assertEquals(0, ZOOKEEPER.getClient().getChildren().forPath("/").size());
}
use of org.apache.flink.runtime.persistence.TestingLongStateHandleHelper in project flink by apache.
the class ZooKeeperStateHandleStoreTest method testRemoveAllHandlesShouldRemoveAllPaths.
@Test
public void testRemoveAllHandlesShouldRemoveAllPaths() throws Exception {
final ZooKeeperStateHandleStore<TestingLongStateHandleHelper.LongStateHandle> zkStore = new ZooKeeperStateHandleStore<>(ZooKeeperUtils.useNamespaceAndEnsurePath(ZOOKEEPER.getClient(), "/path"), new TestingLongStateHandleHelper());
zkStore.addAndLock("/state", new TestingLongStateHandleHelper.LongStateHandle(1L));
zkStore.clearEntries();
assertThat(zkStore.getAllHandles(), is(empty()));
}
use of org.apache.flink.runtime.persistence.TestingLongStateHandleHelper 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);
}
Aggregations