Search in sources :

Example 21 with ChildData

use of org.apache.curator.framework.recipes.cache.ChildData 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 22 with ChildData

use of org.apache.curator.framework.recipes.cache.ChildData 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 23 with ChildData

use of org.apache.curator.framework.recipes.cache.ChildData 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 24 with ChildData

use of org.apache.curator.framework.recipes.cache.ChildData in project elastic-job by dangdangdotcom.

the class FailoverListenerManagerTest method assertJobCrashedJobListenerWhenIsRunningItemPathButNotRemove.

@Test
public void assertJobCrashedJobListenerWhenIsRunningItemPathButNotRemove() {
    failoverListenerManager.new JobCrashedJobListener().dataChanged(null, new TreeCacheEvent(TreeCacheEvent.Type.NODE_ADDED, new ChildData("/test_job/execution/0/running", null, "".getBytes())), "/test_job/execution/0/running");
    verify(failoverService, times(0)).setCrashedFailoverFlag(0);
}
Also used : ChildData(org.apache.curator.framework.recipes.cache.ChildData) TreeCacheEvent(org.apache.curator.framework.recipes.cache.TreeCacheEvent) Test(org.junit.Test)

Example 25 with ChildData

use of org.apache.curator.framework.recipes.cache.ChildData in project elastic-job by dangdangdotcom.

the class FailoverListenerManagerTest method assertJobCrashedJobListenerWhenIsRunningItemPathAndRemoveAndItemNotCompletedAndEnableFailoverAndHasNotRunningItems.

@Test
public void assertJobCrashedJobListenerWhenIsRunningItemPathAndRemoveAndItemNotCompletedAndEnableFailoverAndHasNotRunningItems() {
    when(executionService.isCompleted(0)).thenReturn(false);
    when(configService.load(true)).thenReturn(LiteJobConfiguration.newBuilder(new SimpleJobConfiguration(JobCoreConfiguration.newBuilder("test_job", "0/1 * * * * ?", 3).failover(true).build(), TestSimpleJob.class.getCanonicalName())).monitorExecution(true).build());
    when(shardingService.getLocalHostShardingItems()).thenReturn(Arrays.asList(1, 2));
    when(executionService.hasRunningItems(Arrays.asList(1, 2))).thenReturn(false);
    failoverListenerManager.new JobCrashedJobListener().dataChanged(null, new TreeCacheEvent(TreeCacheEvent.Type.NODE_REMOVED, new ChildData("/test_job/execution/0/running", null, "".getBytes())), "/test_job/execution/0/running");
    verify(executionService).isCompleted(0);
    verify(configService).load(true);
    verify(failoverService).setCrashedFailoverFlag(0);
    verify(shardingService).getLocalHostShardingItems();
    verify(executionService).hasRunningItems(Arrays.asList(1, 2));
    verify(failoverService).failoverIfNecessary();
}
Also used : TestSimpleJob(com.dangdang.ddframe.job.lite.fixture.TestSimpleJob) ChildData(org.apache.curator.framework.recipes.cache.ChildData) SimpleJobConfiguration(com.dangdang.ddframe.job.config.simple.SimpleJobConfiguration) TreeCacheEvent(org.apache.curator.framework.recipes.cache.TreeCacheEvent) Test(org.junit.Test)

Aggregations

ChildData (org.apache.curator.framework.recipes.cache.ChildData)119 Test (org.junit.Test)75 TreeCacheEvent (org.apache.curator.framework.recipes.cache.TreeCacheEvent)70 IOException (java.io.IOException)10 PathChildrenCacheEvent (org.apache.curator.framework.recipes.cache.PathChildrenCacheEvent)9 CuratorFramework (org.apache.curator.framework.CuratorFramework)8 LeaderElectionJobListener (com.dangdang.ddframe.job.lite.internal.election.ElectionListenerManager.LeaderElectionJobListener)7 SimpleJobConfiguration (com.dangdang.ddframe.job.config.simple.SimpleJobConfiguration)6 PathChildrenCache (org.apache.curator.framework.recipes.cache.PathChildrenCache)6 KeeperException (org.apache.zookeeper.KeeperException)6 JobPausedStatusJobListener (com.dangdang.ddframe.job.lite.internal.server.JobOperationListenerManager.JobPausedStatusJobListener)5 PathChildrenCacheListener (org.apache.curator.framework.recipes.cache.PathChildrenCacheListener)5 TreeCache (org.apache.curator.framework.recipes.cache.TreeCache)5 TestSimpleJob (com.dangdang.ddframe.job.lite.fixture.TestSimpleJob)4 CronSettingAndJobEventChangedJobListener (com.dangdang.ddframe.job.lite.internal.config.ConfigurationListenerManager.CronSettingAndJobEventChangedJobListener)4 MonitorExecutionChangedJobListener (com.dangdang.ddframe.job.lite.internal.execution.ExecutionListenerManager.MonitorExecutionChangedJobListener)4 ByteArrayInputStream (java.io.ByteArrayInputStream)4 ServiceDTO (io.fabric8.gateway.ServiceDTO)3 ObjectInputStream (java.io.ObjectInputStream)3 URISyntaxException (java.net.URISyntaxException)3