Search in sources :

Example 1 with ShardingContexts

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

Example 2 with ShardingContexts

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

Example 3 with ShardingContexts

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

Example 4 with ShardingContexts

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

Example 5 with ShardingContexts

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

Aggregations

ShardingContexts (com.dangdang.ddframe.job.executor.ShardingContexts)29 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 ShardingContext (com.dangdang.ddframe.job.api.ShardingContext)1 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 AbstractSpan (org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan)1 Before (org.junit.Before)1