Search in sources :

Example 56 with JobConfig

use of com.vip.saturn.job.console.domain.JobConfig in project Saturn by vipshop.

the class ForceStopJobIT method test_A_forceStopITJob.

/**
 * 作业STOPPING时立即强制终止
 */
@Test
public void test_A_forceStopITJob() throws Exception {
    final int shardCount = 3;
    final String jobName = "test_A_forceStopITJob";
    for (int i = 0; i < shardCount; i++) {
        String key = jobName + "_" + i;
        LongtimeJavaJob.JobStatus status = new LongtimeJavaJob.JobStatus();
        status.runningCount = 0;
        status.sleepSeconds = 60;
        status.finished = false;
        status.beforeTimeout = false;
        status.timeout = false;
        LongtimeJavaJob.statusMap.put(key, status);
    }
    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.setTimeoutSeconds(0);
    jobConfig.setShardingItemParameters("0=0,1=1,2=2");
    addJob(jobConfig);
    Thread.sleep(1000);
    enableJob(jobName);
    Thread.sleep(1000);
    runAtOnce(jobName);
    Thread.sleep(2000);
    disableJob(jobName);
    Thread.sleep(1000);
    forceStopJob(jobName);
    Thread.sleep(1000);
    try {
        waitForFinish(new FinishCheck() {

            @Override
            public boolean isOk() {
                Collection<LongtimeJavaJob.JobStatus> values = LongtimeJavaJob.statusMap.values();
                for (LongtimeJavaJob.JobStatus status : values) {
                    if (!status.interrupted) {
                        return false;
                    }
                    if (status.beforeKilled != 1) {
                        return false;
                    }
                    if (!status.finished || status.killed != 2) {
                        return false;
                    }
                }
                return true;
            }
        }, 30);
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
    for (int j = 0; j < shardCount; j++) {
        String key = jobName + "_" + j;
        LongtimeJavaJob.JobStatus status = LongtimeJavaJob.statusMap.get(key);
        assertThat(status.runningCount).isEqualTo(0);
        String path = JobNodePath.getNodeFullPath(jobName, ExecutionNode.getCompletedNode(j));
        assertThat(regCenter.isExisted(path)).isEqualTo(true);
    }
    enableJob(jobName);
    Thread.sleep(2000);
    for (int i = 0; i < shardCount; i++) {
        String key = jobName + "_" + i;
        LongtimeJavaJob.JobStatus status = new LongtimeJavaJob.JobStatus();
        status.runningCount = 0;
        status.sleepSeconds = 1;
        status.finished = false;
        status.beforeTimeout = false;
        status.timeout = false;
        LongtimeJavaJob.statusMap.put(key, status);
    }
    runAtOnce(jobName);
    try {
        waitForFinish(new FinishCheck() {

            @Override
            public boolean isOk() {
                for (int i = 0; i < shardCount; i++) {
                    String key = jobName + "_" + i;
                    LongtimeJavaJob.JobStatus status = LongtimeJavaJob.statusMap.get(key);
                    if (status.runningCount == 0) {
                        return false;
                    }
                }
                return true;
            }
        }, 30);
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
    disableJob(jobName);
    Thread.sleep(1000);
    removeJob(jobName);
    LongtimeJavaJob.statusMap.clear();
}
Also used : FinishCheck(com.vip.saturn.it.base.FinishCheck) Collection(java.util.Collection) JobConfig(com.vip.saturn.job.console.domain.JobConfig) LongtimeJavaJob(com.vip.saturn.it.job.LongtimeJavaJob)

Example 57 with JobConfig

use of com.vip.saturn.job.console.domain.JobConfig in project Saturn by vipshop.

the class InitJobFailAlarmIT method testE_ClassNotFoundException.

@Test
public void testE_ClassNotFoundException() throws Exception {
    String executorName = startOneNewExecutorList().getExecutorName();
    Thread.sleep(1000);
    JobConfig jobConfig = new JobConfig();
    jobConfig.setJobName("testE_ClassNotFoundException");
    jobConfig.setCron("*/2 * * * * ?");
    jobConfig.setJobType(JobType.JAVA_JOB.toString());
    jobConfig.setJobClass("WhoAmI");
    jobConfig.setShardingTotalCount(1);
    jobConfig.setShardingItemParameters("0=0");
    addJob(jobConfig);
    Thread.sleep(2000);
    assertThat(InitNewJobService.containsJobInitFailedRecord(executorName, jobConfig.getJobName(), "java.lang.ClassNotFoundException: WhoAmI")).isTrue();
    removeJob(jobConfig.getJobName());
}
Also used : JobConfig(com.vip.saturn.job.console.domain.JobConfig)

Example 58 with JobConfig

use of com.vip.saturn.job.console.domain.JobConfig in project Saturn by vipshop.

the class InitJobFailAlarmIT method testG_multiRecord.

@Test
public void testG_multiRecord() throws Exception {
    String executorName = startOneNewExecutorList().getExecutorName();
    Thread.sleep(1000);
    JobConfig jobConfig = new JobConfig();
    jobConfig.setJobName("testG_multiRecord");
    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());
    jobConfig.setJobClass("WhoAmI");
    addJob(jobConfig);
    Thread.sleep(2000);
    assertThat(InitNewJobService.containsJobInitFailedRecord(executorName, jobConfig.getJobName(), "jobClass is not set")).isTrue();
    assertThat(InitNewJobService.containsJobInitFailedRecord(executorName, jobConfig.getJobName(), "java.lang.ClassNotFoundException: WhoAmI")).isTrue();
    removeJob(jobConfig.getJobName());
}
Also used : JobConfig(com.vip.saturn.job.console.domain.JobConfig)

Example 59 with JobConfig

use of com.vip.saturn.job.console.domain.JobConfig in project Saturn by vipshop.

the class InitJobFailAlarmIT method testB_InitFailOfDefaultConstructorJob.

@Test
public void testB_InitFailOfDefaultConstructorJob() throws Exception {
    String executorName = startOneNewExecutorList().getExecutorName();
    Thread.sleep(1000);
    JobConfig jobConfig = new JobConfig();
    jobConfig.setJobName("testB_InitFailOfDefaultConstructorJob");
    jobConfig.setCron("*/2 * * * * ?");
    jobConfig.setJobType(JobType.JAVA_JOB.toString());
    jobConfig.setJobClass(InitFailOfDefaultConstructorJob.class.getCanonicalName());
    jobConfig.setShardingTotalCount(1);
    jobConfig.setShardingItemParameters("0=0");
    addJob(jobConfig);
    Thread.sleep(2000);
    assertThat(InitNewJobService.containsJobInitFailedRecord(executorName, jobConfig.getJobName(), "java.lang.ArithmeticException: / by zero")).isTrue();
    removeJob(jobConfig.getJobName());
}
Also used : JobConfig(com.vip.saturn.job.console.domain.JobConfig)

Example 60 with JobConfig

use of com.vip.saturn.job.console.domain.JobConfig in project Saturn by vipshop.

the class InitJobFailAlarmIT method testD_InitFailOfErrorJob.

@Test
public void testD_InitFailOfErrorJob() throws Exception {
    String executorName = startOneNewExecutorList().getExecutorName();
    Thread.sleep(1000);
    JobConfig jobConfig = new JobConfig();
    jobConfig.setJobName("testD_InitFailOfErrorJob");
    jobConfig.setCron("*/2 * * * * ?");
    jobConfig.setJobType(JobType.JAVA_JOB.toString());
    jobConfig.setJobClass(InitFailOfErrorJob.class.getCanonicalName());
    jobConfig.setShardingTotalCount(1);
    jobConfig.setShardingItemParameters("0=0");
    addJob(jobConfig);
    Thread.sleep(2000);
    assertThat(InitNewJobService.containsJobInitFailedRecord(executorName, jobConfig.getJobName(), "java.lang.Error: Error!!!")).isTrue();
    removeJob(jobConfig.getJobName());
}
Also used : JobConfig(com.vip.saturn.job.console.domain.JobConfig)

Aggregations

JobConfig (com.vip.saturn.job.console.domain.JobConfig)89 FinishCheck (com.vip.saturn.it.base.FinishCheck)45 SimpleJavaJob (com.vip.saturn.it.job.SimpleJavaJob)37 Test (org.junit.Test)35 Main (com.vip.saturn.job.executor.Main)31 LongtimeJavaJob (com.vip.saturn.it.job.LongtimeJavaJob)12 SaturnJobConsoleException (com.vip.saturn.job.console.exception.SaturnJobConsoleException)10 SaturnJobConsoleHttpException (com.vip.saturn.job.console.exception.SaturnJobConsoleHttpException)9 List (java.util.List)6 Collection (java.util.Collection)5 Map (java.util.Map)4 InitByGroupsJob (com.vip.saturn.it.job.InitByGroupsJob)3 CuratorRepository (com.vip.saturn.job.console.repository.zookeeper.CuratorRepository)3 ArrayList (java.util.ArrayList)3 ResponseEntity (org.springframework.http.ResponseEntity)3 Audit (com.vip.saturn.job.console.aop.annotation.Audit)2 JobDiffInfo (com.vip.saturn.job.console.domain.JobDiffInfo)2 RestApiJobConfig (com.vip.saturn.job.console.domain.RestApiJobConfig)2 JobConfig4DB (com.vip.saturn.job.console.mybatis.entity.JobConfig4DB)2 ParseException (java.text.ParseException)2