use of com.vip.saturn.job.executor.Main in project Saturn by vipshop.
the class ShardingWithTrafficIT method test_A_NormalFlow.
/**
* 一般流量摘取和恢复流程:<br> 两个启用状态的作业,两台机A、B;<br> 摘取B的流量,结果B的分片被分配到A;<br> 下线B,分片分配依然不变;<br> 上线B,分配分配依然不变;<br>
* 恢复B的流量,结果平均分配分片到A、B。
*/
@Test
public void test_A_NormalFlow() throws Exception {
String jobName = "test_A_NormalFlow";
String jobName2 = "test_A_NormalFlow2";
final JobConfig jobConfig = new JobConfig();
jobConfig.setJobName(jobName);
jobConfig.setCron("9 9 9 9 9 ? 2099");
jobConfig.setJobType(JobType.JAVA_JOB.toString());
jobConfig.setJobClass(SimpleJavaJob.class.getCanonicalName());
jobConfig.setShardingTotalCount(2);
jobConfig.setShardingItemParameters("0=0,1=1");
final JobConfig jobConfig2 = new JobConfig();
jobConfig2.setJobName(jobName2);
jobConfig2.setCron("9 9 9 9 9 ? 2099");
jobConfig2.setJobType(JobType.JAVA_JOB.toString());
jobConfig2.setJobClass(SimpleJavaJob.class.getCanonicalName());
jobConfig2.setShardingTotalCount(2);
jobConfig2.setShardingItemParameters("0=0,1=1");
addJob(jobConfig);
Thread.sleep(1000L);
addJob(jobConfig2);
Thread.sleep(1000L);
enableJob(jobName);
Thread.sleep(1000L);
enableJob(jobName2);
Thread.sleep(1000L);
Main executor1 = startOneNewExecutorList();
String executorName1 = executor1.getExecutorName();
Main executor2 = startOneNewExecutorList();
String executorName2 = executor2.getExecutorName();
runAtOnceAndWaitShardingCompleted(jobName);
runAtOnceAndWaitShardingCompleted(jobName2);
isItemsBalanceOk(jobName, jobName2, executorName1, executorName2);
extractTraffic(executorName2);
Thread.sleep(1000L);
runAtOnceAndWaitShardingCompleted(jobName);
runAtOnceAndWaitShardingCompleted(jobName2);
isItemsToExecutor1(jobName, jobName2, executorName1, executorName2);
stopExecutorGracefully(1);
Thread.sleep(1000L);
runAtOnceAndWaitShardingCompleted(jobName);
runAtOnceAndWaitShardingCompleted(jobName2);
isItemsToExecutor1(jobName, jobName2, executorName1, executorName2);
executor2 = startExecutor(1);
executorName2 = executor2.getExecutorName();
runAtOnceAndWaitShardingCompleted(jobName);
runAtOnceAndWaitShardingCompleted(jobName2);
isItemsToExecutor1(jobName, jobName2, executorName1, executorName2);
recoverTraffic(executorName2);
Thread.sleep(1000L);
runAtOnceAndWaitShardingCompleted(jobName);
runAtOnceAndWaitShardingCompleted(jobName2);
isItemsBalanceOk(jobName, jobName2, executorName1, executorName2);
// 清理,不影响其他Test
disableJob(jobName);
disableJob(jobName2);
Thread.sleep(1000L);
removeJob(jobName);
removeJob(jobName2);
Thread.sleep(1000L);
stopExecutorListGracefully();
}
use of com.vip.saturn.job.executor.Main in project Saturn by vipshop.
the class TimeoutJobIT method test_B_shJob.
@Test
public void test_B_shJob() throws Exception {
// bacause ScriptPidUtils.isPidRunning don't support mac
if (!OS.isFamilyUnix() || OS.isFamilyMac()) {
return;
}
final int shardCount = 3;
final String jobName = "test_B_shJob";
JobConfig jobConfig = new JobConfig();
jobConfig.setJobName(jobName);
jobConfig.setCron("9 9 9 9 9 ? 2099");
jobConfig.setJobType(JobType.SHELL_JOB.toString());
jobConfig.setJobClass(LongtimeJavaJob.class.getCanonicalName());
jobConfig.setTimeoutSeconds(3);
jobConfig.setShardingTotalCount(shardCount);
jobConfig.setShardingItemParameters("0=sh " + LONG_TIME_SH_PATH + ",1=sh " + LONG_TIME_SH_PATH + ",2=sh " + LONG_TIME_SH_PATH);
addJob(jobConfig);
Thread.sleep(1000);
enableJob(jobConfig.getJobName());
Thread.sleep(1000);
runAtOnce(jobName);
// wait executor receive the runAtOnce event
Thread.sleep(500L);
try {
waitForFinish(new FinishCheck() {
@Override
public boolean isOk() {
for (int i = 0; i < saturnExecutorList.size(); i++) {
Main saturnContainer = saturnExecutorList.get(i);
for (int j = 0; j < shardCount; j++) {
long pid = ScriptPidUtils.getFirstPidFromFile(saturnContainer.getExecutorName(), jobName, "" + j);
if (pid > 0 && ScriptPidUtils.isPidRunning(pid)) {
return false;
}
}
}
return true;
}
}, 10);
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
try {
waitForFinish(new FinishCheck() {
@Override
public boolean isOk() {
for (int j = 0; j < shardCount; j++) {
if (!regCenter.isExisted(JobNodePath.getNodeFullPath(jobName, ExecutionNode.getCompletedNode(j)))) {
return false;
}
}
return true;
}
}, 10);
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
disableJob(jobConfig.getJobName());
Thread.sleep(1000);
removeJob(jobConfig.getJobName());
LongtimeJavaJob.statusMap.clear();
}
use of com.vip.saturn.job.executor.Main in project Saturn by vipshop.
the class UpdateCronJobIT method updateCron.
@Test
public void updateCron() throws Exception {
final int shardCount = 3;
final String jobName = "toBeupdatedITJob";
for (int i = 0; i < shardCount; i++) {
String key = jobName + "_" + i;
SimpleJavaJob.statusMap.put(key, 0);
}
JobConfig jobConfig = new JobConfig();
jobConfig.setJobName(jobName);
jobConfig.setCron("9 9 9 9 9 ? 2099");
jobConfig.setJobType(JobType.JAVA_JOB.toString());
jobConfig.setJobClass(SimpleJavaJob.class.getCanonicalName());
jobConfig.setShardingTotalCount(shardCount);
jobConfig.setTimeoutSeconds(0);
jobConfig.setShardingItemParameters("0=0,1=1,2=2");
addJob(jobConfig);
Thread.sleep(2000);
enableJob(jobName);
jobConfig = new JobConfig();
jobConfig.setJobName("updateCronITJob");
jobConfig.setCron("9 9 9 9 9 ? 2099");
jobConfig.setJobType(JobType.JAVA_JOB.toString());
jobConfig.setJobClass(UpdateCronJob.class.getCanonicalName());
jobConfig.setShardingTotalCount(1);
jobConfig.setProcessCountIntervalSeconds(1);
jobConfig.setShardingItemParameters("0=toBeupdatedITJob");
addJob(jobConfig);
Thread.sleep(2000);
for (int i = 0; i < shardCount; i++) {
String key = jobName + "_" + i;
assertThat(SimpleJavaJob.statusMap.get(key)).isEqualTo(0);
}
enableJob(jobConfig.getJobName());
Thread.sleep(2000);
runAtOnce(jobConfig.getJobName());
Thread.sleep(2000);
final JobConfig t = jobConfig;
waitForFinish(new FinishCheck() {
@Override
public boolean isOk() {
for (Main executor : saturnExecutorList) {
String count = zkGetJobNode(t.getJobName(), "servers/" + executor.getExecutorName() + "/processSuccessCount");
System.out.println("count:" + count + ";executor:" + executor.getExecutorName());
if (count == null)
return false;
int times = Integer.parseInt(count);
if (times <= 0)
return false;
}
return true;
}
}, 10);
disableJob(jobConfig.getJobName());
Thread.sleep(2 * 1000);
removeJob(jobConfig.getJobName());
waitForFinish(new FinishCheck() {
@Override
public boolean isOk() {
for (int i = 0; i < shardCount; i++) {
String key = jobName + "_" + i;
if (SimpleJavaJob.statusMap.get(key) < 1) {
return false;
}
}
return true;
}
}, 30);
disableJob(jobName);
Thread.sleep(1000);
removeJob(jobName);
Thread.sleep(2000);
SimpleJavaJob.statusMap.clear();
}
Aggregations