Search in sources :

Example 6 with LeaderContender

use of org.apache.flink.runtime.leaderelection.LeaderContender in project flink by apache.

the class SingleLeaderElectionServiceTest method testImmediateShutdown.

@Test
public void testImmediateShutdown() throws Exception {
    final UUID uuid = UUID.randomUUID();
    final SingleLeaderElectionService service = new SingleLeaderElectionService(executor, uuid);
    service.shutdown();
    final LeaderContender contender = mock(LeaderContender.class);
    // should not be possible to start
    try {
        service.start(contender);
        fail("should fail with an exception");
    } catch (IllegalStateException e) {
    // expected
    }
    // no additional leadership grant
    verify(contender, times(0)).grantLeadership(any(UUID.class));
}
Also used : LeaderContender(org.apache.flink.runtime.leaderelection.LeaderContender) UUID(java.util.UUID) Test(org.junit.Test)

Example 7 with LeaderContender

use of org.apache.flink.runtime.leaderelection.LeaderContender in project flink by apache.

the class YarnIntraNonHaMasterServicesTest method testClosingReportsToLeader.

@Test
public void testClosingReportsToLeader() throws Exception {
    final Configuration flinkConfig = new Configuration();
    try (YarnHighAvailabilityServices services = new YarnIntraNonHaMasterServices(flinkConfig, hadoopConfig)) {
        final LeaderElectionService elector = services.getResourceManagerLeaderElectionService();
        final LeaderRetrievalService retrieval = services.getResourceManagerLeaderRetriever();
        final LeaderContender contender = mockContender(elector);
        final LeaderRetrievalListener listener = mock(LeaderRetrievalListener.class);
        elector.start(contender);
        retrieval.start(listener);
        // wait until the contender has become the leader
        verify(listener, timeout(1000L).times(1)).notifyLeaderAddress(anyString(), any(UUID.class));
        // now we can close the election service
        services.close();
        verify(contender, timeout(1000L).times(1)).handleError(any(Exception.class));
    }
}
Also used : Configuration(org.apache.flink.configuration.Configuration) LeaderRetrievalService(org.apache.flink.runtime.leaderretrieval.LeaderRetrievalService) LeaderContender(org.apache.flink.runtime.leaderelection.LeaderContender) LeaderElectionService(org.apache.flink.runtime.leaderelection.LeaderElectionService) LeaderRetrievalListener(org.apache.flink.runtime.leaderretrieval.LeaderRetrievalListener) UUID(java.util.UUID) Test(org.junit.Test)

Example 8 with LeaderContender

use of org.apache.flink.runtime.leaderelection.LeaderContender in project flink by apache.

the class YarnIntraNonHaMasterServicesTest method mockContender.

private static LeaderContender mockContender(final LeaderElectionService service, final String address) {
    LeaderContender mockContender = mock(LeaderContender.class);
    when(mockContender.getAddress()).thenReturn(address);
    doAnswer(new Answer<Void>() {

        @Override
        public Void answer(InvocationOnMock invocation) throws Throwable {
            final UUID uuid = (UUID) invocation.getArguments()[0];
            service.confirmLeaderSessionID(uuid);
            return null;
        }
    }).when(mockContender).grantLeadership(any(UUID.class));
    return mockContender;
}
Also used : InvocationOnMock(org.mockito.invocation.InvocationOnMock) LeaderContender(org.apache.flink.runtime.leaderelection.LeaderContender) UUID(java.util.UUID)

Aggregations

UUID (java.util.UUID)8 LeaderContender (org.apache.flink.runtime.leaderelection.LeaderContender)8 Test (org.junit.Test)6 LeaderRetrievalListener (org.apache.flink.runtime.leaderretrieval.LeaderRetrievalListener)2 LeaderRetrievalService (org.apache.flink.runtime.leaderretrieval.LeaderRetrievalService)2 InvocationOnMock (org.mockito.invocation.InvocationOnMock)2 Configuration (org.apache.flink.configuration.Configuration)1 LeaderElectionService (org.apache.flink.runtime.leaderelection.LeaderElectionService)1