use of com.vip.saturn.job.console.domain.JobConfig in project Saturn by vipshop.
the class InitJobFailAlarmIT method testF_jobClassIsNotSet.
@Test
public void testF_jobClassIsNotSet() throws Exception {
String executorName = startOneNewExecutorList().getExecutorName();
Thread.sleep(1000);
JobConfig jobConfig = new JobConfig();
jobConfig.setJobName("testF_jobClassIsNotSet");
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());
}
use of com.vip.saturn.job.console.domain.JobConfig in project Saturn by vipshop.
the class DeleteJobIT method test_A_multiExecutor.
/**
* 多个Executor
*/
@Test
public void test_A_multiExecutor() throws Exception {
startExecutorList(3);
int shardCount = 3;
final String jobName = "test_A_multiExecutor";
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("*/2 * * * * ?");
jobConfig.setJobType(JobType.JAVA_JOB.toString());
jobConfig.setJobClass(SimpleJavaJob.class.getCanonicalName());
jobConfig.setShardingTotalCount(shardCount);
jobConfig.setShardingItemParameters("0=0,1=1,2=2");
addJob(jobConfig);
Thread.sleep(1000);
enableReport(jobName);
enableJob(jobName);
Thread.sleep(4 * 1000);
disableJob(jobName);
Thread.sleep(1000);
for (int i = 0; i < shardCount; i++) {
String key = jobName + "_" + i;
assertThat(SimpleJavaJob.statusMap.get(key)).isGreaterThanOrEqualTo(1);
}
removeJob(jobName);
try {
waitForFinish(new FinishCheck() {
@Override
public boolean isOk() {
for (Main executor : saturnExecutorList) {
if (executor == null) {
continue;
}
if (regCenter.isExisted(ServerNode.getServerNode(jobName, executor.getExecutorName()))) {
return false;
}
}
return true;
}
}, 10);
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
}
use of com.vip.saturn.job.console.domain.JobConfig in project Saturn by vipshop.
the class DeleteJobIT method test_B_oneExecutor.
/**
* 只有一个Executor
*/
@Test
public void test_B_oneExecutor() throws Exception {
startOneNewExecutorList();
final int shardCount = 3;
final String jobName = "test_B_oneExecutor";
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("*/2 * * * * ?");
jobConfig.setJobType(JobType.JAVA_JOB.toString());
jobConfig.setJobClass(SimpleJavaJob.class.getCanonicalName());
jobConfig.setShardingTotalCount(shardCount);
jobConfig.setShardingItemParameters("0=0,1=1,2=2");
addJob(jobConfig);
Thread.sleep(1000);
enableReport(jobName);
enableJob(jobName);
try {
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;
}
}, 4);
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
disableJob(jobName);
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;
}
}, 3);
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
removeJob(jobName);
try {
waitForFinish(new FinishCheck() {
@Override
public boolean isOk() {
for (Main executor : saturnExecutorList) {
if (executor == null) {
continue;
}
if (regCenter.isExisted(ServerNode.getServerNode(jobName, executor.getExecutorName()))) {
return false;
}
}
return true;
}
}, 10);
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
}
use of com.vip.saturn.job.console.domain.JobConfig in project Saturn by vipshop.
the class DeleteJobIT method test_C_alreadyExistsToDelete.
/**
* 补充删除作业时在启动Executor前有toDelete结点的IT: 如果有在启动Executor前作业有配置toDelete结点则会判断并删除$Jobs/jobName/servers/executorName
*/
@Test
public void test_C_alreadyExistsToDelete() throws Exception {
final int shardCount = 3;
final String jobName = "test_C_alreadyExistsToDelete";
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("*/2 * * * * ?");
jobConfig.setJobType(JobType.JAVA_JOB.toString());
jobConfig.setJobClass(SimpleJavaJob.class.getCanonicalName());
jobConfig.setShardingTotalCount(shardCount);
jobConfig.setShardingItemParameters("0=0,1=1,2=2");
addJob(jobConfig);
Thread.sleep(1000);
enableReport(jobName);
// 使用hack的方式,直接新增toDelete结点
zkUpdateJobNode(jobName, ConfigurationNode.TO_DELETE, "1");
final String serverNodePath = JobNodePath.getServerNodePath(jobName, "executorName0");
regCenter.persist(serverNodePath, "");
startOneNewExecutorList();
Thread.sleep(1000);
try {
waitForFinish(new FinishCheck() {
@Override
public boolean isOk() {
if (regCenter.isExisted(serverNodePath)) {
return false;
}
return true;
}
}, 10);
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
removeJob(jobName);
}
use of com.vip.saturn.job.console.domain.JobConfig in project Saturn by vipshop.
the class EnableOrNotIT method testB_restartExecutorWithEnabledChanged.
@Test
public void testB_restartExecutorWithEnabledChanged() throws Exception {
startOneNewExecutorList();
Thread.sleep(1000);
SimpleJavaJob.lock.set(false);
JobConfig jobConfig = new JobConfig();
jobConfig.setJobName("testB_restartExecutor");
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();
stopExecutorGracefully(0);
Thread.sleep(1000);
enableJob(jobConfig.getJobName());
Thread.sleep(1000);
startOneNewExecutorList();
Thread.sleep(1000);
assertThat(SimpleJavaJob.enabled.get()).isTrue();
disableJob(jobConfig.getJobName());
Thread.sleep(1000);
assertThat(SimpleJavaJob.enabled.get()).isFalse();
removeJob(jobConfig.getJobName());
}
Aggregations