Search in sources :

Example 1 with LeaderElectionJobListener

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

the class ElectionListenerManagerTest method assertLeaderElectionJobListenerWhenIsLeaderHostPathAndIsRemoveAndIsLeader.

@Test
public void assertLeaderElectionJobListenerWhenIsLeaderHostPathAndIsRemoveAndIsLeader() {
    when(leaderElectionService.hasLeader()).thenReturn(true);
    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(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 2 with LeaderElectionJobListener

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

the class ElectionListenerManagerTest method assertLeaderElectionJobListenerWhenIsLeaderHostPathAndIsRemoveAndIsNotLeaderWithAvailableServers.

@Test
public void assertLeaderElectionJobListenerWhenIsLeaderHostPathAndIsRemoveAndIsNotLeaderWithAvailableServers() {
    when(leaderElectionService.hasLeader()).thenReturn(false);
    when(serverService.getAvailableServers()).thenReturn(Collections.singletonList("localhost"));
    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).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 3 with LeaderElectionJobListener

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

the class ElectionListenerManagerTest method assertLeaderElectionJobListenerWhenIsNotLeaderHostPath.

@Test
public void assertLeaderElectionJobListenerWhenIsNotLeaderHostPath() {
    electionListenerManager.new LeaderElectionJobListener().dataChanged(null, new TreeCacheEvent(TreeCacheEvent.Type.NODE_ADDED, new ChildData("/test_job/leader/election/other", null, "localhost".getBytes())), "/test_job/leader/election/other");
    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 4 with LeaderElectionJobListener

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

the class ElectionListenerManagerTest method assertLeaderElectionJobListenerWhenIsLeaderHostPathButNotRemove.

@Test
public void assertLeaderElectionJobListenerWhenIsLeaderHostPathButNotRemove() {
    electionListenerManager.new LeaderElectionJobListener().dataChanged(null, new TreeCacheEvent(TreeCacheEvent.Type.NODE_ADDED, new ChildData("/test_job/leader/election/host", null, "localhost".getBytes())), "/test_job/leader/election/host");
    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 5 with LeaderElectionJobListener

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

the class ElectionListenerManagerTest method assertLeaderElectionJobListenerWhenJobShutdownAndIsLeader.

@Test
public void assertLeaderElectionJobListenerWhenJobShutdownAndIsLeader() {
    when(leaderElectionService.isLeader()).thenReturn(true);
    when(serverNode.isLocalJobPausedPath("/test_job/server/mockedIP/shutdown")).thenReturn(true);
    electionListenerManager.new LeaderElectionJobListener().dataChanged(null, new TreeCacheEvent(TreeCacheEvent.Type.NODE_ADDED, new ChildData("/test_job/server/mockedIP/shutdown", null, "localhost".getBytes())), "/test_job/server/mockedIP/shutdown");
    verify(leaderElectionService).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