Search in sources :

Example 41 with FinishCheck

use of com.vip.saturn.it.base.FinishCheck 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 42 with FinishCheck

use of com.vip.saturn.it.base.FinishCheck 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)

Example 43 with FinishCheck

use of com.vip.saturn.it.base.FinishCheck in project Saturn by vipshop.

the class ScriptJobIT method test_A_Normalsh.

@Test
public void test_A_Normalsh() throws Exception {
    if (!OS.isFamilyUnix()) {
        return;
    }
    startOneNewExecutorList();
    final String jobName = "test_A_Normalsh";
    JobConfig jobConfig = new JobConfig();
    jobConfig.setJobName(jobName);
    jobConfig.setCron("*/4 * * * * ?");
    jobConfig.setJobType(JobType.SHELL_JOB.toString());
    jobConfig.setShardingTotalCount(1);
    jobConfig.setProcessCountIntervalSeconds(1);
    jobConfig.setShardingItemParameters("0=sh " + NORMAL_SH_PATH);
    addJob(jobConfig);
    Thread.sleep(1000);
    enableJob(jobName);
    Thread.sleep(1000);
    try {
        waitForFinish(new FinishCheck() {

            @Override
            public boolean isOk() {
                String count = zkGetJobNode(jobName, "servers/" + saturnExecutorList.get(0).getExecutorName() + "/processSuccessCount");
                log.info("success count: {}", count);
                int cc = Integer.parseInt(count);
                if (cc > 0) {
                    return true;
                }
                return false;
            }
        }, 15);
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
    disableJob(jobName);
    Thread.sleep(1000);
    removeJob(jobName);
}
Also used : FinishCheck(com.vip.saturn.it.base.FinishCheck) JobConfig(com.vip.saturn.job.console.domain.JobConfig)

Example 44 with FinishCheck

use of com.vip.saturn.it.base.FinishCheck 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();
}
Also used : FinishCheck(com.vip.saturn.it.base.FinishCheck) Main(com.vip.saturn.job.executor.Main) JobConfig(com.vip.saturn.job.console.domain.JobConfig) LongtimeJavaJob(com.vip.saturn.it.job.LongtimeJavaJob)

Example 45 with FinishCheck

use of com.vip.saturn.it.base.FinishCheck 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();
}
Also used : UpdateCronJob(com.vip.saturn.it.job.UpdateCronJob) 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) Test(org.junit.Test)

Aggregations

FinishCheck (com.vip.saturn.it.base.FinishCheck)45 JobConfig (com.vip.saturn.job.console.domain.JobConfig)45 SimpleJavaJob (com.vip.saturn.it.job.SimpleJavaJob)28 Main (com.vip.saturn.job.executor.Main)26 Test (org.junit.Test)23 LongtimeJavaJob (com.vip.saturn.it.job.LongtimeJavaJob)12 Collection (java.util.Collection)5 Random (java.util.Random)2 Signal (sun.misc.Signal)2 ILoggingEvent (ch.qos.logback.classic.spi.ILoggingEvent)1 IThrowableProxy (ch.qos.logback.classic.spi.IThrowableProxy)1 UpdateCronJob (com.vip.saturn.it.job.UpdateCronJob)1 JobA (com.vip.saturn.it.job.downStream.JobA)1 JobB (com.vip.saturn.it.job.downStream.JobB)1 LogbackListAppender (com.vip.saturn.it.utils.LogbackListAppender)1 UpdateJobConfigVo (com.vip.saturn.job.console.vo.UpdateJobConfigVo)1 CuratorFramework (org.apache.curator.framework.CuratorFramework)1