use of com.vip.saturn.job.console.domain.JobConfig in project Saturn by vipshop.
the class ShutdownGracefullyIT method test_B_INT_Signal.
@Test
public void test_B_INT_Signal() throws Exception {
SystemEnvProperties.VIP_SATURN_SHUTDOWN_TIMEOUT = 5;
startExecutorList(1);
final int shardCount = 3;
final String jobName = "test_B_INT_Signal";
for (int i = 0; i < shardCount; i++) {
String key = jobName + "_" + i;
LongtimeJavaJob.JobStatus status = new LongtimeJavaJob.JobStatus();
status.runningCount = 0;
status.sleepSeconds = 3;
status.finished = 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.setShardingItemParameters("0=0,1=1,2=2");
addJob(jobConfig);
Thread.sleep(1000);
enableJob(jobName);
Thread.sleep(1000);
runAtOnce(jobName);
Thread.sleep(50);
ShutdownHandler.exitAfterHandler(false);
Signal.raise(new Signal("INT"));
try {
waitForFinish(new FinishCheck() {
@Override
public boolean isOk() {
Collection<LongtimeJavaJob.JobStatus> values = LongtimeJavaJob.statusMap.values();
for (LongtimeJavaJob.JobStatus status : values) {
if (!status.finished) {
return false;
}
}
return true;
}
}, 5);
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
stopExecutorListGracefully();
}
use of com.vip.saturn.job.console.domain.JobConfig in project Saturn by vipshop.
the class UpdateConfigIT method updatePauseDate.
@Test
public void updatePauseDate() throws Exception {
int shardCount = 1;
String jobName = "updatePauseDate";
for (int i = 0; i < shardCount; i++) {
String key = jobName + "_" + i;
SimpleJavaJob.statusMap.put(key, 0);
}
JobConfig jobConfig = new JobConfig();
jobConfig.setJobName(jobName);
jobConfig.setTimeZone(TimeZone.getDefault().getID());
jobConfig.setCron("*/1 * * * * ?");
jobConfig.setJobType(JobType.JAVA_JOB.toString());
jobConfig.setJobClass(SimpleJavaJob.class.getCanonicalName());
jobConfig.setShardingTotalCount(shardCount);
jobConfig.setShardingItemParameters("0=0");
addJob(jobConfig);
Thread.sleep(1000);
enableJob(jobName);
Thread.sleep(2 * 1000);
disableJob(jobName);
Thread.sleep(2 * 1000);
for (int i = 0; i < shardCount; i++) {
String key = jobName + "_" + i;
assertThat(SimpleJavaJob.statusMap.get(key)).isGreaterThanOrEqualTo(1);
}
for (int i = 0; i < shardCount; i++) {
String key = jobName + "_" + i;
SimpleJavaJob.statusMap.put(key, 0);
}
int month = Calendar.getInstance().get(Calendar.MONTH) + 1;
String pauseDate = month + "/" + Calendar.getInstance().get(Calendar.DAY_OF_MONTH) + "-" + month + "/" + Calendar.getInstance().get(Calendar.DAY_OF_MONTH);
String pauseTime = Calendar.getInstance().get(Calendar.HOUR_OF_DAY) + ":00" + "-" + Calendar.getInstance().get(Calendar.HOUR_OF_DAY) + ":59";
zkUpdateJobNode(jobName, "config/pausePeriodDate", pauseDate);
zkUpdateJobNode(jobName, "config/pausePeriodTime", pauseTime);
Thread.sleep(1000);
enableJob(jobConfig.getJobName());
Thread.sleep(2 * 1000);
for (int i = 0; i < shardCount; i++) {
String key = jobName + "_" + i;
assertThat(SimpleJavaJob.statusMap.get(key)).isEqualTo(0);
}
SimpleJavaJob.statusMap.clear();
disableJob(jobName);
Thread.sleep(1000);
removeJob(jobName);
Thread.sleep(2000);
}
use of com.vip.saturn.job.console.domain.JobConfig in project Saturn by vipshop.
the class ZkStopStartIT method test_A_zkStopStartJobJava.
@Test
public void test_A_zkStopStartJobJava() throws Exception {
final int shardCount = 3;
final String jobName = "test_A_zkStopStartJobJava";
LongtimeJavaJob.statusMap.clear();
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.timeout = false;
status.running = 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.setShardingItemParameters("0=0,1=1,2=2");
addJob(jobConfig);
Thread.sleep(2000);
enableJob(jobName);
Thread.sleep(2000);
runAtOnce(jobName);
Thread.sleep(2000);
try {
waitForFinish(new FinishCheck() {
@Override
public boolean isOk() {
Collection<LongtimeJavaJob.JobStatus> values = LongtimeJavaJob.statusMap.values();
for (LongtimeJavaJob.JobStatus status : values) {
if (!status.running) {
return false;
}
}
return true;
}
}, 40);
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
stopZkServer();
try {
waitForFinish(new FinishCheck() {
@Override
public boolean isOk() {
Collection<LongtimeJavaJob.JobStatus> values = LongtimeJavaJob.statusMap.values();
for (LongtimeJavaJob.JobStatus status : values) {
if (!status.finished) {
return false;
}
}
return true;
}
}, 40);
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
LongtimeJavaJob.statusMap.clear();
}
use of com.vip.saturn.job.console.domain.JobConfig in project Saturn by vipshop.
the class InitJobFailAlarmIT method testH_clearRecord.
@Test
public void testH_clearRecord() throws Exception {
String executorName = startOneNewExecutorList().getExecutorName();
Thread.sleep(1000);
JobConfig jobConfig = new JobConfig();
jobConfig.setJobName("testH_clearRecord");
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(InitSuccessfullyJob.class.getCanonicalName());
addJob(jobConfig);
Thread.sleep(2000);
assertThat(InitNewJobService.containsJobInitFailedRecord(executorName, jobConfig.getJobName(), "jobClass is not set")).isFalse();
removeJob(jobConfig.getJobName());
}
use of com.vip.saturn.job.console.domain.JobConfig in project Saturn by vipshop.
the class InitJobFailAlarmIT method testA_InitFailOfGetObjectJob.
@Test
public void testA_InitFailOfGetObjectJob() throws Exception {
String executorName = startOneNewExecutorList().getExecutorName();
Thread.sleep(1000);
JobConfig jobConfig = new JobConfig();
jobConfig.setJobName("testA_InitFailOfGetObjectJob");
jobConfig.setCron("*/2 * * * * ?");
jobConfig.setJobType(JobType.JAVA_JOB.toString());
jobConfig.setJobClass(InitFailOfGetObjectJob.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());
}
Aggregations