Search in sources :

Example 21 with SimpleJobConfiguration

use of com.dangdang.ddframe.job.config.simple.SimpleJobConfiguration in project elastic-job by dangdangdotcom.

the class GuaranteeServiceTest method assertIsAllStarted.

@Test
public void assertIsAllStarted() {
    when(jobNodeStorage.isJobNodeExisted("guarantee/started")).thenReturn(true);
    when(configService.load(false)).thenReturn(LiteJobConfiguration.newBuilder(new SimpleJobConfiguration(JobCoreConfiguration.newBuilder("test_job", "0/1 * * * * ?", 3).build(), TestSimpleJob.class.getCanonicalName())).build());
    when(jobNodeStorage.getJobNodeChildrenKeys("guarantee/started")).thenReturn(Arrays.asList("0", "1", "2"));
    assertTrue(guaranteeService.isAllStarted());
}
Also used : SimpleJobConfiguration(com.dangdang.ddframe.job.config.simple.SimpleJobConfiguration) Test(org.junit.Test)

Example 22 with SimpleJobConfiguration

use of com.dangdang.ddframe.job.config.simple.SimpleJobConfiguration in project elastic-job by dangdangdotcom.

the class JobScheduleControllerTest method assertRescheduleJobSuccess.

@Test
public void assertRescheduleJobSuccess() throws NoSuchFieldException, SchedulerException {
    when(schedulerFacade.loadJobConfiguration()).thenReturn(LiteJobConfiguration.newBuilder(new SimpleJobConfiguration(JobCoreConfiguration.newBuilder("test_job", "0/1 * * * * ?", 3).build(), TestSimpleJob.class.getCanonicalName())).build());
    when(scheduler.getTrigger(TriggerKey.triggerKey("test_job_Trigger"))).thenReturn(new CronTriggerImpl());
    ReflectionUtils.setFieldValue(jobScheduleController, "scheduler", scheduler);
    when(scheduler.isShutdown()).thenReturn(false);
    jobScheduleController.rescheduleJob("0/1 * * * * ?");
    verify(scheduler).rescheduleJob(eq(TriggerKey.triggerKey("test_job_Trigger")), Matchers.<Trigger>any());
}
Also used : SimpleJobConfiguration(com.dangdang.ddframe.job.config.simple.SimpleJobConfiguration) CronTriggerImpl(org.quartz.impl.triggers.CronTriggerImpl) Test(org.junit.Test)

Example 23 with SimpleJobConfiguration

use of com.dangdang.ddframe.job.config.simple.SimpleJobConfiguration in project elastic-job by dangdangdotcom.

the class FailoverListenerManagerTest method assertFailoverJobCrashedJobListenerWhenIsRunningItemPathAndRemoveAndItemNotCompletedButDisableFailover.

@Test
public void assertFailoverJobCrashedJobListenerWhenIsRunningItemPathAndRemoveAndItemNotCompletedButDisableFailover() {
    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 FailoverJobCrashedJobListener().dataChanged(null, new TreeCacheEvent(TreeCacheEvent.Type.NODE_REMOVED, new ChildData("/test_job/execution/0/failover", null, "".getBytes())), "/test_job/execution/0/failover");
    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 24 with SimpleJobConfiguration

use of com.dangdang.ddframe.job.config.simple.SimpleJobConfiguration in project elastic-job by dangdangdotcom.

the class FailoverListenerManagerTest method assertFailoverJobCrashedJobListenerWhenIsRunningItemPathAndRemoveAndItemNotCompletedAndEnableFailoverButHasRunningItems.

@Test
public void assertFailoverJobCrashedJobListenerWhenIsRunningItemPathAndRemoveAndItemNotCompletedAndEnableFailoverButHasRunningItems() {
    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 FailoverJobCrashedJobListener().dataChanged(null, new TreeCacheEvent(TreeCacheEvent.Type.NODE_REMOVED, new ChildData("/test_job/execution/0/failover", null, "".getBytes())), "/test_job/execution/0/failover");
    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 25 with SimpleJobConfiguration

use of com.dangdang.ddframe.job.config.simple.SimpleJobConfiguration in project elastic-job by dangdangdotcom.

the class FailoverListenerManagerTest method assertFailoverJobCrashedJobListenerWhenIsRunningItemPathAndRemoveAndItemNotCompletedAndEnableFailoverAndHasNotRunningItems.

@Test
public void assertFailoverJobCrashedJobListenerWhenIsRunningItemPathAndRemoveAndItemNotCompletedAndEnableFailoverAndHasNotRunningItems() {
    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 FailoverJobCrashedJobListener().dataChanged(null, new TreeCacheEvent(TreeCacheEvent.Type.NODE_REMOVED, new ChildData("/test_job/execution/0/failover", null, "".getBytes())), "/test_job/execution/0/failover");
    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

SimpleJobConfiguration (com.dangdang.ddframe.job.config.simple.SimpleJobConfiguration)31 Test (org.junit.Test)27 TestSimpleJob (com.dangdang.ddframe.job.lite.fixture.TestSimpleJob)9 ShardingContexts (com.dangdang.ddframe.job.executor.ShardingContexts)6 ChildData (org.apache.curator.framework.recipes.cache.ChildData)6 TreeCacheEvent (org.apache.curator.framework.recipes.cache.TreeCacheEvent)6 JobCoreConfiguration (com.dangdang.ddframe.job.config.JobCoreConfiguration)2 JobTypeConfiguration (com.dangdang.ddframe.job.config.JobTypeConfiguration)2 DataflowJobConfiguration (com.dangdang.ddframe.job.config.dataflow.DataflowJobConfiguration)2 ScriptJobConfiguration (com.dangdang.ddframe.job.config.script.ScriptJobConfiguration)2 AverageAllocationJobShardingStrategy (com.dangdang.ddframe.job.lite.api.strategy.impl.AverageAllocationJobShardingStrategy)2 TransactionExecutionCallback (com.dangdang.ddframe.job.lite.internal.storage.TransactionExecutionCallback)2 CronTriggerImpl (org.quartz.impl.triggers.CronTriggerImpl)2 ScriptJob (com.dangdang.ddframe.job.api.script.ScriptJob)1 JavaSimpleJob (com.dangdang.ddframe.job.example.job.simple.JavaSimpleJob)1 JavaSimpleDistributeListener (com.dangdang.ddframe.job.example.listener.JavaSimpleDistributeListener)1 JavaSimpleListener (com.dangdang.ddframe.job.example.listener.JavaSimpleListener)1 JobScheduler (com.dangdang.ddframe.job.lite.api.JobScheduler)1 LiteJobConfiguration (com.dangdang.ddframe.job.lite.config.LiteJobConfiguration)1 JobTriggerListener (com.dangdang.ddframe.job.lite.internal.schedule.JobTriggerListener)1