Search in sources :

Example 11 with SimpleJobConfiguration

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

the class FailoverListenerManagerTest method assertJobCrashedJobListenerWhenIsRunningItemPathAndRemoveAndItemNotCompletedAndEnableFailoverAndHasNotRunningItems.

@Test
public void assertJobCrashedJobListenerWhenIsRunningItemPathAndRemoveAndItemNotCompletedAndEnableFailoverAndHasNotRunningItems() {
    when(executionService.isCompleted(0)).thenReturn(false);
    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(shardingService.getLocalHostShardingItems()).thenReturn(Arrays.asList(1, 2));
    when(executionService.hasRunningItems(Arrays.asList(1, 2))).thenReturn(false);
    failoverListenerManager.new JobCrashedJobListener().dataChanged(null, new TreeCacheEvent(TreeCacheEvent.Type.NODE_REMOVED, new ChildData("/test_job/execution/0/running", null, "".getBytes())), "/test_job/execution/0/running");
    verify(executionService).isCompleted(0);
    verify(configService).load(true);
    verify(failoverService).setCrashedFailoverFlag(0);
    verify(shardingService).getLocalHostShardingItems();
    verify(executionService).hasRunningItems(Arrays.asList(1, 2));
    verify(failoverService).failoverIfNecessary();
}
Also used : TestSimpleJob(com.dangdang.ddframe.job.lite.fixture.TestSimpleJob) ChildData(org.apache.curator.framework.recipes.cache.ChildData) SimpleJobConfiguration(com.dangdang.ddframe.job.config.simple.SimpleJobConfiguration) TreeCacheEvent(org.apache.curator.framework.recipes.cache.TreeCacheEvent) Test(org.junit.Test)

Example 12 with SimpleJobConfiguration

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

the class FailoverListenerManagerTest method assertJobCrashedJobListenerWhenIsRunningItemPathAndRemoveAndItemNotCompletedButDisableFailover.

@Test
public void assertJobCrashedJobListenerWhenIsRunningItemPathAndRemoveAndItemNotCompletedButDisableFailover() {
    when(executionService.isCompleted(0)).thenReturn(false);
    when(configService.load(true)).thenReturn(LiteJobConfiguration.newBuilder(new SimpleJobConfiguration(JobCoreConfiguration.newBuilder("test_job", "0/1 * * * * ?", 3).failover(false).build(), TestSimpleJob.class.getCanonicalName())).build());
    failoverListenerManager.new JobCrashedJobListener().dataChanged(null, new TreeCacheEvent(TreeCacheEvent.Type.NODE_REMOVED, new ChildData("/test_job/execution/0/running", null, "".getBytes())), "/test_job/execution/0/running");
    verify(executionService).isCompleted(0);
    verify(configService).load(true);
    verify(failoverService, times(0)).setCrashedFailoverFlag(0);
}
Also used : ChildData(org.apache.curator.framework.recipes.cache.ChildData) SimpleJobConfiguration(com.dangdang.ddframe.job.config.simple.SimpleJobConfiguration) TreeCacheEvent(org.apache.curator.framework.recipes.cache.TreeCacheEvent) Test(org.junit.Test)

Example 13 with SimpleJobConfiguration

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

the class FailoverListenerManagerTest method assertJobCrashedJobListenerWhenIsRunningItemPathAndRemoveAndItemNotCompletedAndEnableFailoverButHasRunningItems.

