Search in sources :

Example 1 with SimpleJobConfiguration

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

the class ShardingServiceTest method assertShardingNecessaryWhenMonitorExecutionDisabled.

@Test
public void assertShardingNecessaryWhenMonitorExecutionDisabled() throws Exception {
    when(serverService.getAvailableShardingServers()).thenReturn(Collections.singletonList("mockedIP"));
    when(jobNodeStorage.isJobNodeExisted("leader/sharding/necessary")).thenReturn(true);
    when(leaderElectionService.isLeader()).thenReturn(true);
    when(configService.load(false)).thenReturn(LiteJobConfiguration.newBuilder(new SimpleJobConfiguration(JobCoreConfiguration.newBuilder("test_job", "0/1 * * * * ?", 3).build(), TestSimpleJob.class.getCanonicalName())).monitorExecution(false).jobShardingStrategyClass(AverageAllocationJobShardingStrategy.class.getCanonicalName()).build());
    when(serverService.getAllServers()).thenReturn(Arrays.asList("ip1", "ip2"));
    shardingService.shardingIfNecessary();
    verify(serverService).getAvailableShardingServers();
    verify(jobNodeStorage).isJobNodeExisted("leader/sharding/necessary");
    verify(leaderElectionService).isLeader();
    verify(configService).load(false);
    verify(jobNodeStorage).removeJobNodeIfExisted("servers/ip1/sharding");
    verify(jobNodeStorage).removeJobNodeIfExisted("servers/ip2/sharding");
    verify(jobNodeStorage).fillEphemeralJobNode("leader/sharding/processing", "");
    verify(jobNodeStorage).executeInTransaction(any(TransactionExecutionCallback.class));
}
Also used : AverageAllocationJobShardingStrategy(com.dangdang.ddframe.job.lite.api.strategy.impl.AverageAllocationJobShardingStrategy) SimpleJobConfiguration(com.dangdang.ddframe.job.config.simple.SimpleJobConfiguration) TransactionExecutionCallback(com.dangdang.ddframe.job.lite.internal.storage.TransactionExecutionCallback) Test(org.junit.Test)

Example 2 with SimpleJobConfiguration

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

the class ShardingServiceTest method assertShardingNecessaryWhenMonitorExecutionEnabled.

@Test
public void assertShardingNecessaryWhenMonitorExecutionEnabled() {
    when(serverService.getAvailableShardingServers()).thenReturn(Collections.singletonList("mockedIP"));
    when(jobNodeStorage.isJobNodeExisted("leader/sharding/necessary")).thenReturn(true);
    when(leaderElectionService.isLeader()).thenReturn(true);
    when(configService.load(false)).thenReturn(LiteJobConfiguration.newBuilder(new SimpleJobConfiguration(JobCoreConfiguration.newBuilder("test_job", "0/1 * * * * ?", 3).build(), TestSimpleJob.class.getCanonicalName())).monitorExecution(true).jobShardingStrategyClass(AverageAllocationJobShardingStrategy.class.getCanonicalName()).build());
    when(serverService.getAllServers()).thenReturn(Arrays.asList("ip1", "ip2"));
    when(executionService.hasRunningItems()).thenReturn(true, false);
    shardingService.shardingIfNecessary();
    verify(serverService).getAvailableShardingServers();
    verify(jobNodeStorage).isJobNodeExisted("leader/sharding/necessary");
    verify(leaderElectionService).isLeader();
    verify(configService).load(false);
    verify(executionService, times(2)).hasRunningItems();
    verify(jobNodeStorage).removeJobNodeIfExisted("servers/ip1/sharding");
    verify(jobNodeStorage).removeJobNodeIfExisted("servers/ip2/sharding");
    verify(jobNodeStorage).fillEphemeralJobNode("leader/sharding/processing", "");
    verify(jobNodeStorage).executeInTransaction(any(TransactionExecutionCallback.class));
}
Also used : AverageAllocationJobShardingStrategy(com.dangdang.ddframe.job.lite.api.strategy.impl.AverageAllocationJobShardingStrategy) SimpleJobConfiguration(com.dangdang.ddframe.job.config.simple.SimpleJobConfiguration) TransactionExecutionCallback(com.dangdang.ddframe.job.lite.internal.storage.TransactionExecutionCallback) Test(org.junit.Test)

