Search in sources :

Example 6 with LeaderElectionJobListener

use of com.dangdang.ddframe.job.lite.internal.election.ElectionListenerManager.LeaderElectionJobListener in project elastic-job by dangdangdotcom.

the class ElectionListenerManagerTest method assertLeaderElectionJobListenerWhenIsLeaderHostPathAndIsRemoveAndIsNotLeaderWithoutAvailableServers.

@Test
public void assertLeaderElectionJobListenerWhenIsLeaderHostPathAndIsRemoveAndIsNotLeaderWithoutAvailableServers() {
    when(leaderElectionService.hasLeader()).thenReturn(false);
    when(serverService.getAvailableServers()).thenReturn(Collections.<String>emptyList());
    electionListenerManager.new LeaderElectionJobListener().dataChanged(null, new TreeCacheEvent(TreeCacheEvent.Type.NODE_REMOVED, new ChildData("/test_job/leader/election/host", null, "localhost".getBytes())), "/test_job/leader/election/host");
    verify(leaderElectionService).hasLeader();
    verify(serverService).getAvailableServers();
    verify(leaderElectionService, times(0)).leaderElection();
}
Also used : ChildData(org.apache.curator.framework.recipes.cache.ChildData) TreeCacheEvent(org.apache.curator.framework.recipes.cache.TreeCacheEvent) LeaderElectionJobListener(com.dangdang.ddframe.job.lite.internal.election.ElectionListenerManager.LeaderElectionJobListener) Test(org.junit.Test)

Example 7 with LeaderElectionJobListener

use of com.dangdang.ddframe.job.lite.internal.election.ElectionListenerManager.LeaderElectionJobListener in project elastic-job by dangdangdotcom.

the class ElectionListenerManagerTest method assertLeaderElectionJobListenerWhenJobDisabledAndIsNotLeader.

@Test
public void assertLeaderElectionJobListenerWhenJobDisabledAndIsNotLeader() {
    when(leaderElectionService.isLeader()).thenReturn(false);
    when(serverNode.isLocalJobPausedPath("/test_job/server/mockedIP/disabled")).thenReturn(true);
    electionListenerManager.new LeaderElectionJobListener().dataChanged(null, new TreeCacheEvent(TreeCacheEvent.Type.NODE_ADDED, new ChildData("/test_job/server/mockedIP/disabled", null, "localhost".getBytes())), "/test_job/server/mockedIP/disabled");
    verify(leaderElectionService, times(0)).removeLeader();
}
Also used : ChildData(org.apache.curator.framework.recipes.cache.ChildData) TreeCacheEvent(org.apache.curator.framework.recipes.cache.TreeCacheEvent) LeaderElectionJobListener(com.dangdang.ddframe.job.lite.internal.election.ElectionListenerManager.LeaderElectionJobListener) Test(org.junit.Test)

Aggregations

LeaderElectionJobListener (com.dangdang.ddframe.job.lite.internal.election.ElectionListenerManager.LeaderElectionJobListener)7 ChildData (org.apache.curator.framework.recipes.cache.ChildData)7 TreeCacheEvent (org.apache.curator.framework.recipes.cache.TreeCacheEvent)7 Test (org.junit.Test)7