Search in sources :

Example 1 with ZooKeeperLeaderRetrievalDriverFactory

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

the class ZooKeeperMultipleComponentLeaderElectionDriverTest method testPublishEmptyLeaderInformation.

@Test
public void testPublishEmptyLeaderInformation() throws Exception {
    new Context() {

        {
            runTest(() -> {
                leaderElectionListener.await(LeaderElectionEvent.IsLeaderEvent.class);
                final String componentId = "retrieved-component";
                final DefaultLeaderRetrievalService defaultLeaderRetrievalService = new DefaultLeaderRetrievalService(new ZooKeeperLeaderRetrievalDriverFactory(curatorFramework.asCuratorFramework(), componentId, ZooKeeperLeaderRetrievalDriver.LeaderInformationClearancePolicy.ON_LOST_CONNECTION));
                final TestingListener leaderRetrievalListener = new TestingListener();
                defaultLeaderRetrievalService.start(leaderRetrievalListener);
                leaderElectionDriver.publishLeaderInformation(componentId, LeaderInformation.known(UUID.randomUUID(), "foobar"));
                leaderRetrievalListener.waitForNewLeader(10_000L);
                leaderElectionDriver.publishLeaderInformation(componentId, LeaderInformation.empty());
                leaderRetrievalListener.waitForEmptyLeaderInformation(10_000L);
                assertThat(leaderRetrievalListener.getLeader()).isEqualTo(LeaderInformation.empty());
            });
        }
    };
}
Also used : ZooKeeperLeaderRetrievalDriverFactory(org.apache.flink.runtime.leaderretrieval.ZooKeeperLeaderRetrievalDriverFactory) DefaultLeaderRetrievalService(org.apache.flink.runtime.leaderretrieval.DefaultLeaderRetrievalService) Test(org.junit.jupiter.api.Test)

Example 2 with ZooKeeperLeaderRetrievalDriverFactory

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

the class ZooKeeperMultipleComponentLeaderElectionDriverTest method testPublishLeaderInformation.

@Test
public void testPublishLeaderInformation() throws Exception {
    new Context() {

        {
            runTest(() -> {
                leaderElectionListener.await(LeaderElectionEvent.IsLeaderEvent.class);
                final String componentId = "retrieved-component";
                final DefaultLeaderRetrievalService defaultLeaderRetrievalService = new DefaultLeaderRetrievalService(new ZooKeeperLeaderRetrievalDriverFactory(curatorFramework.asCuratorFramework(), componentId, ZooKeeperLeaderRetrievalDriver.LeaderInformationClearancePolicy.ON_LOST_CONNECTION));
                final TestingListener leaderRetrievalListener = new TestingListener();
                defaultLeaderRetrievalService.start(leaderRetrievalListener);
                final LeaderInformation leaderInformation = LeaderInformation.known(UUID.randomUUID(), "foobar");
                leaderElectionDriver.publishLeaderInformation(componentId, leaderInformation);
                leaderRetrievalListener.waitForNewLeader(10_000L);
                assertThat(leaderRetrievalListener.getLeader()).isEqualTo(leaderInformation);
            });
        }
    };
}
Also used : ZooKeeperLeaderRetrievalDriverFactory(org.apache.flink.runtime.leaderretrieval.ZooKeeperLeaderRetrievalDriverFactory) DefaultLeaderRetrievalService(org.apache.flink.runtime.leaderretrieval.DefaultLeaderRetrievalService) Test(org.junit.jupiter.api.Test)

Aggregations

DefaultLeaderRetrievalService (org.apache.flink.runtime.leaderretrieval.DefaultLeaderRetrievalService)2 ZooKeeperLeaderRetrievalDriverFactory (org.apache.flink.runtime.leaderretrieval.ZooKeeperLeaderRetrievalDriverFactory)2 Test (org.junit.jupiter.api.Test)2