diff --git a/lts-example-tasktracker/lts-example-tasktracker-tester/pom.xml b/lts-example-tasktracker/lts-example-tasktracker-tester/pom.xml new file mode 100644 index 0000000..7320f41 --- /dev/null +++ b/lts-example-tasktracker/lts-example-tasktracker-tester/pom.xml @@ -0,0 +1,15 @@ + + + + lts-example-tasktracker + com.github.ltsopensource + 1.6.8-SNAPSHOT + + 4.0.0 + + lts-example-tasktracker-tester + + + \ No newline at end of file diff --git a/lts-example-tasktracker/lts-example-tasktracker-tester/src/main/java/com/github/ltsopensource/example/TestJobRunner.java b/lts-example-tasktracker/lts-example-tasktracker-tester/src/main/java/com/github/ltsopensource/example/TestJobRunner.java new file mode 100644 index 0000000..814e15f --- /dev/null +++ b/lts-example-tasktracker/lts-example-tasktracker-tester/src/main/java/com/github/ltsopensource/example/TestJobRunner.java @@ -0,0 +1,34 @@ +package com.github.ltsopensource.example; + +import com.github.ltsopensource.core.domain.Action; +import com.github.ltsopensource.core.logger.Logger; +import com.github.ltsopensource.core.logger.LoggerFactory; +import com.github.ltsopensource.tasktracker.Result; +import com.github.ltsopensource.tasktracker.logger.BizLogger; +import com.github.ltsopensource.tasktracker.runner.JobContext; +import com.github.ltsopensource.tasktracker.runner.JobRunner; + +/** + * @author Robert HG (254963746@qq.com) on 8/19/14. + */ +public class TestJobRunner implements JobRunner { + + private static final Logger LOGGER = LoggerFactory.getLogger(TestJobRunner.class); + + @Override + public Result run(JobContext jobContext) throws Throwable { + try { + BizLogger bizLogger = jobContext.getBizLogger(); + + // TODO 业务逻辑 + LOGGER.info("我要执行:" + jobContext); + // 会发送到 LTS (JobTracker上) + bizLogger.info("测试,业务日志啊啊啊啊啊"); + + } catch (Exception e) { + LOGGER.info("Run job failed!", e); + return new Result(Action.EXECUTE_FAILED, e.getMessage()); + } + return new Result(Action.EXECUTE_SUCCESS, "执行成功了,哈哈"); + } +} diff --git a/lts-example-tasktracker/lts-example-tasktracker-tester/src/main/java/com/github/ltsopensource/example/TestJobRunnerTester.java b/lts-example-tasktracker/lts-example-tasktracker-tester/src/main/java/com/github/ltsopensource/example/TestJobRunnerTester.java new file mode 100644 index 0000000..ba05948 --- /dev/null +++ b/lts-example-tasktracker/lts-example-tasktracker-tester/src/main/java/com/github/ltsopensource/example/TestJobRunnerTester.java @@ -0,0 +1,44 @@ +package com.github.ltsopensource.example; + +import com.github.ltsopensource.core.domain.Job; +import com.github.ltsopensource.core.json.JSON; +import com.github.ltsopensource.tasktracker.Result; +import com.github.ltsopensource.tasktracker.runner.JobContext; +import com.github.ltsopensource.tasktracker.runner.JobExtInfo; +import com.github.ltsopensource.tasktracker.runner.JobRunner; +import com.github.ltsopensource.tasktracker.runner.JobRunnerTester; + +/** + * @author Robert HG (254963746@qq.com) on 9/13/15. + */ +public class TestJobRunnerTester extends JobRunnerTester { + + public static void main(String[] args) throws Throwable { + // Mock Job 数据 + Job job = new Job(); + job.setTaskId("2313213"); + + JobContext jobContext = new JobContext(); + jobContext.setJob(job); + + JobExtInfo jobExtInfo = new JobExtInfo(); + jobExtInfo.setRetry(false); + + jobContext.setJobExtInfo(jobExtInfo); + + // 运行测试 + TestJobRunnerTester tester = new TestJobRunnerTester(); + Result result = tester.run(jobContext); + System.out.println(JSON.toJSONString(result)); + } + + @Override + protected void initContext() { + // TODO 初始化Spring容器 + } + + @Override + protected JobRunner newJobRunner() { + return new TestJobRunner(); + } +} diff --git a/lts-example-tasktracker/pom.xml b/lts-example-tasktracker/pom.xml index b5d64e1..b052c30 100644 --- a/lts-example-tasktracker/pom.xml +++ b/lts-example-tasktracker/pom.xml @@ -17,6 +17,8 @@ lts-example-tasktracker-spring-xml-shard lts-example-tasktracker-spring-annotation lts-example-tasktracker-springboot-shard + ../lts-example-tasktrackerlts-example-tasktracker-tester + lts-example-tasktracker-tester lts-example-tasktracker