Search in sources :

Example 21 with TreeCacheEvent

use of org.apache.flink.shaded.curator5.org.apache.curator.framework.recipes.cache.TreeCacheEvent 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)

Example 22 with TreeCacheEvent

use of org.apache.flink.shaded.curator5.org.apache.curator.framework.recipes.cache.TreeCacheEvent in project elastic-job by dangdangdotcom.

the class FailoverListenerManagerTest method assertJobCrashedJobListenerWhenIsRunningItemPathAndRemoveAndItemNotCompletedButDisableFailover.

@Test
public void assertJobCrashedJobListenerWhenIsRunningItemPathAndRemoveAndItemNotCompletedButDisableFailover() {
    when(executionService.isCompleted(0)).thenReturn(false);
    when(configService.load(true)).thenReturn(LiteJobConfiguration.newBuilder(new SimpleJobConfiguration(JobCoreConfiguration.newBuilder("test_job", "0/1 * * * * ?", 3).failover(false).build(), TestSimpleJob.class.getCanonicalName())).build());
    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, times(0)).setCrashedFailoverFlag(0);
}
Also used : 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)

Example 23 with TreeCacheEvent

use of org.apache.flink.shaded.curator5.org.apache.curator.framework.recipes.cache.TreeCacheEvent in project elastic-job by dangdangdotcom.

the class FailoverListenerManagerTest method assertJobCrashedJobListenerWhenIsRunningItemPathAndRemoveAndItemNotCompletedAndEnableFailoverButHasRunningItems.

@Test
public void assertJobCrashedJobListenerWhenIsRunningItemPathAndRemoveAndItemNotCompletedAndEnableFailoverButHasRunningItems() {
    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(true);
    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, times(0)).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)

Example 24 with TreeCacheEvent

use of org.apache.flink.shaded.curator5.org.apache.curator.framework.recipes.cache.TreeCacheEvent in project elastic-job by dangdangdotcom.

the class GuaranteeListenerManagerTest method assertStartedNodeRemovedJobListenerWhenIsNotStartedNode.

@Test
public void assertStartedNodeRemovedJobListenerWhenIsNotStartedNode() {
    guaranteeListenerManager.new StartedNodeRemovedJobListener().dataChanged(null, new TreeCacheEvent(TreeCacheEvent.Type.NODE_REMOVED, new ChildData("/other_job/guarantee/started", null, "".getBytes())), "/other_job/guarantee/started");
    verify(distributeOnceElasticJobListener, times(0)).notifyWaitingTaskStart();
}
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 TreeCacheEvent

use of org.apache.flink.shaded.curator5.org.apache.curator.framework.recipes.cache.TreeCacheEvent in project elastic-job by dangdangdotcom.

the class CloudJobConfigurationListenerTest method assertChildEventWhenDataIsNull.

@Test
public void assertChildEventWhenDataIsNull() throws Exception {
    cloudJobConfigurationListener.childEvent(null, new TreeCacheEvent(TreeCacheEvent.Type.NODE_ADDED, null));
    verify(producerManager, times(0)).schedule(Matchers.<CloudJobConfiguration>any());
    verify(producerManager, times(0)).reschedule(Matchers.<CloudJobConfiguration>any());
    verify(producerManager, times(0)).unschedule(Matchers.<String>any());
}
Also used : TreeCacheEvent(org.apache.curator.framework.recipes.cache.TreeCacheEvent) Test(org.junit.Test)

Aggregations

TreeCacheEvent (org.apache.curator.framework.recipes.cache.TreeCacheEvent)74 ChildData (org.apache.curator.framework.recipes.cache.ChildData)71 Test (org.junit.Test)69 LeaderElectionJobListener (com.dangdang.ddframe.job.lite.internal.election.ElectionListenerManager.LeaderElectionJobListener)7 SimpleJobConfiguration (com.dangdang.ddframe.job.config.simple.SimpleJobConfiguration)6 JobPausedStatusJobListener (com.dangdang.ddframe.job.lite.internal.server.JobOperationListenerManager.JobPausedStatusJobListener)5 CuratorFramework (org.apache.curator.framework.CuratorFramework)5 TreeCacheListener (org.apache.curator.framework.recipes.cache.TreeCacheListener)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 TreeCache (org.apache.curator.framework.recipes.cache.TreeCache)3 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 TimeDiffIntolerableException (com.vip.saturn.job.exception.TimeDiffIntolerableException)1 SaturnThreadFactory (com.vip.saturn.job.threads.SaturnThreadFactory)1 DataChangedEvent (io.shardingjdbc.orchestration.reg.listener.DataChangedEvent)1 StandardCharsets (java.nio.charset.StandardCharsets)1