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