Search in sources :

Example 26 with SimpleJobConfiguration

use of com.dangdang.ddframe.job.config.simple.SimpleJobConfiguration in project elastic-job by dangdangdotcom.

the class LiteJobFacadeTest method assertFailoverIfUnnecessary.

@Test
public void assertFailoverIfUnnecessary() {
    when(configService.load(true)).thenReturn(LiteJobConfiguration.newBuilder(new SimpleJobConfiguration(JobCoreConfiguration.newBuilder("test_job", "0/1 * * * * ?", 3).failover(false).build(), TestSimpleJob.class.getCanonicalName())).build());
    liteJobFacade.failoverIfNecessary();
    verify(failoverService, times(0)).failoverIfNecessary();
}
Also used : SimpleJobConfiguration(com.dangdang.ddframe.job.config.simple.SimpleJobConfiguration) Test(org.junit.Test)

Example 27 with SimpleJobConfiguration

use of com.dangdang.ddframe.job.config.simple.SimpleJobConfiguration 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 28 with SimpleJobConfiguration

use of com.dangdang.ddframe.job.config.simple.SimpleJobConfiguration 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 29 with SimpleJobConfiguration

use of com.dangdang.ddframe.job.config.simple.SimpleJobConfiguration 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)

Example 30 with SimpleJobConfiguration

use of com.dangdang.ddframe.job.config.simple.SimpleJobConfiguration in project elastic-job by dangdangdotcom.

the class LiteJobFacadeTest method assertRegisterJobCompletedWhenFailoverEnabled.

@Test
public void assertRegisterJobCompletedWhenFailoverEnabled() {
    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());
    liteJobFacade.registerJobCompleted(shardingContexts);
    verify(executionService).registerJobCompleted(shardingContexts);
    verify(failoverService).updateFailoverComplete(shardingContexts.getShardingItemParameters().keySet());
}
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

SimpleJobConfiguration (com.dangdang.ddframe.job.config.simple.SimpleJobConfiguration)31 Test (org.junit.Test)27 TestSimpleJob (com.dangdang.ddframe.job.lite.fixture.TestSimpleJob)9 ShardingContexts (com.dangdang.ddframe.job.executor.ShardingContexts)6 ChildData (org.apache.curator.framework.recipes.cache.ChildData)6 TreeCacheEvent (org.apache.curator.framework.recipes.cache.TreeCacheEvent)6 JobCoreConfiguration (com.dangdang.ddframe.job.config.JobCoreConfiguration)2 JobTypeConfiguration (com.dangdang.ddframe.job.config.JobTypeConfiguration)2 DataflowJobConfiguration (com.dangdang.ddframe.job.config.dataflow.DataflowJobConfiguration)2 ScriptJobConfiguration (com.dangdang.ddframe.job.config.script.ScriptJobConfiguration)2 AverageAllocationJobShardingStrategy (com.dangdang.ddframe.job.lite.api.strategy.impl.AverageAllocationJobShardingStrategy)2 TransactionExecutionCallback (com.dangdang.ddframe.job.lite.internal.storage.TransactionExecutionCallback)2 CronTriggerImpl (org.quartz.impl.triggers.CronTriggerImpl)2 ScriptJob (com.dangdang.ddframe.job.api.script.ScriptJob)1 JavaSimpleJob (com.dangdang.ddframe.job.example.job.simple.JavaSimpleJob)1 JavaSimpleDistributeListener (com.dangdang.ddframe.job.example.listener.JavaSimpleDistributeListener)1 JavaSimpleListener (com.dangdang.ddframe.job.example.listener.JavaSimpleListener)1 JobScheduler (com.dangdang.ddframe.job.lite.api.JobScheduler)1 LiteJobConfiguration (com.dangdang.ddframe.job.lite.config.LiteJobConfiguration)1 JobTriggerListener (com.dangdang.ddframe.job.lite.internal.schedule.JobTriggerListener)1