Search in sources :

Example 6 with SimpleJobConfiguration

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

the class GuaranteeServiceTest method assertIsNotAllCompleted.

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

Example 7 with SimpleJobConfiguration

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

the class JobScheduleControllerTest method assertRescheduleJobFailure.

@Test(expected = JobSystemException.class)
public void assertRescheduleJobFailure() 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());
    doThrow(SchedulerException.class).when(scheduler).rescheduleJob(eq(TriggerKey.triggerKey("test_job_Trigger")), Matchers.<Trigger>any());
    ReflectionUtils.setFieldValue(jobScheduleController, "scheduler", scheduler);
    try {
        jobScheduleController.rescheduleJob("0/1 * * * * ?");
    } finally {
        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 8 with SimpleJobConfiguration

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

the class JobScheduleControllerTest method assertRescheduleJobWhenTriggerIsNull.

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

Example 9 with SimpleJobConfiguration

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

the class ExecutionServiceTest method assertCleanPreviousExecutionInfoWhenNeedFixExecutionInfoForNewValuesEqual.

@Test
public void assertCleanPreviousExecutionInfoWhenNeedFixExecutionInfoForNewValuesEqual() {
    when(jobNodeStorage.isJobNodeExisted("execution")).thenReturn(true);
    when(leaderElectionService.isLeader()).thenReturn(true);
    when(jobNodeStorage.getJobNodeChildrenKeys("execution")).thenReturn(Arrays.asList("0", "1", "2"));
    when(jobNodeStorage.isJobNodeExisted("leader/execution/necessary")).thenReturn(true);
    when(configService.load(false)).thenReturn(LiteJobConfiguration.newBuilder(new SimpleJobConfiguration(JobCoreConfiguration.newBuilder("test_job", "0/1 * * * * ?", 3).build(), TestSimpleJob.class.getCanonicalName())).build());
    executionService.cleanPreviousExecutionInfo();
    verify(jobNodeStorage).isJobNodeExisted("execution");
    verify(leaderElectionService).isLeader();
    verify(jobNodeStorage).fillEphemeralJobNode("leader/execution/cleaning", "");
    verify(jobNodeStorage).getJobNodeChildrenKeys("execution");
    verify(jobNodeStorage).removeJobNodeIfExisted("execution/0/completed");
    verify(jobNodeStorage).removeJobNodeIfExisted("execution/1/completed");
    verify(jobNodeStorage).removeJobNodeIfExisted("execution/2/completed");
    verify(jobNodeStorage).isJobNodeExisted("leader/execution/necessary");
    verify(configService).load(false);
    verify(jobNodeStorage).removeJobNodeIfExisted("leader/execution/necessary");
    verify(jobNodeStorage).removeJobNodeIfExisted("leader/execution/cleaning");
    verify(jobNodeStorage).isJobNodeExisted("leader/execution/cleaning");
}
Also used : SimpleJobConfiguration(com.dangdang.ddframe.job.config.simple.SimpleJobConfiguration) Test(org.junit.Test)

Example 10 with SimpleJobConfiguration

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

the class ExecutionServiceTest method assertCleanPreviousExecutionInfoWhenNeedFixExecutionInfoForNewValuesGreater.

@Test
public void assertCleanPreviousExecutionInfoWhenNeedFixExecutionInfoForNewValuesGreater() {
    when(jobNodeStorage.isJobNodeExisted("execution")).thenReturn(true);
    when(leaderElectionService.isLeader()).thenReturn(true);
    when(jobNodeStorage.getJobNodeChildrenKeys("execution")).thenReturn(Arrays.asList("0", "1", "2"));
    when(jobNodeStorage.isJobNodeExisted("leader/execution/necessary")).thenReturn(true);
    when(configService.load(false)).thenReturn(LiteJobConfiguration.newBuilder(new SimpleJobConfiguration(JobCoreConfiguration.newBuilder("test_job", "0/1 * * * * ?", 4).build(), TestSimpleJob.class.getCanonicalName())).build());
    executionService.cleanPreviousExecutionInfo();
    verify(jobNodeStorage).isJobNodeExisted("execution");
    verify(leaderElectionService).isLeader();
    verify(jobNodeStorage).fillEphemeralJobNode("leader/execution/cleaning", "");
    verify(jobNodeStorage).getJobNodeChildrenKeys("execution");
    verify(jobNodeStorage).removeJobNodeIfExisted("execution/0/completed");
    verify(jobNodeStorage).removeJobNodeIfExisted("execution/1/completed");
    verify(jobNodeStorage).removeJobNodeIfExisted("execution/2/completed");
    verify(jobNodeStorage).isJobNodeExisted("leader/execution/necessary");
    verify(configService).load(false);
    verify(jobNodeStorage).createJobNodeIfNeeded("execution/3");
    verify(jobNodeStorage).removeJobNodeIfExisted("leader/execution/necessary");
    verify(jobNodeStorage).removeJobNodeIfExisted("leader/execution/cleaning");
    verify(jobNodeStorage).isJobNodeExisted("leader/execution/cleaning");
}
Also used : SimpleJobConfiguration(com.dangdang.ddframe.job.config.simple.SimpleJobConfiguration) 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