Search in sources :

Example 11 with CuratorFrameworkWithUnhandledErrorListener

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();
}
Also used : Configuration(org.apache.flink.configuration.Configuration) CuratorFrameworkWithUnhandledErrorListener(org.apache.flink.runtime.highavailability.zookeeper.CuratorFrameworkWithUnhandledErrorListener) TestCompletedCheckpointStorageLocation(org.apache.flink.runtime.state.testutils.TestCompletedCheckpointStorageLocation) CountDownLatch(java.util.concurrent.CountDownLatch) JobID(org.apache.flink.api.common.JobID) Test(org.junit.Test)

Example 12 with CuratorFrameworkWithUnhandledErrorListener

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();
        }
    }
}
Also used : ZooKeeperLeaderRetrievalDriver(org.apache.flink.runtime.leaderretrieval.ZooKeeperLeaderRetrievalDriver) LeaderRetrievalDriver(org.apache.flink.runtime.leaderretrieval.LeaderRetrievalDriver) NodeCache(org.apache.flink.shaded.curator5.org.apache.curator.framework.recipes.cache.NodeCache) CuratorFrameworkWithUnhandledErrorListener(org.apache.flink.runtime.highavailability.zookeeper.CuratorFrameworkWithUnhandledErrorListener) TestingLeaderRetrievalEventHandler(org.apache.flink.runtime.leaderretrieval.TestingLeaderRetrievalEventHandler) TimeoutException(java.util.concurrent.TimeoutException) Test(org.junit.Test)

Example 13 with CuratorFrameworkWithUnhandledErrorListener

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();
        }
    }
}
Also used : CuratorFramework(org.apache.flink.shaded.curator5.org.apache.curator.framework.CuratorFramework) CreateBuilder(org.apache.flink.shaded.curator5.org.apache.curator.framework.api.CreateBuilder) CuratorFrameworkWithUnhandledErrorListener(org.apache.flink.runtime.highavailability.zookeeper.CuratorFrameworkWithUnhandledErrorListener) Mockito.anyString(org.mockito.Mockito.anyString) TimeoutException(java.util.concurrent.TimeoutException) KeeperException(org.apache.flink.shaded.zookeeper3.org.apache.zookeeper.KeeperException) FlinkRuntimeException(org.apache.flink.util.FlinkRuntimeException) IOException(java.io.IOException) Test(org.junit.Test)

Example 14 with CuratorFrameworkWithUnhandledErrorListener

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();
    }
}
Also used : CuratorFrameworkWithUnhandledErrorListener(org.apache.flink.runtime.highavailability.zookeeper.CuratorFrameworkWithUnhandledErrorListener) Test(org.junit.jupiter.api.Test)

Example 15 with CuratorFrameworkWithUnhandledErrorListener

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;
}
Also used : Configuration(org.apache.flink.configuration.Configuration) CuratorFrameworkWithUnhandledErrorListener(org.apache.flink.runtime.highavailability.zookeeper.CuratorFrameworkWithUnhandledErrorListener) Nonnull(javax.annotation.Nonnull)

Aggregations

CuratorFrameworkWithUnhandledErrorListener (org.apache.flink.runtime.highavailability.zookeeper.CuratorFrameworkWithUnhandledErrorListener)18 Test (org.junit.Test)11 Configuration (org.apache.flink.configuration.Configuration)8 CuratorFramework (org.apache.flink.shaded.curator5.org.apache.curator.framework.CuratorFramework)6 JobID (org.apache.flink.api.common.JobID)3 JobGraph (org.apache.flink.runtime.jobgraph.JobGraph)3 ZooKeeperLeaderRetrievalDriver (org.apache.flink.runtime.leaderretrieval.ZooKeeperLeaderRetrievalDriver)3 KeeperException (org.apache.flink.shaded.zookeeper3.org.apache.zookeeper.KeeperException)3 Mockito.anyString (org.mockito.Mockito.anyString)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 IOException (java.io.IOException)2 ObjectOutputStream (java.io.ObjectOutputStream)2 CompletableFuture (java.util.concurrent.CompletableFuture)2 TimeoutException (java.util.concurrent.TimeoutException)2 Nonnull (javax.annotation.Nonnull)2 CuratorFrameworkFactory (org.apache.flink.shaded.curator5.org.apache.curator.framework.CuratorFrameworkFactory)2 ACLProvider (org.apache.flink.shaded.curator5.org.apache.curator.framework.api.ACLProvider)2 ExponentialBackoffRetry (org.apache.flink.shaded.curator5.org.apache.curator.retry.ExponentialBackoffRetry)2 ACL (org.apache.flink.shaded.zookeeper3.org.apache.zookeeper.data.ACL)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1