use of com.vip.saturn.job.console.domain.JobConfig in project Saturn by vipshop.
the class EnableOrNotIT method testA.
@Test
public void testA() throws Exception {
startOneNewExecutorList();
Thread.sleep(1000);
SimpleJavaJob.lock.set(false);
JobConfig jobConfig = new JobConfig();
jobConfig.setJobName("testA");
jobConfig.setCron("*/2 * * * * ?");
jobConfig.setJobType(JobType.JAVA_JOB.toString());
jobConfig.setJobClass(SimpleJavaJob.class.getCanonicalName());
jobConfig.setShardingTotalCount(1);
jobConfig.setShardingItemParameters("0=0");
addJob(jobConfig);
Thread.sleep(1000);
assertThat(SimpleJavaJob.enabled.get()).isFalse();
enableJob(jobConfig.getJobName());
Thread.sleep(1000);
assertThat(SimpleJavaJob.enabled.get()).isTrue();
disableJob(jobConfig.getJobName());
Thread.sleep(1000);
assertThat(SimpleJavaJob.enabled.get()).isFalse();
removeJob(jobConfig.getJobName());
}
use of com.vip.saturn.job.console.domain.JobConfig in project Saturn by vipshop.
the class EnableOrNotIT method testC_singleExecutor.
@Test
public void testC_singleExecutor() throws Exception {
startOneNewExecutorList();
Thread.sleep(1000);
SimpleJavaJob.lock.set(true);
JobConfig jobConfig = new JobConfig();
jobConfig.setJobName("testC_singleExecutor");
jobConfig.setCron("*/2 * * * * ?");
jobConfig.setJobType(JobType.JAVA_JOB.toString());
jobConfig.setJobClass(SimpleJavaJob.class.getCanonicalName());
jobConfig.setShardingTotalCount(1);
jobConfig.setShardingItemParameters("0=0");
addJob(jobConfig);
Thread.sleep(1000);
assertThat(SimpleJavaJob.enabled.get()).isFalse();
enableJob(jobConfig.getJobName());
Thread.sleep(1000);
assertThat(SimpleJavaJob.enabled.get()).isTrue();
disableJob(jobConfig.getJobName());
Thread.sleep(1000);
// still true
assertThat(SimpleJavaJob.enabled.get()).isTrue();
synchronized (SimpleJavaJob.lock) {
SimpleJavaJob.lock.notifyAll();
}
Thread.sleep(200);
// change to false
assertThat(SimpleJavaJob.enabled.get()).isFalse();
removeJob(jobConfig.getJobName());
}
use of com.vip.saturn.job.console.domain.JobConfig in project Saturn by vipshop.
the class ExecutorCleanIT method test_B_NoClean.
@Test
public void test_B_NoClean() throws Exception {
SystemEnvProperties.VIP_SATURN_EXECUTOR_CLEAN = false;
startOneNewExecutorList();
final String executorName = saturnExecutorList.get(0).getExecutorName();
final JobConfig job = new JobConfig();
job.setJobName("test_B_NoClean");
job.setCron("*/2 * * * * ?");
job.setJobType(JobType.JAVA_JOB.toString());
job.setJobClass(SimpleJavaJob.class.getCanonicalName());
job.setShardingTotalCount(1);
job.setShardingItemParameters("0=0");
job.setPreferList(executorName);
addJob(job);
Thread.sleep(1000);
enableJob(job.getJobName());
Thread.sleep(3 * 1000);
stopExecutorListGracefully();
Thread.sleep(1000);
assertNoDelete(job.getJobName(), executorName);
}
use of com.vip.saturn.job.console.domain.JobConfig in project Saturn by vipshop.
the class ExecutorCleanIT method test_C_Clean_When_SessionTimeoutAndReconnect.
@Test
public void test_C_Clean_When_SessionTimeoutAndReconnect() throws Exception {
SystemEnvProperties.VIP_SATURN_EXECUTOR_CLEAN = true;
startOneNewExecutorList();
final String executorName = saturnExecutorList.get(0).getExecutorName();
final JobConfig job = new JobConfig();
job.setJobName("test_C_SessionTimeoutAndReconnect");
job.setCron("*/2 * * * * ?");
job.setJobType(JobType.JAVA_JOB.toString());
job.setJobClass(SimpleJavaJob.class.getCanonicalName());
job.setShardingTotalCount(1);
job.setShardingItemParameters("0=0");
job.setPreferList(executorName);
addJob(job);
Thread.sleep(1000);
enableJob(job.getJobName());
Thread.sleep(3 * 1000);
killSession((CuratorFramework) getExecutorRegistryCenter(saturnExecutorList.get(0)).getRawClient());
assertDelete(job.getJobName(), executorName);
Thread.sleep(40 * 1000);
assertNoDelete2(job.getJobName(), executorName);
// stopExecutorListGracefully();
}
use of com.vip.saturn.job.console.domain.JobConfig in project Saturn by vipshop.
the class FailoverIT method failoverWithDisabled.
/**
* 在failover执行之前禁用的作业重新启用后不应该继续上次的failover流程
*/
private void failoverWithDisabled(final int shardCount, final String jobName, final int disableTime) throws Exception {
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);
}
// 1 新建一个执行时间为10S的作业,它只能手工触发
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.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 String firstExecutorName = saturnExecutorList.get(0).getExecutorName();
final List<Integer> items = ItemUtils.toItemList(regCenter.getDirectly(JobNodePath.getNodeFullPath(jobName, ShardingNode.getShardingNode(firstExecutorName))));
final String secondExecutorName = saturnExecutorList.get(1).getExecutorName();
final List<Integer> items2 = ItemUtils.toItemList(regCenter.getDirectly(JobNodePath.getNodeFullPath(jobName, ShardingNode.getShardingNode(secondExecutorName))));
if (disableTime == 1) {
disableJob(jobName);
}
// 4 停止第一个executor,在该executor上运行的分片会失败转移
stopExecutor(0);
System.out.println("items:" + items);
// 5 直到第一个Executor完全下线
try {
waitForFinish(new FinishCheck() {
@Override
public boolean isOk() {
if (isOnline(firstExecutorName)) {
// 判断该Executor是否在线
return false;
}
return true;
}
}, 20);
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
// 6 检查停止的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;
}
// 7 检查运行executor2上的分片都正在运行,而且runningCount为0
for (Integer item : items2) {
String key = jobName + "_" + item;
LongtimeJavaJob.JobStatus status = LongtimeJavaJob.statusMap.get(key);
if (status.finished || status.killed > 0 || status.timeout) {
fail("should running");
}
if (status.runningCount != 0) {
fail("runningCount should be 0");
}
}
// 8 禁用作业
if (disableTime == 2) {
disableJob(jobName);
}
// 9 等待executor2分片运行完
try {
waitForFinish(new FinishCheck() {
@Override
public boolean isOk() {
for (Integer item : items2) {
String key = jobName + "_" + item;
LongtimeJavaJob.JobStatus status = LongtimeJavaJob.statusMap.get(key);
if (!status.finished) {
return false;
}
}
return true;
}
}, 20);
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
// 10 检测无failover信息
assertThat(noFailoverItems(jobName));
for (Integer item : items) {
assertThat(isFailoverAssigned(jobName, item)).isEqualTo(false);
}
// 11 检测只executor2的分片只运行了一次
Thread.sleep(2000);
for (Integer item : items2) {
String key = jobName + "_" + item;
LongtimeJavaJob.JobStatus status = LongtimeJavaJob.statusMap.get(key);
if (status.runningCount != 1) {
fail("runningCount should be 1");
}
}
removeJob(jobName);
Thread.sleep(2000);
LongtimeJavaJob.statusMap.clear();
}
Aggregations