Search in sources :

Example 1 with LeaderConnectionInfo

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();
}
Also used : LeaderConnectionInfo(org.apache.flink.runtime.util.LeaderConnectionInfo) DispatcherGateway(org.apache.flink.runtime.dispatcher.DispatcherGateway)

Example 2 with LeaderConnectionInfo

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));
}
Also used : LeaderRetrievalUtils(org.apache.flink.runtime.util.LeaderRetrievalUtils) LeaderConnectionInfo(org.apache.flink.runtime.util.LeaderConnectionInfo) UUID(java.util.UUID)

Example 3 with LeaderConnectionInfo

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));
    }
}
Also used : LeaderConnectionInfo(org.apache.flink.runtime.util.LeaderConnectionInfo) UUID(java.util.UUID) Test(org.junit.Test)

Example 4 with LeaderConnectionInfo

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) {
        }
    }
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) LeaderConnectionInfo(org.apache.flink.runtime.util.LeaderConnectionInfo) UUID(java.util.UUID) TimeoutException(java.util.concurrent.TimeoutException) Test(org.junit.Test)

Example 5 with LeaderConnectionInfo

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();
}
Also used : LeaderConnectionInfo(org.apache.flink.runtime.util.LeaderConnectionInfo) UUID(java.util.UUID) DispatcherGateway(org.apache.flink.runtime.dispatcher.DispatcherGateway)

Aggregations

LeaderConnectionInfo (org.apache.flink.runtime.util.LeaderConnectionInfo)5 UUID (java.util.UUID)4 DispatcherGateway (org.apache.flink.runtime.dispatcher.DispatcherGateway)2 Test (org.junit.Test)2 CompletableFuture (java.util.concurrent.CompletableFuture)1 TimeoutException (java.util.concurrent.TimeoutException)1 LeaderRetrievalUtils (org.apache.flink.runtime.util.LeaderRetrievalUtils)1