use of com.vip.saturn.job.console.domain.JobConfig in project Saturn by vipshop.
the class ExecutionIT method test_A_report.
@Test
public void test_A_report() throws Exception {
startExecutorList(1);
final JobConfig jobConfig = new JobConfig();
jobConfig.setJobName("test_A_report");
jobConfig.setCron("9 9 9 9 9 ? 2099");
jobConfig.setJobType(JobType.JAVA_JOB.toString());
jobConfig.setJobClass(SimpleJavaJob.class.getCanonicalName());
jobConfig.setShardingTotalCount(1);
jobConfig.setShardingItemParameters("0=0");
addJob(jobConfig);
zkUpdateJobNode(jobConfig.getJobName(), "config/enabledReport", "true");
Thread.sleep(1000);
enableJob(jobConfig.getJobName());
Thread.sleep(1000);
runAtOnce(jobConfig.getJobName());
Thread.sleep(1000);
assertThat(zkGetJobNode(jobConfig.getJobName(), "execution/0/lastBeginTime")).isNull();
assertThat(zkGetJobNode(jobConfig.getJobName(), "execution/0/nextFireTime")).isNull();
assertThat(zkGetJobNode(jobConfig.getJobName(), "execution/0/lastCompleteTime")).isNull();
assertThat(zkGetJobNode(jobConfig.getJobName(), "execution/0/jobMsg")).isNull();
assertThat(zkGetJobNode(jobConfig.getJobName(), "execution/0/jobLog")).isNull();
assertThat(zkGetJobNode(jobConfig.getJobName(), "execution/0/completed")).isNotNull();
doReport(jobConfig.getJobName());
waitForFinish(new FinishCheck() {
@Override
public boolean isOk() {
if (zkGetJobNode(jobConfig.getJobName(), "execution/0/lastBeginTime") != null && zkGetJobNode(jobConfig.getJobName(), "execution/0/nextFireTime") != null && zkGetJobNode(jobConfig.getJobName(), "execution/0/lastCompleteTime") != null && zkGetJobNode(jobConfig.getJobName(), "execution/0/jobMsg") != null && zkGetJobNode(jobConfig.getJobName(), "execution/0/jobLog") != null) {
return true;
}
return false;
}
}, 3);
zkRemoveJobNode(jobConfig.getJobName(), "execution/0/lastBeginTime");
zkRemoveJobNode(jobConfig.getJobName(), "execution/0/nextFireTime");
zkRemoveJobNode(jobConfig.getJobName(), "execution/0/lastCompleteTime");
zkRemoveJobNode(jobConfig.getJobName(), "execution/0/jobMsg");
zkRemoveJobNode(jobConfig.getJobName(), "execution/0/jobLog");
zkRemoveJobNode(jobConfig.getJobName(), "execution/0/completed");
disableJob(jobConfig.getJobName());
Thread.sleep(1000);
disableReport(jobConfig.getJobName());
Thread.sleep(1000);
enableJob(jobConfig.getJobName());
Thread.sleep(1000);
runAtOnce(jobConfig.getJobName());
Thread.sleep(1000);
assertThat(zkGetJobNode(jobConfig.getJobName(), "execution/0/completed")).isNull();
doReport(jobConfig.getJobName());
waitForFinish(new FinishCheck() {
@Override
public boolean isOk() {
if (zkGetJobNode(jobConfig.getJobName(), "execution/0/lastBeginTime") != null && zkGetJobNode(jobConfig.getJobName(), "execution/0/nextFireTime") != null && zkGetJobNode(jobConfig.getJobName(), "execution/0/lastCompleteTime") != null && zkGetJobNode(jobConfig.getJobName(), "execution/0/jobMsg") != null && zkGetJobNode(jobConfig.getJobName(), "execution/0/jobLog") != null) {
return true;
}
return false;
}
}, 3);
disableJob(jobConfig.getJobName());
Thread.sleep(1000);
removeJob(jobConfig.getJobName());
Thread.sleep(1000);
stopExecutorListGracefully();
}
use of com.vip.saturn.job.console.domain.JobConfig in project Saturn by vipshop.
the class FailoverWithPreferListIT method test_A_JavaJob.
@Test
public void test_A_JavaJob() throws Exception {
final int shardCount = 2;
final String jobName = "failoverWithPreferITJobJava";
for (int i = 0; i < shardCount; i++) {
String key = jobName + "_" + i;
LongtimeJavaJob.JobStatus status = new LongtimeJavaJob.JobStatus();
status.runningCount = 0;
status.sleepSeconds = 10;
status.finished = false;
status.timeout = false;
LongtimeJavaJob.statusMap.put(key, status);
}
// 1 新建一个执行时间为10S的作业,它只能手工触发,它设置了preferList为executor0,并且只能使用优先结点
final 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.setPreferList(saturnExecutorList.get(0).getExecutorName());
jobConfig.setUseDispreferList(false);
jobConfig.setShardingItemParameters("0=0,1=1,2=2");
addJob(jobConfig);
Thread.sleep(1000);
// 2 启动作业并立刻执行一次
enableJob(jobConfig.getJobName());
Thread.sleep(2000);
runAtOnce(jobName);
// 3 保证全部作业分片正在运行中
try {
waitForFinish(new FinishCheck() {
@Override
public boolean isOk() {
for (int j = 0; j < shardCount; j++) {
if (!regCenter.isExisted(JobNodePath.getNodeFullPath(jobName, ExecutionNode.getRunningNode(j)))) {
return false;
}
}
return true;
}
}, 30);
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
Thread.sleep(2000);
final List<Integer> items = ItemUtils.toItemList(regCenter.getDirectly(JobNodePath.getNodeFullPath(jobName, ShardingNode.getShardingNode(saturnExecutorList.get(0).getExecutorName()))));
// 4 停止第一个executor,在该executor上运行的分片不会失败转移(因为优先结点已经全部死掉了)
stopExecutor(0);
System.out.println("items:" + items);
try {
waitForFinish(new FinishCheck() {
@Override
public boolean isOk() {
for (int j = 0; j < shardCount; j++) {
if (regCenter.isExisted(JobNodePath.getNodeFullPath(jobName, ExecutionNode.getRunningNode(j)))) {
return false;
}
}
return true;
}
}, 20);
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
// 5 没有失败转移,executor0上面运行的分片不会被执行
for (Integer item : items) {
String key = jobName + "_" + item;
LongtimeJavaJob.JobStatus status = LongtimeJavaJob.statusMap.get(key);
assertThat(status.runningCount).isEqualTo(0);
}
disableJob(jobConfig.getJobName());
Thread.sleep(1000);
removeJob(jobConfig.getJobName());
Thread.sleep(2000);
LongtimeJavaJob.statusMap.clear();
}
use of com.vip.saturn.job.console.domain.JobConfig in project Saturn by vipshop.
the class InitJobByGroupsIT method testC_ExecutorConfigGroupsAndInitJobFailed.
@Test
public void testC_ExecutorConfigGroupsAndInitJobFailed() throws Exception {
try {
System.setProperty(SystemEnvProperties.NAME_VIP_SATURN_INIT_JOB_BY_GROUPS, "group1, group2");
SystemEnvProperties.loadProperties();
InitByGroupsJob.inited = false;
startOneNewExecutorList();
Thread.sleep(1000);
JobConfig jobConfig = new JobConfig();
jobConfig.setJobName("testC_ExecutorConfigGroupsAndInitJobFailed");
jobConfig.setCron("*/2 * * * * ?");
jobConfig.setJobType(JobType.JAVA_JOB.toString());
jobConfig.setJobClass(InitByGroupsJob.class.getCanonicalName());
jobConfig.setShardingTotalCount(1);
jobConfig.setShardingItemParameters("0=0");
jobConfig.setGroups("");
addJob(jobConfig);
Thread.sleep(1000);
assertThat(InitByGroupsJob.inited).isFalse();
removeJob(jobConfig.getJobName());
} finally {
System.clearProperty(SystemEnvProperties.NAME_VIP_SATURN_INIT_JOB_BY_GROUPS);
SystemEnvProperties.loadProperties();
}
}
use of com.vip.saturn.job.console.domain.JobConfig in project Saturn by vipshop.
the class InitJobByGroupsIT method testB_ExecutorConfigGroupsAndInitJobSuccessfully.
@Test
public void testB_ExecutorConfigGroupsAndInitJobSuccessfully() throws Exception {
try {
System.setProperty(SystemEnvProperties.NAME_VIP_SATURN_INIT_JOB_BY_GROUPS, "group1, group2");
SystemEnvProperties.loadProperties();
InitByGroupsJob.inited = false;
startOneNewExecutorList();
Thread.sleep(1000);
JobConfig jobConfig = new JobConfig();
jobConfig.setJobName("testB_ExecutorConfigGroupsAndInitJobSuccessfully");
jobConfig.setCron("*/2 * * * * ?");
jobConfig.setJobType(JobType.JAVA_JOB.toString());
jobConfig.setJobClass(InitByGroupsJob.class.getCanonicalName());
jobConfig.setShardingTotalCount(1);
jobConfig.setShardingItemParameters("0=0");
jobConfig.setGroups("group2");
addJob(jobConfig);
Thread.sleep(1000);
assertThat(InitByGroupsJob.inited).isTrue();
removeJob(jobConfig.getJobName());
} finally {
System.clearProperty(SystemEnvProperties.NAME_VIP_SATURN_INIT_JOB_BY_GROUPS);
SystemEnvProperties.loadProperties();
}
}
use of com.vip.saturn.job.console.domain.JobConfig in project Saturn by vipshop.
the class InitJobByGroupsIT method testA_ExecutorNotConfigGroups.
@Test
public void testA_ExecutorNotConfigGroups() throws Exception {
System.clearProperty(SystemEnvProperties.NAME_VIP_SATURN_INIT_JOB_BY_GROUPS);
SystemEnvProperties.loadProperties();
InitByGroupsJob.inited = false;
startOneNewExecutorList();
Thread.sleep(1000);
JobConfig jobConfig = new JobConfig();
jobConfig.setJobName("testA_ExecutorNotConfigGroups");
jobConfig.setCron("*/2 * * * * ?");
jobConfig.setJobType(JobType.JAVA_JOB.toString());
jobConfig.setJobClass(InitByGroupsJob.class.getCanonicalName());
jobConfig.setShardingTotalCount(1);
jobConfig.setShardingItemParameters("0=0");
jobConfig.setGroups("");
addJob(jobConfig);
Thread.sleep(1000);
assertThat(InitByGroupsJob.inited).isTrue();
removeJob(jobConfig.getJobName());
}
Aggregations