use of com.vip.saturn.job.console.domain.JobConfig in project Saturn by vipshop.
the class ForceStopJobIT method test_A_forceStopITJob.
/**
* 作业STOPPING时立即强制终止
*/
@Test
public void test_A_forceStopITJob() throws Exception {
final int shardCount = 3;
final String jobName = "test_A_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.beforeTimeout = false;
status.timeout = false;
LongtimeJavaJob.statusMap.put(key, status);
}
JobConfig jobConfig = new JobConfig();
jobConfig.setJobName(jobName);
jobConfig.setCron("9 9 9 9 9 ? 2099");
jobConfig.setJobType(JobType.JAVA_JOB.toString());
jobConfig.setJobClass(LongtimeJavaJob.class.getCanonicalName());
jobConfig.setShardingTotalCount(shardCount);
jobConfig.setTimeoutSeconds(0);
jobConfig.setShardingItemParameters("0=0,1=1,2=2");
addJob(jobConfig);
Thread.sleep(1000);
enableJob(jobName);
Thread.sleep(1000);
runAtOnce(jobName);
Thread.sleep(2000);
disableJob(jobName);
Thread.sleep(1000);
forceStopJob(jobName);
Thread.sleep(1000);
try {
waitForFinish(new FinishCheck() {
@Override
public boolean isOk() {
Collection<LongtimeJavaJob.JobStatus> values = LongtimeJavaJob.statusMap.values();
for (LongtimeJavaJob.JobStatus status : values) {
if (!status.interrupted) {
return false;
}
if (status.beforeKilled != 1) {
return false;
}
if (!status.finished || status.killed != 2) {
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.beforeTimeout = false;
status.timeout = false;
LongtimeJavaJob.statusMap.put(key, status);
}
runAtOnce(jobName);
try {
waitForFinish(new FinishCheck() {
@Override
public boolean isOk() {
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.console.domain.JobConfig in project Saturn by vipshop.
the class InitJobFailAlarmIT method testE_ClassNotFoundException.
@Test
public void testE_ClassNotFoundException() throws Exception {
String executorName = startOneNewExecutorList().getExecutorName();
Thread.sleep(1000);
JobConfig jobConfig = new JobConfig();
jobConfig.setJobName("testE_ClassNotFoundException");
jobConfig.setCron("*/2 * * * * ?");
jobConfig.setJobType(JobType.JAVA_JOB.toString());
jobConfig.setJobClass("WhoAmI");
jobConfig.setShardingTotalCount(1);
jobConfig.setShardingItemParameters("0=0");
addJob(jobConfig);
Thread.sleep(2000);
assertThat(InitNewJobService.containsJobInitFailedRecord(executorName, jobConfig.getJobName(), "java.lang.ClassNotFoundException: WhoAmI")).isTrue();
removeJob(jobConfig.getJobName());
}
use of com.vip.saturn.job.console.domain.JobConfig in project Saturn by vipshop.
the class InitJobFailAlarmIT method testG_multiRecord.
@Test
public void testG_multiRecord() throws Exception {
String executorName = startOneNewExecutorList().getExecutorName();
Thread.sleep(1000);
JobConfig jobConfig = new JobConfig();
jobConfig.setJobName("testG_multiRecord");
jobConfig.setCron("*/2 * * * * ?");
jobConfig.setJobType(JobType.JAVA_JOB.toString());
jobConfig.setJobClass("");
jobConfig.setShardingTotalCount(1);
jobConfig.setShardingItemParameters("0=0");
// just add to zk, because add fail if add job by console api
zkAddJob(jobConfig);
Thread.sleep(2000);
assertThat(InitNewJobService.containsJobInitFailedRecord(executorName, jobConfig.getJobName(), "jobClass is not set")).isTrue();
zkRemoveJob(jobConfig.getJobName());
jobConfig.setJobClass("WhoAmI");
addJob(jobConfig);
Thread.sleep(2000);
assertThat(InitNewJobService.containsJobInitFailedRecord(executorName, jobConfig.getJobName(), "jobClass is not set")).isTrue();
assertThat(InitNewJobService.containsJobInitFailedRecord(executorName, jobConfig.getJobName(), "java.lang.ClassNotFoundException: WhoAmI")).isTrue();
removeJob(jobConfig.getJobName());
}
use of com.vip.saturn.job.console.domain.JobConfig in project Saturn by vipshop.
the class InitJobFailAlarmIT method testB_InitFailOfDefaultConstructorJob.
@Test
public void testB_InitFailOfDefaultConstructorJob() throws Exception {
String executorName = startOneNewExecutorList().getExecutorName();
Thread.sleep(1000);
JobConfig jobConfig = new JobConfig();
jobConfig.setJobName("testB_InitFailOfDefaultConstructorJob");
jobConfig.setCron("*/2 * * * * ?");
jobConfig.setJobType(JobType.JAVA_JOB.toString());
jobConfig.setJobClass(InitFailOfDefaultConstructorJob.class.getCanonicalName());
jobConfig.setShardingTotalCount(1);
jobConfig.setShardingItemParameters("0=0");
addJob(jobConfig);
Thread.sleep(2000);
assertThat(InitNewJobService.containsJobInitFailedRecord(executorName, jobConfig.getJobName(), "java.lang.ArithmeticException: / by zero")).isTrue();
removeJob(jobConfig.getJobName());
}
use of com.vip.saturn.job.console.domain.JobConfig in project Saturn by vipshop.
the class InitJobFailAlarmIT method testD_InitFailOfErrorJob.
@Test
public void testD_InitFailOfErrorJob() throws Exception {
String executorName = startOneNewExecutorList().getExecutorName();
Thread.sleep(1000);
JobConfig jobConfig = new JobConfig();
jobConfig.setJobName("testD_InitFailOfErrorJob");
jobConfig.setCron("*/2 * * * * ?");
jobConfig.setJobType(JobType.JAVA_JOB.toString());
jobConfig.setJobClass(InitFailOfErrorJob.class.getCanonicalName());
jobConfig.setShardingTotalCount(1);
jobConfig.setShardingItemParameters("0=0");
addJob(jobConfig);
Thread.sleep(2000);
assertThat(InitNewJobService.containsJobInitFailedRecord(executorName, jobConfig.getJobName(), "java.lang.Error: Error!!!")).isTrue();
removeJob(jobConfig.getJobName());
}
Aggregations