ActiveInstanceElectorService implements Service, LeaderLatchListener { @Override public void notLeader() { LOG.warn("Server instance with server id {} is removed as leader", serverId); serviceState.becomingPassive(); for (ActiveStateChangeHandler handler: activeStateChangeHandlers) { try { handler.instanceIsPassive(); } catch (AtlasException e) { LOG.error("Error while reacting to passive state.", e); } } serviceState.setPassive(); } @Inject  ActiveInstanceElectorService(Configuration configuration,
                                 Set<ActiveStateChangeHandler> activeStateChangeHandlerProviders,
                                 CuratorFactory curatorFactory, ActiveInstanceState activeInstanceState,
                                 ServiceState serviceState); @Override void start(); @Override void stop(); @Override void isLeader(); @Override void notLeader();  }
@Test public void testPassiveStateSetOnLoosingLeadership() { ActiveInstanceElectorService activeInstanceElectorService = new ActiveInstanceElectorService(configuration, new HashSet<ActiveStateChangeHandler>(), curatorFactory, activeInstanceState, serviceState); activeInstanceElectorService.notLeader(); InOrder inOrder = inOrder(serviceState); inOrder.verify(serviceState).becomingPassive(); inOrder.verify(serviceState).setPassive(); }