Search in sources :

Example 16 with SimpleJobConfiguration

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

the class JobSchedulerTest method mockInit.

private void mockInit(final boolean isMisfire) {
    when(schedulerFacade.newJobTriggerListener()).thenReturn(new JobTriggerListener(null, null));
    when(schedulerFacade.loadJobConfiguration()).thenReturn(LiteJobConfiguration.newBuilder(new SimpleJobConfiguration(JobCoreConfiguration.newBuilder("test_job", "* * 0/10 * * ? 2050", 3).misfire(isMisfire).build(), TestSimpleJob.class.getCanonicalName())).build());
}
Also used : SimpleJobConfiguration(com.dangdang.ddframe.job.config.simple.SimpleJobConfiguration) JobTriggerListener(com.dangdang.ddframe.job.lite.internal.schedule.JobTriggerListener)

Example 17 with SimpleJobConfiguration

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

the class ExecutionServiceTest method assertRegisterJobCompletedWhenNotMonitorExecution.

@Test
public void assertRegisterJobCompletedWhenNotMonitorExecution() {
    when(configService.load(true)).thenReturn(LiteJobConfiguration.newBuilder(new SimpleJobConfiguration(JobCoreConfiguration.newBuilder("test_job", "0/1 * * * * ?", 3).build(), TestSimpleJob.class.getCanonicalName())).monitorExecution(false).build());
    executionService.registerJobCompleted(new ShardingContexts("fake_task_id", "test_job", 10, "", Collections.<Integer, String>emptyMap()));
    verify(configService).load(true);
    verify(serverService, times(0)).updateServerStatus(ServerStatus.READY);
}
Also used : TestSimpleJob(com.dangdang.ddframe.job.lite.fixture.TestSimpleJob) SimpleJobConfiguration(com.dangdang.ddframe.job.config.simple.SimpleJobConfiguration) ShardingContexts(com.dangdang.ddframe.job.executor.ShardingContexts) Test(org.junit.Test)

Example 18 with SimpleJobConfiguration

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

the class ExecutionServiceTest method assertCleanPreviousExecutionInfoWhenNeedFixExecutionInfoForNewValuesLess.

@Test
public void assertCleanPreviousExecutionInfoWhenNeedFixExecutionInfoForNewValuesLess() {
    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 * * * * ?", 2).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("execution/2");
    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 19 with SimpleJobConfiguration

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

the class ExecutionServiceTest method assertRegisterJobBeginWithNextFireTime.

@Test
public void assertRegisterJobBeginWithNextFireTime() {
    when(configService.load(true)).thenReturn(LiteJobConfiguration.newBuilder(new SimpleJobConfiguration(JobCoreConfiguration.newBuilder("test_job", "0/1 * * * * ?", 3).build(), TestSimpleJob.class.getCanonicalName())).monitorExecution(true).build());
    when(jobScheduleController.getNextFireTime()).thenReturn(new Date(0L));
    JobRegistry.getInstance().addJobScheduleController("test_job", jobScheduleController);
    executionService.registerJobBegin(getShardingContext());
    verify(configService).load(true);
    verify(serverService).updateServerStatus(ServerStatus.RUNNING);
    verify(jobNodeStorage).fillEphemeralJobNode("execution/0/running", "");
    verify(jobNodeStorage).fillEphemeralJobNode("execution/1/running", "");
    verify(jobNodeStorage).fillEphemeralJobNode("execution/2/running", "");
    verify(jobNodeStorage).replaceJobNode(eq("execution/0/lastBeginTime"), anyLong());
    verify(jobNodeStorage).replaceJobNode(eq("execution/1/lastBeginTime"), anyLong());
    verify(jobNodeStorage).replaceJobNode(eq("execution/2/lastBeginTime"), anyLong());
    verify(jobNodeStorage).replaceJobNode("execution/0/nextFireTime", 0L);
    verify(jobNodeStorage).replaceJobNode("execution/1/nextFireTime", 0L);
    verify(jobNodeStorage).replaceJobNode("execution/2/nextFireTime", 0L);
}
Also used : TestSimpleJob(com.dangdang.ddframe.job.lite.fixture.TestSimpleJob) SimpleJobConfiguration(com.dangdang.ddframe.job.config.simple.SimpleJobConfiguration) Date(java.util.Date) Test(org.junit.Test)

Example 20 with SimpleJobConfiguration

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

the class LiteJobConfigurationGsonFactoryTest method assertToJsonForSimpleJob.

@Test
public void assertToJsonForSimpleJob() {
    LiteJobConfiguration actual = LiteJobConfiguration.newBuilder(new SimpleJobConfiguration(JobCoreConfiguration.newBuilder("test_job", "0/1 * * * * ?", 3).failover(true).misfire(false).build(), TestSimpleJob.class.getCanonicalName())).monitorExecution(false).maxTimeDiffSeconds(1000).monitorPort(8888).jobShardingStrategyClass("testClass").disabled(true).overwrite(true).reconcileIntervalMinutes(15).build();
    assertThat(LiteJobConfigurationGsonFactory.toJson(actual), is(simpleJobJson));
}
Also used : LiteJobConfiguration(com.dangdang.ddframe.job.lite.config.LiteJobConfiguration) 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