Search in sources :

Example 16 with ShardingContexts

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();
}
Also used : ShardingContexts(com.dangdang.ddframe.job.executor.ShardingContexts) Test(org.junit.Test)

Example 17 with ShardingContexts

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);
}
Also used : ShardingContexts(com.dangdang.ddframe.job.executor.ShardingContexts) Test(org.junit.Test)

Example 18 with 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);
}
Also used : TestDistributeOnceElasticJobListener(com.dangdang.ddframe.job.lite.api.listener.fixture.TestDistributeOnceElasticJobListener) HashMap(java.util.HashMap) ShardingContexts(com.dangdang.ddframe.job.executor.ShardingContexts) Before(org.junit.Before)

Example 19 with ShardingContexts

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);
}
Also used : HashMap(java.util.HashMap) ShardingContexts(com.dangdang.ddframe.job.executor.ShardingContexts) DataflowJobConfiguration(com.dangdang.ddframe.job.config.dataflow.DataflowJobConfiguration) TestDataflowJob(com.dangdang.ddframe.job.lite.fixture.TestDataflowJob) Test(org.junit.Test)

Example 20 with ShardingContexts

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");
}
Also used : HashMap(java.util.HashMap) ShardingContexts(com.dangdang.ddframe.job.executor.ShardingContexts) DataflowJobConfiguration(com.dangdang.ddframe.job.config.dataflow.DataflowJobConfiguration) TestDataflowJob(com.dangdang.ddframe.job.lite.fixture.TestDataflowJob) Test(org.junit.Test)

Aggregations

ShardingContexts (com.dangdang.ddframe.job.executor.ShardingContexts)28 Test (org.junit.Test)23 SimpleJobConfiguration (com.dangdang.ddframe.job.config.simple.SimpleJobConfiguration)6 HashMap (java.util.HashMap)6 TestSimpleJob (com.dangdang.ddframe.job.lite.fixture.TestSimpleJob)4 DataflowJobConfiguration (com.dangdang.ddframe.job.config.dataflow.DataflowJobConfiguration)3 TestDataflowJob (com.dangdang.ddframe.job.lite.fixture.TestDataflowJob)3 ShardingItemParameters (com.dangdang.ddframe.job.util.config.ShardingItemParameters)2 ByteString (com.google.protobuf.ByteString)2 CloudAppConfiguration (com.dangdang.ddframe.job.cloud.scheduler.config.app.CloudAppConfiguration)1 CloudJobConfiguration (com.dangdang.ddframe.job.cloud.scheduler.config.job.CloudJobConfiguration)1 TaskContext (com.dangdang.ddframe.job.context.TaskContext)1 TestDistributeOnceElasticJobListener (com.dangdang.ddframe.job.lite.api.listener.fixture.TestDistributeOnceElasticJobListener)1 LiteJobConfiguration (com.dangdang.ddframe.job.lite.config.LiteJobConfiguration)1 LinkedHashMap (java.util.LinkedHashMap)1 Protos (org.apache.mesos.Protos)1 Before (org.junit.Before)1