Search in sources :

Example 21 with ShardingContexts

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

the class ExecutionServiceTest method assertRegisterJobCompletedWhenNotMonitorExecution.

@Test
public void assertRegisterJobCompletedWhenNotMonitorExecution() {
    when(configService.load(true)).thenReturn(LiteJobConfiguration.newBuilder(new SimpleJobConfiguration(JobCoreConfiguration.newBuilder("test_job", "0/1 * * * * ?", 3).build(), TestSimpleJob.class.getCanonicalName())).monitorExecution(false).build());
    executionService.registerJobCompleted(new ShardingContexts("fake_task_id", "test_job", 10, "", Collections.<Integer, String>emptyMap()));
    verify(configService).load(true);
    verify(serverService, times(0)).updateServerStatus(ServerStatus.READY);
}
Also used : TestSimpleJob(com.dangdang.ddframe.job.lite.fixture.TestSimpleJob) SimpleJobConfiguration(com.dangdang.ddframe.job.config.simple.SimpleJobConfiguration) ShardingContexts(com.dangdang.ddframe.job.executor.ShardingContexts) Test(org.junit.Test)

Example 22 with ShardingContexts

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

the class LiteJobFacadeTest method assertGetShardingContextWhenIsFailoverDisable.

@Test
public void assertGetShardingContextWhenIsFailoverDisable() {
    ShardingContexts shardingContexts = new ShardingContexts("fake_task_id", "test_job", 10, "", Collections.<Integer, String>emptyMap());
    when(configService.load(true)).thenReturn(LiteJobConfiguration.newBuilder(new SimpleJobConfiguration(JobCoreConfiguration.newBuilder("test_job", "0/1 * * * * ?", 3).failover(false).build(), TestSimpleJob.class.getCanonicalName())).build());
    when(shardingService.getLocalHostShardingItems()).thenReturn(Lists.newArrayList(0, 1));
    when(executionContextService.getJobShardingContext(Lists.newArrayList(0, 1))).thenReturn(shardingContexts);
    assertThat(liteJobFacade.getShardingContexts(), is(shardingContexts));
    verify(shardingService).shardingIfNecessary();
}
Also used : SimpleJobConfiguration(com.dangdang.ddframe.job.config.simple.SimpleJobConfiguration) ShardingContexts(com.dangdang.ddframe.job.executor.ShardingContexts) Test(org.junit.Test)

Example 23 with ShardingContexts

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

the class LiteJobFacadeTest method assertGetShardingContextWhenIsFailoverEnableAndFailover.

@Test
public void assertGetShardingContextWhenIsFailoverEnableAndFailover() {
    ShardingContexts shardingContexts = new ShardingContexts("fake_task_id", "test_job", 10, "", Collections.<Integer, String>emptyMap());
    when(configService.load(true)).thenReturn(LiteJobConfiguration.newBuilder(new SimpleJobConfiguration(JobCoreConfiguration.newBuilder("test_job", "0/1 * * * * ?", 3).failover(true).build(), TestSimpleJob.class.getCanonicalName())).monitorExecution(true).build());
    when(failoverService.getLocalHostFailoverItems()).thenReturn(Collections.singletonList(1));
    when(executionContextService.getJobShardingContext(Collections.singletonList(1))).thenReturn(shardingContexts);
    assertThat(liteJobFacade.getShardingContexts(), is(shardingContexts));
    verify(shardingService, times(0)).shardingIfNecessary();
}
Also used : TestSimpleJob(com.dangdang.ddframe.job.lite.fixture.TestSimpleJob) SimpleJobConfiguration(com.dangdang.ddframe.job.config.simple.SimpleJobConfiguration) ShardingContexts(com.dangdang.ddframe.job.executor.ShardingContexts) Test(org.junit.Test)

Example 24 with ShardingContexts

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

the class LiteJobFacadeTest method assertBeforeJobExecuted.

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

Example 25 with ShardingContexts

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

the class LiteJobFacadeTest method assertGetShardingContextWhenIsFailoverEnableAndNotFailover.

@Test
public void assertGetShardingContextWhenIsFailoverEnableAndNotFailover() {
    ShardingContexts shardingContexts = new ShardingContexts("fake_task_id", "test_job", 10, "", Collections.<Integer, String>emptyMap());
    when(configService.load(true)).thenReturn(LiteJobConfiguration.newBuilder(new SimpleJobConfiguration(JobCoreConfiguration.newBuilder("test_job", "0/1 * * * * ?", 3).failover(true).build(), TestSimpleJob.class.getCanonicalName())).monitorExecution(true).build());
    when(failoverService.getLocalHostFailoverItems()).thenReturn(Collections.<Integer>emptyList());
    when(shardingService.getLocalHostShardingItems()).thenReturn(Lists.newArrayList(0, 1));
    when(failoverService.getLocalHostTakeOffItems()).thenReturn(Collections.singletonList(0));
    when(executionContextService.getJobShardingContext(Collections.singletonList(1))).thenReturn(shardingContexts);
    assertThat(liteJobFacade.getShardingContexts(), is(shardingContexts));
    verify(shardingService).shardingIfNecessary();
}
Also used : TestSimpleJob(com.dangdang.ddframe.job.lite.fixture.TestSimpleJob) SimpleJobConfiguration(com.dangdang.ddframe.job.config.simple.SimpleJobConfiguration) 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