Search in sources :

Example 76 with JobConfig

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

the class JobOperationRestApiControllerTest method testCreateSuccessfully.

@Test
public void testCreateSuccessfully() throws Exception {
    JobEntity jobEntity = constructJobEntity("job1");
    mvc.perform(post("/rest/v1/domain/jobs").contentType(MediaType.APPLICATION_JSON).content(jobEntity.toJSON())).andExpect(status().isCreated());
    JobConfig jobConfig = convert2JobConfig("domain", jobEntity);
    ArgumentCaptor<JobConfig> argument = ArgumentCaptor.forClass(JobConfig.class);
    verify(restApiService).createJob(eq("domain"), argument.capture());
    assertTrue("jobconfig is not equal", jobConfig.equals(argument.getValue()));
}
Also used : RestApiJobConfig(com.vip.saturn.job.console.domain.RestApiJobConfig) JobConfig(com.vip.saturn.job.console.domain.JobConfig) Test(org.junit.Test) WebMvcTest(org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest) AbstractSaturnConsoleTest(com.vip.saturn.job.console.AbstractSaturnConsoleTest)

Example 77 with JobConfig

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

the class JobOverviewControllerTest method buildJobConfig.

private JobConfig buildJobConfig(String name) {
    JobConfig jobConfig = new JobConfig();
    jobConfig.setJobName(name);
    return jobConfig;
}
Also used : JobConfig(com.vip.saturn.job.console.domain.JobConfig)

Example 78 with JobConfig

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

the class LocalModeIT method test_B.

@Test
public void test_B() throws Exception {
    startExecutorList(2);
    int shardCount = 3;
    final String jobName = "test_B";
    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("*/1 * * * * ?");
    jobConfig.setJobType(JobType.JAVA_JOB.toString());
    jobConfig.setProcessCountIntervalSeconds(1);
    jobConfig.setJobClass(SimpleJavaJob.class.getCanonicalName());
    jobConfig.setShardingItemParameters("*=0");
    jobConfig.setLocalMode(true);
    addJob(jobConfig);
    Thread.sleep(1000);
    enableJob(jobName);
    Thread.sleep(1000);
    waitForFinish(new FinishCheck() {

        @Override
        public boolean isOk() {
            for (Main executor : saturnExecutorList) {
                String count = zkGetJobNode(jobName, "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;
        }
    }, 60);
    disableJob(jobName);
    Thread.sleep(1000);
    removeJob(jobName);
}
Also used : FinishCheck(com.vip.saturn.it.base.FinishCheck) SimpleJavaJob(com.vip.saturn.it.job.SimpleJavaJob) Main(com.vip.saturn.job.executor.Main) JobConfig(com.vip.saturn.job.console.domain.JobConfig)

Example 79 with JobConfig

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

the class LocalModeIT method test_D_fixIssue441.

@Test
public void test_D_fixIssue441() throws Exception {
    LogbackListAppender logbackListAppender = new LogbackListAppender();
    logbackListAppender.addToLogger(AbstractAsyncShardingTask.class);
    logbackListAppender.start();
    final int items = 4;
    final String jobName = "test_D_fixIssue441";
    JobConfig jobConfig = new JobConfig();
    jobConfig.setJobName(jobName);
    jobConfig.setCron("*/1 * * * * ?");
    jobConfig.setJobType(JobType.JAVA_JOB.toString());
    jobConfig.setProcessCountIntervalSeconds(1);
    jobConfig.setJobClass(SimpleJavaJob.class.getCanonicalName());
    jobConfig.setShardingItemParameters("*=0");
    jobConfig.setLocalMode(true);
    addJob(jobConfig);
    Thread.sleep(1000);
    enableJob(jobName);
    Thread.sleep(1000);
    startExecutorList(items);
    waitForFinish(new FinishCheck() {

        @Override
        public boolean isOk() {
            for (int i = 0; i < items; i++) {
                if (SimpleJavaJob.statusMap.get(jobName + "_" + i) <= 0) {
                    return false;
                }
            }
            return true;
        }
    }, 30);
    // 下线0,1,2
    stopExecutorGracefully(0);
    stopExecutorGracefully(1);
    stopExecutorGracefully(2);
    // 上线一个executor
    startOneNewExecutorList();
    List<ILoggingEvent> allLogs = logbackListAppender.getAllLogs();
    Iterator<ILoggingEvent> iterator = allLogs.iterator();
    while (iterator.hasNext()) {
        ILoggingEvent event = iterator.next();
        if (event != null) {
            IThrowableProxy throwableProxy = event.getThrowableProxy();
            if (throwableProxy != null) {
                assertThat(throwableProxy.getClassName()).isNotEqualTo("java.lang.ArrayIndexOutOfBoundsException");
            }
        }
    }
    disableJob(jobName);
    Thread.sleep(1000);
    removeJob(jobName);
}
Also used : LogbackListAppender(com.vip.saturn.it.utils.LogbackListAppender) IThrowableProxy(ch.qos.logback.classic.spi.IThrowableProxy) FinishCheck(com.vip.saturn.it.base.FinishCheck) SimpleJavaJob(com.vip.saturn.it.job.SimpleJavaJob) ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent) JobConfig(com.vip.saturn.job.console.domain.JobConfig)

Example 80 with JobConfig

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

the class LocalModeIT method test_C_withPreferList.

@Test
public void test_C_withPreferList() throws Exception {
    startExecutorList(2);
    int shardCount = 3;
    final String jobName = "test_C_withPreferList";
    for (int i = 0; i < shardCount; i++) {
        String key = jobName + "_" + i;
        SimpleJavaJob.statusMap.put(key, 0);
    }
    final Main preferExecutor = saturnExecutorList.get(0);
    JobConfig jobConfig = new JobConfig();
    jobConfig.setJobName(jobName);
    jobConfig.setCron("*/1 * * * * ?");
    jobConfig.setJobType(JobType.JAVA_JOB.toString());
    jobConfig.setProcessCountIntervalSeconds(1);
    jobConfig.setJobClass(SimpleJavaJob.class.getCanonicalName());
    jobConfig.setShardingItemParameters("*=0");
    jobConfig.setLocalMode(true);
    jobConfig.setPreferList(preferExecutor.getExecutorName());
    addJob(jobConfig);
    Thread.sleep(1000);
    enableJob(jobName);
    Thread.sleep(1000);
    waitForFinish(new FinishCheck() {

        @Override
        public boolean isOk() {
            String count0 = zkGetJobNode(jobName, "servers/" + preferExecutor.getExecutorName() + "/processSuccessCount");
            System.out.println("count:" + count0 + ";executor:" + preferExecutor.getExecutorName());
            if (count0 == null)
                return false;
            int times0 = Integer.parseInt(count0);
            if (times0 <= 0)
                return false;
            for (int i = 1; i < saturnExecutorList.size(); i++) {
                Main executor = saturnExecutorList.get(i);
                String count = zkGetJobNode(jobName, "servers/" + executor.getExecutorName() + "/processSuccessCount");
                System.out.println("count:" + count + ";executor:" + executor.getExecutorName());
                if (count != null) {
                    int times = Integer.parseInt(count);
                    if (times != 0)
                        return false;
                }
            }
            return true;
        }
    }, 30);
    disableJob(jobName);
    Thread.sleep(1000);
    removeJob(jobName);
}
Also used : FinishCheck(com.vip.saturn.it.base.FinishCheck) SimpleJavaJob(com.vip.saturn.it.job.SimpleJavaJob) Main(com.vip.saturn.job.executor.Main) 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