use of org.apache.flink.runtime.persistence.TestingLongStateHandleHelper in project flink by apache.
the class ZooKeeperStateHandleStoreTest method testFailingAddWithPossiblyInconsistentState.
/**
* Tests that the created state handle is not discarded if ZooKeeper create fails with an
* generic exception.
*/
@Test
public void testFailingAddWithPossiblyInconsistentState() throws Exception {
final TestingLongStateHandleHelper stateHandleProvider = new TestingLongStateHandleHelper();
CuratorFramework client = spy(ZOOKEEPER.getClient());
when(client.inTransaction()).thenThrow(new RuntimeException("Expected test Exception."));
ZooKeeperStateHandleStore<TestingLongStateHandleHelper.LongStateHandle> store = new ZooKeeperStateHandleStore<>(client, stateHandleProvider);
// Config
final String pathInZooKeeper = "/testAddDiscardStateHandleAfterFailure";
final long state = 81282227L;
try {
// Test
store.addAndLock(pathInZooKeeper, new TestingLongStateHandleHelper.LongStateHandle(state));
fail("PossibleInconsistentStateException should have been thrown.");
} catch (PossibleInconsistentStateException ignored) {
// PossibleInconsistentStateException expected
}
// State handle created and not discarded
assertEquals(1, TestingLongStateHandleHelper.getGlobalStorageSize());
assertEquals(state, TestingLongStateHandleHelper.getStateHandleValueByIndex(0));
assertEquals(0, TestingLongStateHandleHelper.getDiscardCallCountForStateHandleByIndex(0));
}
use of org.apache.flink.runtime.persistence.TestingLongStateHandleHelper 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());
}
use of org.apache.flink.runtime.persistence.TestingLongStateHandleHelper in project flink by apache.
the class ZooKeeperStateHandleStoreTest method testRemove.
/**
* Tests that state handles are correctly removed.
*/
@Test
public void testRemove() throws Exception {
// Setup
final TestingLongStateHandleHelper stateHandleProvider = new TestingLongStateHandleHelper();
ZooKeeperStateHandleStore<TestingLongStateHandleHelper.LongStateHandle> store = new ZooKeeperStateHandleStore<>(ZOOKEEPER.getClient(), stateHandleProvider);
// Config
final String pathInZooKeeper = "/testRemove";
store.addAndLock(pathInZooKeeper, new TestingLongStateHandleHelper.LongStateHandle(27255442L));
final int numberOfGlobalDiscardCalls = TestingLongStateHandleHelper.getGlobalDiscardCount();
// Test
store.releaseAndTryRemove(pathInZooKeeper);
// Verify discarded
assertEquals(0, ZOOKEEPER.getClient().getChildren().forPath("/").size());
assertEquals(numberOfGlobalDiscardCalls + 1, TestingLongStateHandleHelper.getGlobalDiscardCount());
}
use of org.apache.flink.runtime.persistence.TestingLongStateHandleHelper in project flink by apache.
the class ZooKeeperStateHandleStoreTest method testReplace.
/**
* Tests that a state handle is replaced.
*/
@Test
public void testReplace() throws Exception {
// Setup
final TestingLongStateHandleHelper stateHandleProvider = new TestingLongStateHandleHelper();
ZooKeeperStateHandleStore<TestingLongStateHandleHelper.LongStateHandle> store = new ZooKeeperStateHandleStore<>(ZOOKEEPER.getClient(), stateHandleProvider);
// Config
final String pathInZooKeeper = "/testReplace";
final long initialState = 30968470898L;
final long replaceState = 88383776661L;
// Test
store.addAndLock(pathInZooKeeper, new TestingLongStateHandleHelper.LongStateHandle(initialState));
store.replace(pathInZooKeeper, IntegerResourceVersion.valueOf(0), new TestingLongStateHandleHelper.LongStateHandle(replaceState));
// Verify
// State handles created
assertEquals(2, TestingLongStateHandleHelper.getGlobalStorageSize());
assertEquals(initialState, TestingLongStateHandleHelper.getStateHandleValueByIndex(0));
assertEquals(replaceState, TestingLongStateHandleHelper.getStateHandleValueByIndex(1));
// Path created and is persistent
Stat stat = ZOOKEEPER.getClient().checkExists().forPath(pathInZooKeeper);
assertNotNull(stat);
assertEquals(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(replaceState, actual);
}
use of org.apache.flink.runtime.persistence.TestingLongStateHandleHelper in project flink by apache.
the class ZooKeeperStateHandleStoreTest method testLockCleanupWhenClientTimesOut.
/**
* FLINK-6612
*
* <p>Tests that lock nodes will be released if the client dies.
*/
@Test
public void testLockCleanupWhenClientTimesOut() throws Exception {
final TestingLongStateHandleHelper longStateStorage = new TestingLongStateHandleHelper();
Configuration configuration = new Configuration();
configuration.setString(HighAvailabilityOptions.HA_ZOOKEEPER_QUORUM, ZOOKEEPER.getConnectString());
configuration.setInteger(HighAvailabilityOptions.ZOOKEEPER_SESSION_TIMEOUT, 100);
configuration.setString(HighAvailabilityOptions.HA_ZOOKEEPER_ROOT, "timeout");
try (CuratorFrameworkWithUnhandledErrorListener curatorFrameworkWrapper = ZooKeeperUtils.startCuratorFramework(configuration, NoOpFatalErrorHandler.INSTANCE);
CuratorFrameworkWithUnhandledErrorListener curatorFrameworkWrapper2 = ZooKeeperUtils.startCuratorFramework(configuration, NoOpFatalErrorHandler.INSTANCE)) {
CuratorFramework client = curatorFrameworkWrapper.asCuratorFramework();
CuratorFramework client2 = curatorFrameworkWrapper2.asCuratorFramework();
ZooKeeperStateHandleStore<TestingLongStateHandleHelper.LongStateHandle> zkStore = new ZooKeeperStateHandleStore<>(client, longStateStorage);
final String path = "/state";
zkStore.addAndLock(path, new TestingLongStateHandleHelper.LongStateHandle(42L));
// this should delete all ephemeral nodes
client.close();
Stat stat = client2.checkExists().forPath(path);
// check that our state node still exists
assertNotNull(stat);
Collection<String> children = client2.getChildren().forPath(path);
// check that the lock node has been released
assertEquals(0, children.size());
}
}
Aggregations