Search in sources :

Example 6 with ShardingContexts

use of com.dangdang.ddframe.job.executor.ShardingContexts in project elastic-job by dangdangdotcom.

the class WrongJobExecutorTest method assertWrongJobExecutorWithMultipleItems.

@Test
public void assertWrongJobExecutorWithMultipleItems() throws NoSuchFieldException {
    Map<Integer, String> map = new HashMap<>(1, 1);
    map.put(0, "A");
    map.put(1, "B");
    ShardingContexts shardingContexts = new ShardingContexts("fake_task_id", "test_job", 10, "", map);
    when(jobFacade.getShardingContexts()).thenReturn(shardingContexts);
    wrongSimpleJobExecutor.execute();
    verify(jobFacade).getShardingContexts();
    verify(jobFacade).postJobStatusTraceEvent("fake_task_id", State.TASK_RUNNING, "");
}
Also used : HashMap(java.util.HashMap) ShardingContexts(com.dangdang.ddframe.job.executor.ShardingContexts) Test(org.junit.Test)

Example 7 with ShardingContexts

use of com.dangdang.ddframe.job.executor.ShardingContexts in project elastic-job by dangdangdotcom.

the class ExecutionContextService method getJobShardingContext.

/**
     * 获取当前作业服务器分片上下文.
     * 
     * @param shardingItems 分片项
     * @return 分片上下文
     */
public ShardingContexts getJobShardingContext(final List<Integer> shardingItems) {
    LiteJobConfiguration liteJobConfig = configService.load(false);
    removeRunningIfMonitorExecution(liteJobConfig.isMonitorExecution(), shardingItems);
    if (shardingItems.isEmpty()) {
        return new ShardingContexts(buildTaskId(liteJobConfig, shardingItems), liteJobConfig.getJobName(), liteJobConfig.getTypeConfig().getCoreConfig().getShardingTotalCount(), liteJobConfig.getTypeConfig().getCoreConfig().getJobParameter(), Collections.<Integer, String>emptyMap());
    }
    Map<Integer, String> shardingItemParameterMap = new ShardingItemParameters(liteJobConfig.getTypeConfig().getCoreConfig().getShardingItemParameters()).getMap();
    return new ShardingContexts(buildTaskId(liteJobConfig, shardingItems), liteJobConfig.getJobName(), liteJobConfig.getTypeConfig().getCoreConfig().getShardingTotalCount(), liteJobConfig.getTypeConfig().getCoreConfig().getJobParameter(), getAssignedShardingItemParameterMap(shardingItems, shardingItemParameterMap));
}
Also used : LiteJobConfiguration(com.dangdang.ddframe.job.lite.config.LiteJobConfiguration) ShardingItemParameters(com.dangdang.ddframe.job.util.config.ShardingItemParameters) ShardingContexts(com.dangdang.ddframe.job.executor.ShardingContexts)

Example 8 with ShardingContexts

use of com.dangdang.ddframe.job.executor.ShardingContexts in project elastic-job by dangdangdotcom.

the class LiteJobFacadeTest method assertAfterJobExecuted.

@Test
public void assertAfterJobExecuted() {
    liteJobFacade.afterJobExecuted(new ShardingContexts("fake_task_id", "test_job", 10, "", Collections.<Integer, String>emptyMap()));
    verify(caller).after();
}
Also used : ShardingContexts(com.dangdang.ddframe.job.executor.ShardingContexts) Test(org.junit.Test)

Example 9 with ShardingContexts

use of com.dangdang.ddframe.job.executor.ShardingContexts in project elastic-job by dangdangdotcom.

the class ExecutionContextServiceTest method assertGetShardingContextWhenNotAssignShardingItem.

@Test
public void assertGetShardingContextWhenNotAssignShardingItem() {
    when(configService.load(false)).thenReturn(LiteJobConfiguration.newBuilder(new DataflowJobConfiguration(JobCoreConfiguration.newBuilder("test_job", "0/1 * * * * ?", 3).build(), TestDataflowJob.class.getCanonicalName(), true)).monitorExecution(false).build());
    ShardingContexts shardingContexts = executionContextService.getJobShardingContext(Collections.<Integer>emptyList());
    assertTrue(shardingContexts.getTaskId().startsWith("test_job@-@@-@READY@-@"));
    assertThat(shardingContexts.getShardingTotalCount(), is(3));
    verify(configService).load(false);
}
Also used : 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 10 with ShardingContexts

use of com.dangdang.ddframe.job.executor.ShardingContexts in project elastic-job by dangdangdotcom.

the class ExecutionServiceTest method assertRegisterJobBeginWhenNotAssignAnyItem.

@Test
public void assertRegisterJobBeginWhenNotAssignAnyItem() {
    executionService.registerJobBegin(new ShardingContexts("fake_task_id", "test_job", 10, "", Collections.<Integer, String>emptyMap()));
    verify(configService, times(0)).load(true);
}
Also used : ShardingContexts(com.dangdang.ddframe.job.executor.ShardingContexts) 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