use of com.dangdang.ddframe.job.executor.ShardingContexts in project elastic-job by dangdangdotcom.
the class SimpleJobExecutorTest method assertExecuteWhenPreviousJobStillRunning.
@Test
public void assertExecuteWhenPreviousJobStillRunning() throws JobExecutionEnvironmentException {
ShardingContexts shardingContexts = new ShardingContexts("fake_task_id", "test_job", 10, "", Collections.<Integer, String>emptyMap());
when(jobFacade.getShardingContexts()).thenReturn(shardingContexts);
when(jobFacade.misfireIfNecessary(shardingContexts.getShardingItemParameters().keySet())).thenReturn(true);
simpleJobExecutor.execute();
verify(jobFacade).postJobStatusTraceEvent(shardingContexts.getTaskId(), State.TASK_STAGING, "Job 'test_job' execute begin.");
verify(jobFacade).postJobStatusTraceEvent(shardingContexts.getTaskId(), State.TASK_FINISHED, "Previous job 'test_job' - shardingItems '[]' is still running, misfired job will start after previous job completed.");
verify(jobFacade).checkJobExecutionEnvironment();
verify(jobFacade).getShardingContexts();
verify(jobFacade).misfireIfNecessary(shardingContexts.getShardingItemParameters().keySet());
verify(jobCaller, times(0)).execute();
}
use of com.dangdang.ddframe.job.executor.ShardingContexts in project elastic-job by dangdangdotcom.
the class SimpleJobExecutorTest method assertAfterJobExecutedFailure.
@Test(expected = JobSystemException.class)
public void assertAfterJobExecutedFailure() {
ShardingContexts shardingContexts = ShardingContextsBuilder.getMultipleShardingContexts();
when(jobFacade.getShardingContexts()).thenReturn(shardingContexts);
when(jobFacade.misfireIfNecessary(shardingContexts.getShardingItemParameters().keySet())).thenReturn(false);
when(jobFacade.isExecuteMisfired(shardingContexts.getShardingItemParameters().keySet())).thenReturn(false);
doThrow(RuntimeException.class).when(jobFacade).afterJobExecuted(shardingContexts);
try {
simpleJobExecutor.execute();
} finally {
verify(jobCaller, times(2)).execute();
}
}
use of com.dangdang.ddframe.job.executor.ShardingContexts in project elastic-job by dangdangdotcom.
the class SimpleJobExecutorTest method assertBeforeJobExecutedFailure.
@Test(expected = JobSystemException.class)
public void assertBeforeJobExecutedFailure() {
ShardingContexts shardingContexts = ShardingContextsBuilder.getMultipleShardingContexts();
when(jobFacade.getShardingContexts()).thenReturn(shardingContexts);
when(jobFacade.misfireIfNecessary(shardingContexts.getShardingItemParameters().keySet())).thenReturn(false);
doThrow(RuntimeException.class).when(jobFacade).beforeJobExecuted(shardingContexts);
try {
simpleJobExecutor.execute();
} finally {
verify(jobCaller, times(0)).execute();
}
}
use of com.dangdang.ddframe.job.executor.ShardingContexts in project elastic-job by dangdangdotcom.
the class SimpleJobExecutorTest method assertExecuteWhenRunOnceWithMisfireIsEmpty.
@Test
public void assertExecuteWhenRunOnceWithMisfireIsEmpty() {
ShardingContexts shardingContexts = ShardingContextsBuilder.getMultipleShardingContexts();
when(jobFacade.getShardingContexts()).thenReturn(shardingContexts);
when(jobFacade.isExecuteMisfired(shardingContexts.getShardingItemParameters().keySet())).thenReturn(false);
simpleJobExecutor.execute();
ElasticJobVerify.verifyForIsNotMisfire(jobFacade, shardingContexts);
verify(jobCaller, times(2)).execute();
}
use of com.dangdang.ddframe.job.executor.ShardingContexts in project elastic-job by dangdangdotcom.
the class WrongJobExecutorTest method assertWrongJobExecutorWithSingleItem.
@Test(expected = RuntimeException.class)
public void assertWrongJobExecutorWithSingleItem() throws NoSuchFieldException {
Map<Integer, String> map = new HashMap<>(1, 1);
map.put(0, "A");
ShardingContexts shardingContexts = new ShardingContexts("fake_task_id", "test_job", 10, "", map);
when(jobFacade.getShardingContexts()).thenReturn(shardingContexts);
wrongSimpleJobExecutor.execute();
}
Aggregations