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));
}
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));
}
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));
}
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();
}
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());
}
Aggregations