use of com.vip.saturn.job.internal.config.JobConfiguration in project Saturn by vipshop.
the class ForceStopJobIT method test_A.
/**
* 作业STOPPING时立即强制终止
* @throws InterruptedException
*/
@Test
public void test_A() throws InterruptedException {
final int shardCount = 3;
final String jobName = "forceStopITJob";
for (int i = 0; i < shardCount; i++) {
String key = jobName + "_" + i;
LongtimeJavaJob.JobStatus status = new LongtimeJavaJob.JobStatus();
status.runningCount = 0;
status.sleepSeconds = 60;
status.finished = false;
status.killed = false;
status.timeout = false;
LongtimeJavaJob.statusMap.put(key, status);
}
JobConfiguration jobConfiguration = new JobConfiguration(jobName);
jobConfiguration.setCron("0 0 * * * ?");
jobConfiguration.setJobType(JobType.JAVA_JOB.toString());
jobConfiguration.setJobClass(LongtimeJavaJob.class.getCanonicalName());
jobConfiguration.setShardingTotalCount(shardCount);
jobConfiguration.setTimeoutSeconds(0);
jobConfiguration.setShardingItemParameters("0=0,1=1,2=2");
addJob(jobConfiguration);
Thread.sleep(1000);
enableJob(jobConfiguration.getJobName());
Thread.sleep(1000);
runAtOnce(jobName);
Thread.sleep(2000);
disableJob(jobConfiguration.getJobName());
Thread.sleep(1000);
forceStopJob((jobConfiguration.getJobName()));
Thread.sleep(1000);
try {
waitForFinish(new FinishCheck() {
@Override
public boolean docheck() {
Collection<LongtimeJavaJob.JobStatus> values = LongtimeJavaJob.statusMap.values();
for (LongtimeJavaJob.JobStatus status : values) {
if (!status.finished || !status.killed) {
return false;
}
}
return true;
}
}, 30);
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
for (int j = 0; j < shardCount; j++) {
String key = jobName + "_" + j;
LongtimeJavaJob.JobStatus status = LongtimeJavaJob.statusMap.get(key);
assertThat(status.runningCount).isEqualTo(0);
String path = JobNodePath.getNodeFullPath(jobName, ExecutionNode.getCompletedNode(j));
assertThat(regCenter.isExisted(path)).isEqualTo(true);
}
enableJob(jobName);
Thread.sleep(2000);
for (int i = 0; i < shardCount; i++) {
String key = jobName + "_" + i;
LongtimeJavaJob.JobStatus status = new LongtimeJavaJob.JobStatus();
status.runningCount = 0;
status.sleepSeconds = 1;
status.finished = false;
status.killed = false;
status.timeout = false;
LongtimeJavaJob.statusMap.put(key, status);
}
runAtOnce(jobName);
try {
waitForFinish(new FinishCheck() {
@Override
public boolean docheck() {
for (int i = 0; i < shardCount; i++) {
String key = jobName + "_" + i;
LongtimeJavaJob.JobStatus status = LongtimeJavaJob.statusMap.get(key);
if (status.runningCount == 0) {
return false;
}
}
return true;
}
}, 30);
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
disableJob(jobName);
Thread.sleep(1000);
removeJob(jobName);
LongtimeJavaJob.statusMap.clear();
}
use of com.vip.saturn.job.internal.config.JobConfiguration in project Saturn by vipshop.
the class SaturnAutoBasic method initConfigOfshellCronJob.
private static JobConfiguration initConfigOfshellCronJob(String jobName, String cron, int shardCount, String shardingItemParameters) {
JobConfiguration jobCfg = new JobConfiguration(jobName);
jobCfg.setJobType(JobType.SHELL_JOB.toString());
jobCfg.setCron(cron);
// for quickly get statistics
jobCfg.setProcessCountIntervalSeconds(1);
jobCfg.setShardingTotalCount(shardCount);
jobCfg.setShardingItemParameters(shardingItemParameters);
return jobCfg;
}
use of com.vip.saturn.job.internal.config.JobConfiguration in project Saturn by vipshop.
the class SaturnAutoBasic method initConfigOfShellMsgJob.
private static JobConfiguration initConfigOfShellMsgJob(String jobName, String queue, int shardCount, String shardingItemParameters) {
JobConfiguration jobCfg = new JobConfiguration(jobName);
jobCfg.setJobType(JobType.VSHELL.toString());
jobCfg.setQueueName(queue);
// for quickly get statistics
jobCfg.setProcessCountIntervalSeconds(1);
jobCfg.setShardingTotalCount(shardCount);
jobCfg.setShardingItemParameters(shardingItemParameters);
return jobCfg;
}
use of com.vip.saturn.job.internal.config.JobConfiguration in project Saturn by vipshop.
the class SaturnAutoBasic method initConfigOfjavaCronJob.
private static JobConfiguration initConfigOfjavaCronJob(String jobName, String cron, int shardCount, String shardingItemParameters) {
JobConfiguration jobCfg = new JobConfiguration(jobName);
jobCfg.setJobType(JobType.JAVA_JOB.toString());
jobCfg.setCron(cron);
// for quickly get statistics
jobCfg.setProcessCountIntervalSeconds(1);
jobCfg.setShardingTotalCount(shardCount);
jobCfg.setShardingItemParameters(shardingItemParameters);
return jobCfg;
}
use of com.vip.saturn.job.internal.config.JobConfiguration in project Saturn by vipshop.
the class SaturnAutoBasic method configJob.
protected static void configJob(String jobName, String configPath, Object value) {
JobConfiguration jobConfiguration = new JobConfiguration(jobName);
JobNodeStorage jobNodeStorage = new JobNodeStorage(regCenter, jobConfiguration);
jobNodeStorage.fillJobNodeIfNullOrOverwrite(configPath, value);
}
Aggregations