Search in sources :

Example 1 with ZooKeeperLeaderRetrievalDriver

use of org.apache.flink.runtime.leaderretrieval.ZooKeeperLeaderRetrievalDriver in project flink by apache.

the class ZooKeeperLeaderElectionTest method testNotLeaderShouldNotCleanUpTheLeaderInformation.

@Test
public void testNotLeaderShouldNotCleanUpTheLeaderInformation() throws Exception {
    final TestingLeaderElectionEventHandler electionEventHandler = new TestingLeaderElectionEventHandler(LEADER_ADDRESS);
    final TestingLeaderRetrievalEventHandler retrievalEventHandler = new TestingLeaderRetrievalEventHandler();
    ZooKeeperLeaderElectionDriver leaderElectionDriver = null;
    ZooKeeperLeaderRetrievalDriver leaderRetrievalDriver = null;
    try {
        leaderElectionDriver = createAndInitLeaderElectionDriver(curatorFrameworkWrapper.asCuratorFramework(), electionEventHandler);
        electionEventHandler.waitForLeader(timeout);
        final LeaderInformation confirmedLeaderInformation = electionEventHandler.getConfirmedLeaderInformation();
        assertThat(confirmedLeaderInformation.getLeaderAddress(), is(LEADER_ADDRESS));
        // Leader is revoked
        leaderElectionDriver.notLeader();
        electionEventHandler.waitForRevokeLeader(timeout);
        assertThat(electionEventHandler.getConfirmedLeaderInformation(), is(LeaderInformation.empty()));
        // The data on ZooKeeper it not be cleared
        leaderRetrievalDriver = ZooKeeperUtils.createLeaderRetrievalDriverFactory(curatorFrameworkWrapper.asCuratorFramework()).createLeaderRetrievalDriver(retrievalEventHandler, retrievalEventHandler::handleError);
        retrievalEventHandler.waitForNewLeader(timeout);
        assertThat(retrievalEventHandler.getLeaderSessionID(), is(confirmedLeaderInformation.getLeaderSessionID()));
        assertThat(retrievalEventHandler.getAddress(), is(confirmedLeaderInformation.getLeaderAddress()));
    } finally {
        electionEventHandler.close();
        if (leaderElectionDriver != null) {
            leaderElectionDriver.close();
        }
        if (leaderRetrievalDriver != null) {
            leaderRetrievalDriver.close();
        }
    }
}
Also used : ZooKeeperLeaderRetrievalDriver(org.apache.flink.runtime.leaderretrieval.ZooKeeperLeaderRetrievalDriver) TestingLeaderRetrievalEventHandler(org.apache.flink.runtime.leaderretrieval.TestingLeaderRetrievalEventHandler) Test(org.junit.Test)

Aggregations

TestingLeaderRetrievalEventHandler (org.apache.flink.runtime.leaderretrieval.TestingLeaderRetrievalEventHandler)1 ZooKeeperLeaderRetrievalDriver (org.apache.flink.runtime.leaderretrieval.ZooKeeperLeaderRetrievalDriver)1 Test (org.junit.Test)1