Search in sources :

Example 1 with LogbackListAppender

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

Aggregations

ILoggingEvent (ch.qos.logback.classic.spi.ILoggingEvent)1 IThrowableProxy (ch.qos.logback.classic.spi.IThrowableProxy)1 FinishCheck (com.vip.saturn.it.base.FinishCheck)1 SimpleJavaJob (com.vip.saturn.it.job.SimpleJavaJob)1 LogbackListAppender (com.vip.saturn.it.utils.LogbackListAppender)1 JobConfig (com.vip.saturn.job.console.domain.JobConfig)1