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());
});
}
};
}
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);
});
}
};
}
Aggregations