Example 3 with SimpleJobConfiguration

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

the class LiteJobConfigurationTest method assertBuildAllProperties.

@Test
public void assertBuildAllProperties() {
    LiteJobConfiguration actual = LiteJobConfiguration.newBuilder(new SimpleJobConfiguration(JobCoreConfiguration.newBuilder("test_job", "0/1 * * * * ?", 3).build(), TestSimpleJob.class.getCanonicalName())).monitorExecution(false).maxTimeDiffSeconds(1000).monitorPort(8888).jobShardingStrategyClass("testClass").disabled(true).overwrite(true).reconcileIntervalMinutes(60).build();
    assertFalse(actual.isMonitorExecution());
    assertThat(actual.getMaxTimeDiffSeconds(), is(1000));
    assertThat(actual.getMonitorPort(), is(8888));
    assertThat(actual.getJobShardingStrategyClass(), is("testClass"));
    assertTrue(actual.isDisabled());
    assertTrue(actual.isOverwrite());
    assertThat(actual.getReconcileIntervalMinutes(), is(60));
}
Also used : SimpleJobConfiguration(com.dangdang.ddframe.job.config.simple.SimpleJobConfiguration) Test(org.junit.Test)

Example 4 with SimpleJobConfiguration

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

the class AbstractBaseStdJobTest method initJobConfig.

private LiteJobConfiguration initJobConfig(final Class<? extends ElasticJob> elasticJobClass) {
    String cron = "0/1 * * * * ?";
    int totalShardingCount = 3;
    String shardingParameters = "0=A,1=B,2=C";
    JobCoreConfiguration jobCoreConfig = JobCoreConfiguration.newBuilder(jobName, cron, totalShardingCount).shardingItemParameters(shardingParameters).jobProperties(JobProperties.JobPropertiesEnum.JOB_EXCEPTION_HANDLER.getKey(), IgnoreJobExceptionHandler.class.getCanonicalName()).build();
    JobTypeConfiguration jobTypeConfig;
    if (DataflowJob.class.isAssignableFrom(elasticJobClass)) {
        jobTypeConfig = new DataflowJobConfiguration(jobCoreConfig, elasticJobClass.getCanonicalName(), false);
    } else if (ScriptJob.class.isAssignableFrom(elasticJobClass)) {
        jobTypeConfig = new ScriptJobConfiguration(jobCoreConfig, AbstractBaseStdJobTest.class.getResource("/script/test.sh").getPath());
    } else {
        jobTypeConfig = new SimpleJobConfiguration(jobCoreConfig, elasticJobClass.getCanonicalName());
    }
    return LiteJobConfiguration.newBuilder(jobTypeConfig).monitorPort(monitorPort).disabled(disabled).overwrite(true).build();
}
Also used : ScriptJob(com.dangdang.ddframe.job.api.script.ScriptJob) JobCoreConfiguration(com.dangdang.ddframe.job.config.JobCoreConfiguration) 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)

Example 5 with SimpleJobConfiguration

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

the class GuaranteeServiceTest method assertIsAllCompleted.

@Test
public void assertIsAllCompleted() {
    when(jobNodeStorage.isJobNodeExisted("guarantee/completed")).thenReturn(true);
    when(configService.load(false)).thenReturn(LiteJobConfiguration.newBuilder(new SimpleJobConfiguration(JobCoreConfiguration.newBuilder("test_job", "0/1 * * * * ?", 3).build(), TestSimpleJob.class.getCanonicalName())).build());
    when(jobNodeStorage.getJobNodeChildrenKeys("guarantee/completed")).thenReturn(Arrays.asList("0", "1", "2"));
    assertTrue(guaranteeService.isAllCompleted());
}
Also used : SimpleJobConfiguration(com.dangdang.ddframe.job.config.simple.SimpleJobConfiguration) 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