use of com.vip.saturn.it.base.FinishCheck in project Saturn by vipshop.
the class DownStreamIT method test.
@Test
public void test() throws Exception {
startOneNewExecutorList();
JobB.count = 0;
// add downStream firstly
JobConfig jobB = new JobConfig();
jobB.setJobName("downStreamITJobB");
jobB.setJobType(JobType.PASSIVE_JAVA_JOB.toString());
jobB.setJobClass(JobB.class.getCanonicalName());
jobB.setShardingTotalCount(1);
jobB.setShardingItemParameters("0=0");
addJob(jobB);
Thread.sleep(1000);
JobConfig jobA = new JobConfig();
jobA.setJobName("downStreamITJobA");
jobA.setCron("9 9 9 9 9 ? 2099");
jobA.setJobType(JobType.JAVA_JOB.toString());
jobA.setJobClass(JobA.class.getCanonicalName());
jobA.setShardingTotalCount(1);
jobA.setShardingItemParameters("0=0");
jobA.setDownStream(jobB.getJobName());
addJob(jobA);
Thread.sleep(1000);
enableJob(jobA.getJobName());
enableJob(jobB.getJobName());
Thread.sleep(1000);
runAtOnce(jobA.getJobName());
Thread.sleep(1000);
waitForFinish(new FinishCheck() {
@Override
public boolean isOk() {
return JobB.count == 1;
}
}, 10);
disableJob(jobA.getJobName());
disableJob(jobB.getJobName());
Thread.sleep(1000);
UpdateJobConfigVo updateJobConfigVo = new UpdateJobConfigVo();
updateJobConfigVo.setJobName(jobA.getJobName());
updateJobConfigVo.setDownStream("");
updateJob(updateJobConfigVo);
Thread.sleep(1000);
removeJob(jobA.getJobName());
removeJob(jobB.getJobName());
}
use of com.vip.saturn.it.base.FinishCheck in project Saturn by vipshop.
the class ExecutionIT method test_B_executionStatus.
@Test
public void test_B_executionStatus() throws Exception {
startExecutorList(1);
final String jobName = "test_B_executionStatus";
final int shardCount = 1;
for (int i = 0; i < shardCount; i++) {
String key = jobName + "_" + i;
LongtimeJavaJob.JobStatus status = new LongtimeJavaJob.JobStatus();
status.runningCount = 0;
status.sleepSeconds = 20;
status.finished = false;
status.timeout = false;
LongtimeJavaJob.statusMap.put(key, status);
}
JobConfig jobConfig = new JobConfig();
jobConfig.setJobName(jobName);
// 间隔大于5分钟,会上报状态,failover
jobConfig.setCron("0 */6 * * * ? 2099");
jobConfig.setJobType(JobType.JAVA_JOB.toString());
jobConfig.setJobClass(LongtimeJavaJob.class.getCanonicalName());
jobConfig.setShardingTotalCount(shardCount);
jobConfig.setTimeoutSeconds(0);
jobConfig.setShardingItemParameters("0=0");
addJob(jobConfig);
Thread.sleep(1000);
enableJob(jobName);
Thread.sleep(1000);
runAtOnce(jobName);
Thread.sleep(2000);
assertThat(zkGetJobNode(jobName, "execution/0/running")).isEqualTo("executorName0");
zkRemoveJobNode(jobName, "execution/0/running");
Thread.sleep(1000);
// itself take over 0 item
assertThat(zkGetJobNode(jobName, "execution/0/failover")).isEqualTo("executorName0");
// wait the last finish, until the failover lifecycle begin
waitForFinish(new FinishCheck() {
@Override
public boolean isOk() {
return regCenter.isExisted(JobNodePath.getNodeFullPath(jobName, "execution/0/running"));
}
}, 30);
assertThat(zkGetJobNode(jobName, "execution/0/running")).isEqualTo("executorName0");
// wait the failover lifecycle finish
waitForFinish(new FinishCheck() {
@Override
public boolean isOk() {
return regCenter.isExisted(JobNodePath.getNodeFullPath(jobName, "execution/0/completed"));
}
}, 30);
assertThat(zkGetJobNode(jobName, "execution/0/completed")).isEqualTo("executorName0");
disableJob(jobName);
Thread.sleep(1000);
removeJob(jobName);
Thread.sleep(2000);
LongtimeJavaJob.statusMap.clear();
stopExecutorListGracefully();
}
use of com.vip.saturn.it.base.FinishCheck 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.it.base.FinishCheck 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.it.base.FinishCheck in project Saturn by vipshop.
the class FailoverIT method failover.
private void failover(final int shardCount, final String jobName) throws Exception {
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的作业,它只能手工触发
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);
// 2 启动作业并立刻执行一次
enableJob(jobName);
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;
}
}, 6);
} 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 (Integer item : items) {
if (!isFailoverAssigned(jobName, item)) {
return false;
}
}
return true;
}
}, 20);
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
Thread.sleep(1000);
// 5 检查停止的executor 上面的分片是否已经被KILL
for (Integer item : items) {
String key = jobName + "_" + item;
LongtimeJavaJob.JobStatus status = LongtimeJavaJob.statusMap.get(key);
if (!status.finished || status.killed == 0) {
fail("should finish and killed");
}
status.runningCount = 0;
}
// 6 保证全部分片都会执行一次(被停止的executor上的分片会失败转移从而也会执行一次)
try {
waitForFinish(new FinishCheck() {
@Override
public boolean isOk() {
for (int j = 0; j < shardCount; j++) {
String key = jobName + "_" + j;
LongtimeJavaJob.JobStatus status = LongtimeJavaJob.statusMap.get(key);
if (status.runningCount <= 0) {
return false;
}
}
return true;
}
}, 60);
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
disableJob(jobName);
Thread.sleep(1000);
removeJob(jobName);
Thread.sleep(2000);
LongtimeJavaJob.statusMap.clear();
}
Aggregations