use of com.dangdang.ddframe.job.executor.ShardingContexts in project elastic-job by dangdangdotcom.
the class SimpleJobExecutorTest method assertExecuteWhenShardingItemsIsEmpty.
@Test
public void assertExecuteWhenShardingItemsIsEmpty() throws JobExecutionEnvironmentException {
ShardingContexts shardingContexts = new ShardingContexts("fake_task_id", "test_job", 10, "", Collections.<Integer, String>emptyMap());
ElasticJobVerify.prepareForIsNotMisfire(jobFacade, shardingContexts);
simpleJobExecutor.execute();
verify(jobFacade).postJobStatusTraceEvent(shardingContexts.getTaskId(), State.TASK_STAGING, "Job 'test_job' execute begin.");
verify(jobFacade).postJobStatusTraceEvent(shardingContexts.getTaskId(), State.TASK_FINISHED, "Sharding item for job 'test_job' is empty.");
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 assertExecuteWhenRunOnceWithMisfire.
@Test
public void assertExecuteWhenRunOnceWithMisfire() throws JobExecutionEnvironmentException {
ShardingContexts shardingContexts = ShardingContextsBuilder.getMultipleShardingContexts();
when(jobFacade.getShardingContexts()).thenReturn(shardingContexts);
when(jobFacade.misfireIfNecessary(shardingContexts.getShardingItemParameters().keySet())).thenReturn(false);
when(jobFacade.isExecuteMisfired(shardingContexts.getShardingItemParameters().keySet())).thenReturn(true, false);
when(jobFacade.isNeedSharding()).thenReturn(false);
simpleJobExecutor.execute();
verify(jobFacade).postJobStatusTraceEvent(shardingContexts.getTaskId(), JobStatusTraceEvent.State.TASK_STAGING, "Job 'test_job' execute begin.");
verify(jobFacade, times(2)).postJobStatusTraceEvent(shardingContexts.getTaskId(), JobStatusTraceEvent.State.TASK_RUNNING, "");
verify(jobFacade).checkJobExecutionEnvironment();
verify(jobFacade).getShardingContexts();
verify(jobFacade).misfireIfNecessary(shardingContexts.getShardingItemParameters().keySet());
verify(jobFacade, times(2)).registerJobBegin(shardingContexts);
verify(jobCaller, times(4)).execute();
verify(jobFacade, times(2)).registerJobCompleted(shardingContexts);
}
use of com.dangdang.ddframe.job.executor.ShardingContexts in project elastic-job by dangdangdotcom.
the class DistributeOnceElasticJobListenerTest method setUp.
@Before
public void setUp() throws NoSuchFieldException {
MockitoAnnotations.initMocks(this);
distributeOnceElasticJobListener = new TestDistributeOnceElasticJobListener(elasticJobListenerCaller);
ReflectionUtils.setFieldValue(distributeOnceElasticJobListener, ReflectionUtils.getFieldWithName(AbstractDistributeOnceElasticJobListener.class, "guaranteeService", false), guaranteeService);
ReflectionUtils.setFieldValue(distributeOnceElasticJobListener, ReflectionUtils.getFieldWithName(AbstractDistributeOnceElasticJobListener.class, "timeService", false), timeService);
Map<Integer, String> map = new HashMap<>(2, 1);
map.put(0, "");
map.put(1, "");
shardingContexts = new ShardingContexts("fake_task_id", "test_job", 10, "", map);
}
use of com.dangdang.ddframe.job.executor.ShardingContexts in project elastic-job by dangdangdotcom.
the class ExecutionContextServiceTest method assertGetShardingContextWhenAssignShardingItems.
@Test
public void assertGetShardingContextWhenAssignShardingItems() {
when(configService.load(false)).thenReturn(LiteJobConfiguration.newBuilder(new DataflowJobConfiguration(JobCoreConfiguration.newBuilder("test_job", "0/1 * * * * ?", 3).shardingItemParameters("0=A,1=B,2=C").build(), TestDataflowJob.class.getCanonicalName(), true)).monitorExecution(false).build());
Map<Integer, String> map = new HashMap<>(3);
map.put(0, "A");
map.put(1, "B");
ShardingContexts expected = new ShardingContexts("fake_task_id", "test_job", 3, "", map);
assertShardingContext(executionContextService.getJobShardingContext(Arrays.asList(0, 1)), expected);
verify(configService).load(false);
}
use of com.dangdang.ddframe.job.executor.ShardingContexts in project elastic-job by dangdangdotcom.
the class ExecutionContextServiceTest method assertGetShardingContextWhenHasRunningItems.
@Test
public void assertGetShardingContextWhenHasRunningItems() {
when(configService.load(false)).thenReturn(LiteJobConfiguration.newBuilder(new DataflowJobConfiguration(JobCoreConfiguration.newBuilder("test_job", "0/1 * * * * ?", 3).shardingItemParameters("0=A,1=B,2=C").build(), TestDataflowJob.class.getCanonicalName(), true)).monitorExecution(true).build());
when(jobNodeStorage.isJobNodeExisted("execution/0/running")).thenReturn(false);
when(jobNodeStorage.isJobNodeExisted("execution/1/running")).thenReturn(true);
Map<Integer, String> map = new HashMap<>(1, 1);
map.put(0, "A");
ShardingContexts expected = new ShardingContexts("fake_task_id", "test_job", 3, "", map);
assertShardingContext(executionContextService.getJobShardingContext(Lists.newArrayList(0, 1)), expected);
verify(configService).load(false);
verify(jobNodeStorage).isJobNodeExisted("execution/0/running");
verify(jobNodeStorage).isJobNodeExisted("execution/1/running");
}
Aggregations