Search in sources :

Example 6 with SaturnJobReturn

use of com.vip.saturn.job.SaturnJobReturn in project Saturn by vipshop.

the class JsonParseObjectTest method test_E_lessFieldReturnCode.

/**
 * 少returnCode,默认为0
 */
@Test
public void test_E_lessFieldReturnCode() throws Exception {
    LogbackListAppender logbackListAppender = new LogbackListAppender();
    logbackListAppender.addToLogger(ScriptJobRunner.class);
    logbackListAppender.start();
    SaturnJobReturn saturnJobReturn = readSaturnJobReturn("/SaturnJobReturnLessFieldReturnCode");
    SaturnJobReturn expect = new SaturnJobReturn(0, "hello world", 200);
    HashMap<String, String> prop = new HashMap();
    prop.put("key", "value");
    expect.setProp(prop);
    assertThat(logbackListAppender.getLastMessage()).isNull();
    assertThat(saturnJobReturn).isNotNull().isEqualToComparingFieldByField(expect);
}
Also used : SaturnJobReturn(com.vip.saturn.job.SaturnJobReturn) LogbackListAppender(com.vip.saturn.job.executor.utils.LogbackListAppender) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 7 with SaturnJobReturn

use of com.vip.saturn.job.SaturnJobReturn in project Saturn by vipshop.

the class JsonParseObjectTest method test_A_normal.

@Test
public void test_A_normal() throws Exception {
    LogbackListAppender logbackListAppender = new LogbackListAppender();
    logbackListAppender.addToLogger(ScriptJobRunner.class);
    logbackListAppender.start();
    SaturnJobReturn saturnJobReturn = readSaturnJobReturn("/SaturnJobReturnNormal");
    SaturnJobReturn expect = new SaturnJobReturn(500, "hello world", 200);
    HashMap<String, String> prop = new HashMap();
    prop.put("key", "value");
    expect.setProp(prop);
    assertThat(logbackListAppender.getLastMessage()).isNull();
    assertThat(saturnJobReturn).isNotNull().isEqualToComparingFieldByField(expect);
}
Also used : SaturnJobReturn(com.vip.saturn.job.SaturnJobReturn) LogbackListAppender(com.vip.saturn.job.executor.utils.LogbackListAppender) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 8 with SaturnJobReturn

use of com.vip.saturn.job.SaturnJobReturn in project Saturn by vipshop.

the class JsonParseObjectTest method test_D_lessFieldProp.

/**
 * 少prop,默认为空
 */
@Test
public void test_D_lessFieldProp() throws Exception {
    LogbackListAppender logbackListAppender = new LogbackListAppender();
    logbackListAppender.addToLogger(ScriptJobRunner.class);
    logbackListAppender.start();
    SaturnJobReturn saturnJobReturn = readSaturnJobReturn("/SaturnJobReturnLessFieldProp");
    SaturnJobReturn expect = new SaturnJobReturn(500, "hello world", 200);
    assertThat(logbackListAppender.getLastMessage()).isNull();
    assertThat(saturnJobReturn).isNotNull().isEqualToComparingFieldByField(expect);
}
Also used : SaturnJobReturn(com.vip.saturn.job.SaturnJobReturn) LogbackListAppender(com.vip.saturn.job.executor.utils.LogbackListAppender) Test(org.junit.Test)

Example 9 with SaturnJobReturn

use of com.vip.saturn.job.SaturnJobReturn in project Saturn by vipshop.

the class JsonParseObjectTest method test_F_lessFieldReturnMsg.

/**
 * 少returnMsg,默认为空
 */
@Test
public void test_F_lessFieldReturnMsg() throws Exception {
    LogbackListAppender logbackListAppender = new LogbackListAppender();
    logbackListAppender.addToLogger(ScriptJobRunner.class);
    logbackListAppender.start();
    SaturnJobReturn saturnJobReturn = readSaturnJobReturn("/SaturnJobReturnLessFieldReturnMsg");
    SaturnJobReturn expect = new SaturnJobReturn(500, null, 200);
    HashMap<String, String> prop = new HashMap();
    prop.put("key", "value");
    expect.setProp(prop);
    assertThat(logbackListAppender.getLastMessage()).isNull();
    assertThat(saturnJobReturn).isNotNull().isEqualToComparingFieldByField(expect);
}
Also used : SaturnJobReturn(com.vip.saturn.job.SaturnJobReturn) LogbackListAppender(com.vip.saturn.job.executor.utils.LogbackListAppender) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 10 with SaturnJobReturn

use of com.vip.saturn.job.SaturnJobReturn in project Saturn by vipshop.

the class JavaShardingItemCallable method call.

/**
 * 真正执行作业分片逻辑
 *
 * @return 执行结果
 */
public SaturnJobReturn call() {
    reset();
    SaturnSystemOutputStream.initLogger();
    currentThread = Thread.currentThread();
    SaturnJobReturn temp = null;
    try {
        beforeExecution();
        temp = doExecution();
        // 在此之后,不能再强制停止本线程
        breakForceStop = true;
    } catch (Throwable t) {
        // 在此之后,不能再强制停止本线程
        breakForceStop = true;
        // 不是超时,不是强制停止。 打印错误日志,设置SaturnJobReturn。
        if (status.get() != TIMEOUT && status.get() != FORCE_STOP) {
            LogUtils.error(log, jobName, t.toString(), t);
            temp = new SaturnJobReturn(SaturnSystemReturnCode.SYSTEM_FAIL, t.getMessage(), SaturnSystemErrorGroup.FAIL);
        }
    } finally {
        if (status.compareAndSet(INIT, SUCCESS)) {
            saturnJobReturn = temp;
        }
        if (saturnJob != null && saturnJob.getConfigService().showNormalLog()) {
            String jobLog = SaturnSystemOutputStream.clearAndGetLog();
            if (jobLog != null && jobLog.length() > SaturnConstant.MAX_JOB_LOG_DATA_LENGTH) {
                LogUtils.info(log, jobName, "As the job log exceed max length, only the previous {} characters will be reported", SaturnConstant.MAX_JOB_LOG_DATA_LENGTH);
                jobLog = jobLog.substring(0, SaturnConstant.MAX_JOB_LOG_DATA_LENGTH);
            }
            this.shardingContext.putJobLog(this.item, jobLog);
        }
    }
    return saturnJobReturn;
}
Also used : SaturnJobReturn(com.vip.saturn.job.SaturnJobReturn)

Aggregations

SaturnJobReturn (com.vip.saturn.job.SaturnJobReturn)35 LogbackListAppender (com.vip.saturn.job.executor.utils.LogbackListAppender)9 HashMap (java.util.HashMap)9 Test (org.junit.Test)9 Date (java.util.Date)4 JobInitAlarmException (com.vip.saturn.job.exception.JobInitAlarmException)2 UncaughtExceptionHandler (java.lang.Thread.UncaughtExceptionHandler)2 ExecutorService (java.util.concurrent.ExecutorService)2 DemoService (com.vip.saturn.demo.service.DemoService)1 SaturnExecutionContext (com.vip.saturn.job.basic.SaturnExecutionContext)1 ShardingItemCallable (com.vip.saturn.job.basic.ShardingItemCallable)1 ExecutionInfo (com.vip.saturn.job.internal.control.ExecutionInfo)1 RegException (com.vip.saturn.job.reg.exception.RegException)1 ScriptJobRunner (com.vip.saturn.job.shell.ScriptJobRunner)1 IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 CommandLine (org.apache.commons.exec.CommandLine)1