use of org.apache.flink.runtime.util.LeaderConnectionInfo in project flink by apache.
the class DefaultDispatcherRunnerITCase method electLeaderAndRetrieveGateway.
private DispatcherGateway electLeaderAndRetrieveGateway(UUID firstLeaderSessionId) throws InterruptedException, java.util.concurrent.ExecutionException {
dispatcherLeaderElectionService.isLeader(firstLeaderSessionId);
final LeaderConnectionInfo leaderConnectionInfo = dispatcherLeaderElectionService.getConfirmationFuture().get();
return rpcServiceResource.getTestingRpcService().connect(leaderConnectionInfo.getAddress(), DispatcherId.fromUuid(leaderConnectionInfo.getLeaderSessionId()), DispatcherGateway.class).get();
}
use of org.apache.flink.runtime.util.LeaderConnectionInfo in project flink by apache.
the class EmbeddedHaServicesTest method runLeaderRetrievalTest.
private void runLeaderRetrievalTest(LeaderElectionService leaderElectionService, LeaderRetrievalService leaderRetrievalService) throws Exception {
LeaderRetrievalUtils.LeaderConnectionInfoListener leaderRetrievalListener = new LeaderRetrievalUtils.LeaderConnectionInfoListener();
TestingLeaderContender leaderContender = new TestingLeaderContender();
leaderRetrievalService.start(leaderRetrievalListener);
leaderElectionService.start(leaderContender);
final UUID leaderId = leaderContender.getLeaderSessionFuture().get();
leaderElectionService.confirmLeadership(leaderId, ADDRESS);
final LeaderConnectionInfo leaderConnectionInfo = leaderRetrievalListener.getLeaderConnectionInfoFuture().get();
assertThat(leaderConnectionInfo.getAddress(), is(ADDRESS));
assertThat(leaderConnectionInfo.getLeaderSessionId(), is(leaderId));
}
use of org.apache.flink.runtime.util.LeaderConnectionInfo in project flink by apache.
the class DefaultDispatcherRunnerTest method grantLeadership_validLeader_confirmsLeaderSession.
@Test
public void grantLeadership_validLeader_confirmsLeaderSession() throws Exception {
final UUID leaderSessionId = UUID.randomUUID();
try (final DispatcherRunner dispatcherRunner = createDispatcherRunner()) {
testingLeaderElectionService.isLeader(leaderSessionId);
final CompletableFuture<LeaderConnectionInfo> confirmationFuture = testingLeaderElectionService.getConfirmationFuture();
final LeaderConnectionInfo leaderConnectionInfo = confirmationFuture.get();
assertThat(leaderConnectionInfo.getLeaderSessionId(), is(leaderSessionId));
}
}
use of org.apache.flink.runtime.util.LeaderConnectionInfo in project flink by apache.
the class DefaultDispatcherRunnerTest method grantLeadership_oldLeader_doesNotConfirmLeaderSession.
@Test
public void grantLeadership_oldLeader_doesNotConfirmLeaderSession() throws Exception {
final UUID leaderSessionId = UUID.randomUUID();
final CompletableFuture<String> contenderConfirmationFuture = new CompletableFuture<>();
final TestingDispatcherLeaderProcess testingDispatcherLeaderProcess = TestingDispatcherLeaderProcess.newBuilder(leaderSessionId).setConfirmLeaderSessionFuture(contenderConfirmationFuture).build();
testingDispatcherLeaderProcessFactory = TestingDispatcherLeaderProcessFactory.from(testingDispatcherLeaderProcess);
try (final DispatcherRunner dispatcherRunner = createDispatcherRunner()) {
testingLeaderElectionService.isLeader(leaderSessionId);
testingLeaderElectionService.notLeader();
// complete the confirmation future after losing the leadership
contenderConfirmationFuture.complete("leader address");
final CompletableFuture<LeaderConnectionInfo> leaderElectionConfirmationFuture = testingLeaderElectionService.getConfirmationFuture();
try {
leaderElectionConfirmationFuture.get(5L, TimeUnit.MILLISECONDS);
fail("No valid leader should exist.");
} catch (TimeoutException expected) {
}
}
}
use of org.apache.flink.runtime.util.LeaderConnectionInfo in project flink by apache.
the class ZooKeeperDefaultDispatcherRunnerTest method grantLeadership.
private DispatcherGateway grantLeadership(TestingLeaderElectionService dispatcherLeaderElectionService) throws InterruptedException, java.util.concurrent.ExecutionException {
final UUID leaderSessionId = UUID.randomUUID();
dispatcherLeaderElectionService.isLeader(leaderSessionId);
final LeaderConnectionInfo leaderConnectionInfo = dispatcherLeaderElectionService.getConfirmationFuture().get();
return testingRpcServiceResource.getTestingRpcService().connect(leaderConnectionInfo.getAddress(), DispatcherId.fromUuid(leaderSessionId), DispatcherGateway.class).get();
}
Aggregations