@Test
public void assertJobCrashedJobListenerWhenIsRunningItemPathAndRemoveAndItemNotCompletedAndEnableFailoverButHasRunningItems() {
    when(executionService.isCompleted(0)).thenReturn(false);
    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(shardingService.getLocalHostShardingItems()).thenReturn(Arrays.asList(1, 2));
    when(executionService.hasRunningItems(Arrays.asList(1, 2))).thenReturn(true);
    failoverListenerManager.new JobCrashedJobListener().dataChanged(null, new TreeCacheEvent(TreeCacheEvent.Type.NODE_REMOVED, new ChildData("/test_job/execution/0/running", null, "".getBytes())), "/test_job/execution/0/running");
    verify(executionService).isCompleted(0);
    verify(configService).load(true);
    verify(failoverService).setCrashedFailoverFlag(0);
    verify(shardingService).getLocalHostShardingItems();
    verify(executionService).hasRunningItems(Arrays.asList(1, 2));
    verify(failoverService, times(0)).failoverIfNecessary();
}
Also used : TestSimpleJob(com.dangdang.ddframe.job.lite.fixture.TestSimpleJob) ChildData(org.apache.curator.framework.recipes.cache.ChildData) SimpleJobConfiguration(com.dangdang.ddframe.job.config.simple.SimpleJobConfiguration) TreeCacheEvent(org.apache.curator.framework.recipes.cache.TreeCacheEvent) Test(org.junit.Test)

Example 14 with SimpleJobConfiguration

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

the class JavaMain method setUpSimpleJob.

private static void setUpSimpleJob(final CoordinatorRegistryCenter regCenter, final JobEventConfiguration jobEventConfig) {
    JobCoreConfiguration coreConfig = JobCoreConfiguration.newBuilder("javaSimpleJob", "0/5 * * * * ?", 3).shardingItemParameters("0=Beijing,1=Shanghai,2=Guangzhou").build();
    SimpleJobConfiguration simpleJobConfig = new SimpleJobConfiguration(coreConfig, JavaSimpleJob.class.getCanonicalName());
    new JobScheduler(regCenter, LiteJobConfiguration.newBuilder(simpleJobConfig).build(), jobEventConfig, new JavaSimpleListener(), new JavaSimpleDistributeListener(1000L, 2000L)).init();
}
Also used : JobScheduler(com.dangdang.ddframe.job.lite.api.JobScheduler) JobCoreConfiguration(com.dangdang.ddframe.job.config.JobCoreConfiguration) SimpleJobConfiguration(com.dangdang.ddframe.job.config.simple.SimpleJobConfiguration) JavaSimpleJob(com.dangdang.ddframe.job.example.job.simple.JavaSimpleJob) JavaSimpleListener(com.dangdang.ddframe.job.example.listener.JavaSimpleListener) JavaSimpleDistributeListener(com.dangdang.ddframe.job.example.listener.JavaSimpleDistributeListener)

Example 15 with SimpleJobConfiguration

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

the class AbstractJobConfigurationGsonTypeAdapter method getJobTypeConfiguration.

private JobTypeConfiguration getJobTypeConfiguration(final JobCoreConfiguration coreConfig, final JobType jobType, final String jobClass, final boolean streamingProcess, final String scriptCommandLine) {
    JobTypeConfiguration result;
    Preconditions.checkNotNull(jobType, "jobType cannot be null.");
    switch(jobType) {
        case SIMPLE:
            Preconditions.checkArgument(!Strings.isNullOrEmpty(jobClass), "jobClass cannot be empty.");
            result = new SimpleJobConfiguration(coreConfig, jobClass);
            break;
        case DATAFLOW:
            Preconditions.checkArgument(!Strings.isNullOrEmpty(jobClass), "jobClass cannot be empty.");
            result = new DataflowJobConfiguration(coreConfig, jobClass, streamingProcess);
            break;
        case SCRIPT:
            result = new ScriptJobConfiguration(coreConfig, scriptCommandLine);
            break;
        default:
            throw new UnsupportedOperationException(jobType.name());
    }
    return result;
}
Also used : SimpleJobConfiguration(com.dangdang.ddframe.job.config.simple.SimpleJobConfiguration) DataflowJobConfiguration(com.dangdang.ddframe.job.config.dataflow.DataflowJobConfiguration) ScriptJobConfiguration(com.dangdang.ddframe.job.config.script.ScriptJobConfiguration) JobTypeConfiguration(com.dangdang.ddframe.job.config.JobTypeConfiguration)

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