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);
}
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);
}
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);
}
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);
}
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;
}
Aggregations