use of org.apache.flink.runtime.highavailability.zookeeper.CuratorFrameworkWithUnhandledErrorListener in project flink by apache.
the class ZooKeeperCompletedCheckpointStoreTest method testAddCheckpointWithFailedRemove.
/**
* Tests that the checkpoint does not exist in the store when we fail to add it into the store
* (i.e., there exists an exception thrown by the method).
*/
@Test
public void testAddCheckpointWithFailedRemove() throws Exception {
final int numCheckpointsToRetain = 1;
final Configuration configuration = new Configuration();
configuration.setString(HighAvailabilityOptions.HA_ZOOKEEPER_QUORUM, zooKeeperResource.getConnectString());
final CuratorFrameworkWithUnhandledErrorListener curatorFrameworkWrapper = ZooKeeperUtils.startCuratorFramework(configuration, NoOpFatalErrorHandler.INSTANCE);
final CompletedCheckpointStore store = createZooKeeperCheckpointStore(curatorFrameworkWrapper.asCuratorFramework());
CountDownLatch discardAttempted = new CountDownLatch(1);
for (long i = 0; i < numCheckpointsToRetain + 1; ++i) {
CompletedCheckpoint checkpointToAdd = new CompletedCheckpoint(new JobID(), i, i, i, Collections.emptyMap(), Collections.emptyList(), CheckpointProperties.forCheckpoint(NEVER_RETAIN_AFTER_TERMINATION), new TestCompletedCheckpointStorageLocation());
// shouldn't fail despite the exception
store.addCheckpointAndSubsumeOldestOne(checkpointToAdd, new CheckpointsCleaner(), () -> {
discardAttempted.countDown();
throw new RuntimeException();
});
}
discardAttempted.await();
}
use of org.apache.flink.runtime.highavailability.zookeeper.CuratorFrameworkWithUnhandledErrorListener in project flink by apache.
the class ZooKeeperLeaderElectionTest method testEphemeralZooKeeperNodes.
/**
* Tests that there is no information left in the ZooKeeper cluster after the ZooKeeper client
* has terminated. In other words, checks that the ZooKeeperLeaderElection service uses
* ephemeral nodes.
*/
@Test
public void testEphemeralZooKeeperNodes() throws Exception {
ZooKeeperLeaderElectionDriver leaderElectionDriver = null;
LeaderRetrievalDriver leaderRetrievalDriver = null;
final TestingLeaderElectionEventHandler electionEventHandler = new TestingLeaderElectionEventHandler(LEADER_ADDRESS);
final TestingLeaderRetrievalEventHandler retrievalEventHandler = new TestingLeaderRetrievalEventHandler();
CuratorFrameworkWithUnhandledErrorListener curatorFrameworkWrapper = null;
CuratorFrameworkWithUnhandledErrorListener curatorFrameworkWrapper2 = null;
NodeCache cache = null;
try {
curatorFrameworkWrapper = ZooKeeperUtils.startCuratorFramework(configuration, testingFatalErrorHandlerResource.getFatalErrorHandler());
curatorFrameworkWrapper2 = ZooKeeperUtils.startCuratorFramework(configuration, testingFatalErrorHandlerResource.getFatalErrorHandler());
leaderElectionDriver = createAndInitLeaderElectionDriver(curatorFrameworkWrapper.asCuratorFramework(), electionEventHandler);
leaderRetrievalDriver = ZooKeeperUtils.createLeaderRetrievalDriverFactory(curatorFrameworkWrapper2.asCuratorFramework()).createLeaderRetrievalDriver(retrievalEventHandler, retrievalEventHandler::handleError);
cache = new NodeCache(curatorFrameworkWrapper2.asCuratorFramework(), leaderElectionDriver.getConnectionInformationPath());
ExistsCacheListener existsListener = new ExistsCacheListener(cache);
DeletedCacheListener deletedCacheListener = new DeletedCacheListener(cache);
cache.getListenable().addListener(existsListener);
cache.start();
electionEventHandler.waitForLeader(timeout);
retrievalEventHandler.waitForNewLeader(timeout);
Future<Boolean> existsFuture = existsListener.nodeExists();
existsFuture.get(timeout, TimeUnit.MILLISECONDS);
cache.getListenable().addListener(deletedCacheListener);
leaderElectionDriver.close();
// now stop the underlying client
curatorFrameworkWrapper.close();
Future<Boolean> deletedFuture = deletedCacheListener.nodeDeleted();
// make sure that the leader node has been deleted
deletedFuture.get(timeout, TimeUnit.MILLISECONDS);
try {
retrievalEventHandler.waitForNewLeader(1000L);
fail("TimeoutException was expected because there is no leader registered and " + "thus there shouldn't be any leader information in ZooKeeper.");
} catch (TimeoutException e) {
// that was expected
}
} finally {
electionEventHandler.close();
if (leaderRetrievalDriver != null) {
leaderRetrievalDriver.close();
}
if (cache != null) {
cache.close();
}
if (curatorFrameworkWrapper2 != null) {
curatorFrameworkWrapper2.close();
}
}
}
use of org.apache.flink.runtime.highavailability.zookeeper.CuratorFrameworkWithUnhandledErrorListener in project flink by apache.
the class ZooKeeperLeaderElectionTest method testExceptionForwarding.
/**
* Test that errors in the {@link LeaderElectionDriver} are correctly forwarded to the {@link
* LeaderContender}.
*/
@Test
public void testExceptionForwarding() throws Exception {
LeaderElectionDriver leaderElectionDriver = null;
final TestingLeaderElectionEventHandler electionEventHandler = new TestingLeaderElectionEventHandler(LEADER_ADDRESS);
CuratorFramework client = null;
final CreateBuilder mockCreateBuilder = mock(CreateBuilder.class, Mockito.RETURNS_DEEP_STUBS);
final String exMsg = "Test exception";
final Exception testException = new Exception(exMsg);
final CuratorFrameworkWithUnhandledErrorListener curatorFrameworkWrapper = ZooKeeperUtils.startCuratorFramework(configuration, NoOpFatalErrorHandler.INSTANCE);
try {
client = spy(curatorFrameworkWrapper.asCuratorFramework());
doAnswer(invocation -> mockCreateBuilder).when(client).create();
when(mockCreateBuilder.creatingParentsIfNeeded().withMode(Matchers.any(CreateMode.class)).forPath(anyString(), any(byte[].class))).thenThrow(testException);
leaderElectionDriver = createAndInitLeaderElectionDriver(client, electionEventHandler);
electionEventHandler.waitForError(timeout);
assertNotNull(electionEventHandler.getError());
assertThat(ExceptionUtils.findThrowableWithMessage(electionEventHandler.getError(), exMsg).isPresent(), is(true));
} finally {
electionEventHandler.close();
if (leaderElectionDriver != null) {
leaderElectionDriver.close();
}
if (curatorFrameworkWrapper != null) {
curatorFrameworkWrapper.close();
}
}
}
use of org.apache.flink.runtime.highavailability.zookeeper.CuratorFrameworkWithUnhandledErrorListener in project flink by apache.
the class ZooKeeperUtilsITCase method testDeleteZNode.
@Test
public void testDeleteZNode() throws Exception {
final CuratorFrameworkWithUnhandledErrorListener curatorFramework = startCuratorFramework();
try {
final String path = "/foobar";
curatorFramework.asCuratorFramework().create().forPath(path, new byte[4]);
curatorFramework.asCuratorFramework().create().forPath(path + "/bar", new byte[4]);
ZooKeeperUtils.deleteZNode(curatorFramework.asCuratorFramework(), path);
assertThat(curatorFramework.asCuratorFramework().getChildren().forPath("/")).isEmpty();
} finally {
curatorFramework.close();
}
}
use of org.apache.flink.runtime.highavailability.zookeeper.CuratorFrameworkWithUnhandledErrorListener in project flink by apache.
the class ZooKeeperUtilsITCase method startCuratorFramework.
@Nonnull
private CuratorFrameworkWithUnhandledErrorListener startCuratorFramework() {
final Configuration configuration = new Configuration();
configuration.set(HighAvailabilityOptions.HA_ZOOKEEPER_QUORUM, zooKeeperExtension.getConnectString());
final CuratorFrameworkWithUnhandledErrorListener curatorFramework = ZooKeeperUtils.startCuratorFramework(configuration, NoOpFatalErrorHandler.INSTANCE);
return curatorFramework;
}
Aggregations