use of org.apache.flink.runtime.leaderretrieval.LeaderRetrievalListener in project flink by apache.
the class SingleLeaderElectionServiceTest method testShutdown.
@Test
public void testShutdown() throws Exception {
final UUID uuid = UUID.randomUUID();
final SingleLeaderElectionService service = new SingleLeaderElectionService(executor, uuid);
// create a leader contender and let it grab leadership
final LeaderContender contender = mockContender(service);
service.start(contender);
verify(contender, times(1)).grantLeadership(uuid);
// some leader listeners
final LeaderRetrievalListener listener1 = mock(LeaderRetrievalListener.class);
final LeaderRetrievalListener listener2 = mock(LeaderRetrievalListener.class);
LeaderRetrievalService listenerService1 = service.createLeaderRetrievalService();
LeaderRetrievalService listenerService2 = service.createLeaderRetrievalService();
listenerService1.start(listener1);
listenerService2.start(listener2);
// one listener stops
listenerService1.stop();
// shut down the service
service.shutdown();
// the leader contender and running listener should get error notifications
verify(contender, times(1)).handleError(any(Exception.class));
verify(listener2, times(1)).handleError(any(Exception.class));
// the stopped listener gets no notification
verify(listener1, times(0)).handleError(any(Exception.class));
// should not be possible to start again after shutdown
try {
service.start(contender);
fail("should fail with an exception");
} catch (IllegalStateException e) {
// expected
}
// no additional leadership grant
verify(contender, times(1)).grantLeadership(any(UUID.class));
}
use of org.apache.flink.runtime.leaderretrieval.LeaderRetrievalListener in project flink by apache.
the class FlinkResourceManager method preStart.
// ------------------------------------------------------------------------
// Actor Behavior
// ------------------------------------------------------------------------
@Override
public void preStart() {
try {
// we start our leader retrieval service to make sure we get informed
// about JobManager leader changes
leaderRetriever.start(new LeaderRetrievalListener() {
@Override
public void notifyLeaderAddress(String leaderAddress, UUID leaderSessionID) {
self().tell(new NewLeaderAvailable(leaderAddress, leaderSessionID), ActorRef.noSender());
}
@Override
public void handleError(Exception e) {
self().tell(new FatalErrorOccurred("Leader retrieval service failed", e), ActorRef.noSender());
}
});
// framework specific initialization
initialize();
} catch (Throwable t) {
self().tell(new FatalErrorOccurred("Error during startup of ResourceManager actor", t), ActorRef.noSender());
}
}
use of org.apache.flink.runtime.leaderretrieval.LeaderRetrievalListener 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));
}
}
Aggregations