allow-restart-if-completeの挙動を確かめてみる
TweetPosted on Monday Feb 10, 2014 at 06:48PM in Technology
jbatchでは異常終了したジョブの再実行が可能である。再実行の際、正常終了したStepを再度実行するかどうかはジョブXML内のstep要素のallow-restart-if-complete属性で制御できる。これを実験してみる
環境
- WildFly8.0.0.Final
- その他はArquillianでジョブのテストをしてみると同じ
環境・前提条件
- Arquillianでジョブのテストをしてみるで作ったプロジェクトが普通に動いているものとする
準備
必要な資源の詳細はこのへんを参照
バッチ資源
aric.xml (ジョブXML)
- Stepが3つある
- あるジョブ引数を与えるとStep3で例外が起こりジョブが死ぬ
- Step1のみallow-restart-if-complete=trueになっている(デフォルトはfalse[1])
- Step1は再実行時も動く
- Step2は再実行時は動かない
ExceptionBatchlet.java
- 3つのStepは全部これを使っている
- @BatchPropertyで与えられる引数がtrueの場合例外を投げる
テスト用資源
AbstractJobTest.java
- 再実行用のメソッドがなかったので追加してある
ARICJobTest.java (テストクラス)
- テスト内容は以下
- 一旦ジョブを実行した後にexecutionIdを使って再実行する
- 初回実行時は異常終了(Step3で例外を出させる)
- 再実行時は正常終了(Step3で例外を出させない)
テストクラスを実行してみる
ログ
17:09:14,004 FINE [org.nailedtothex.jbatch.example.aric.ExceptionBatchlet] (batch-batch - 4) process(): stepName=step1, exception=null 17:09:14,008 FINE [org.nailedtothex.jbatch.example.aric.ExceptionBatchlet] (batch-batch - 4) process(): stepName=step2, exception=null 17:09:14,012 FINE [org.nailedtothex.jbatch.example.aric.ExceptionBatchlet] (batch-batch - 4) process(): stepName=step3, exception=true 17:09:14,013 WARN [org.jberet] (batch-batch - 4) JBERET000001: Failed to run batchlet org.jberet.job.model.RefArtifact@694eb7ca: java.lang.RuntimeException: true at org.nailedtothex.jbatch.example.aric.ExceptionBatchlet.process(ExceptionBatchlet.java:28) [classes:] at org.jberet.runtime.runner.BatchletRunner.run(BatchletRunner.java:61) [jberet-core-1.0.0.Final.jar:1.0.0.Final] at org.jberet.runtime.runner.StepExecutionRunner.runBatchletOrChunk(StepExecutionRunner.java:207) [jberet-core-1.0.0.Final.jar:1.0.0.Final] at org.jberet.runtime.runner.StepExecutionRunner.run(StepExecutionRunner.java:131) [jberet-core-1.0.0.Final.jar:1.0.0.Final] at org.jberet.runtime.runner.CompositeExecutionRunner.runStep(CompositeExecutionRunner.java:162) [jberet-core-1.0.0.Final.jar:1.0.0.Final] at org.jberet.runtime.runner.CompositeExecutionRunner.runJobElement(CompositeExecutionRunner.java:126) [jberet-core-1.0.0.Final.jar:1.0.0.Final] at org.jberet.runtime.runner.StepExecutionRunner.run(StepExecutionRunner.java:177) [jberet-core-1.0.0.Final.jar:1.0.0.Final] at org.jberet.runtime.runner.CompositeExecutionRunner.runStep(CompositeExecutionRunner.java:162) [jberet-core-1.0.0.Final.jar:1.0.0.Final] at org.jberet.runtime.runner.CompositeExecutionRunner.runJobElement(CompositeExecutionRunner.java:126) [jberet-core-1.0.0.Final.jar:1.0.0.Final] at org.jberet.runtime.runner.StepExecutionRunner.run(StepExecutionRunner.java:177) [jberet-core-1.0.0.Final.jar:1.0.0.Final] at org.jberet.runtime.runner.CompositeExecutionRunner.runStep(CompositeExecutionRunner.java:162) [jberet-core-1.0.0.Final.jar:1.0.0.Final] at org.jberet.runtime.runner.CompositeExecutionRunner.runFromHeadOrRestartPoint(CompositeExecutionRunner.java:88) [jberet-core-1.0.0.Final.jar:1.0.0.Final] at org.jberet.runtime.runner.JobExecutionRunner.run(JobExecutionRunner.java:58) [jberet-core-1.0.0.Final.jar:1.0.0.Final] at org.wildfly.jberet.services.BatchEnvironmentService$WildFlyBatchEnvironment$1.run(BatchEnvironmentService.java:149) [wildfly-jberet-8.0.0.Final.jar:8.0.0.Final] at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471) [rt.jar:1.7.0_51] at java.util.concurrent.FutureTask.run(FutureTask.java:262) [rt.jar:1.7.0_51] at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [rt.jar:1.7.0_51] at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [rt.jar:1.7.0_51] at java.lang.Thread.run(Thread.java:744) [rt.jar:1.7.0_51] at org.jboss.threads.JBossThread.run(JBossThread.java:122) 17:09:15,013 FINE [org.nailedtothex.jbatch.example.aric.ExceptionBatchlet] (batch-batch - 8) process(): stepName=step1, exception=null 17:09:15,017 FINE [org.nailedtothex.jbatch.example.aric.ExceptionBatchlet] (batch-batch - 8) process(): stepName=step3, exception=false
Repository
job_execution
jbatch=# select * from job_execution where jobexecutionid in (21, 22); jobexecutionid | jobinstanceid | version | createtime | starttime | endtime | lastupdatedtime | batchstatus | exitstatus | jobparameters | restartposition ----------------+---------------+---------+-------------------------+-------------------------+-------------------------+-------------------------+-------------+------------+---------------------+----------------- 21 | 20 | | 2014-02-13 17:09:14.001 | 2014-02-13 17:09:14.001 | 2014-02-13 17:09:14.016 | 2014-02-13 17:09:14.016 | FAILED | FAILED | failAtStep3 = true +| | | | | | | | | | | 22 | 20 | | 2014-02-13 17:09:15.01 | 2014-02-13 17:09:15.01 | 2014-02-13 17:09:15.019 | 2014-02-13 17:09:15.019 | COMPLETED | COMPLETED | failAtStep3 = false+| | | | | | | | | | | (2 rows) jbatch=#
step_execution
jbatch=# select * from step_execution where jobexecutionid in (21, 22) order by jobexecutionid, stepexecutionid; stepexecutionid | jobexecutionid | version | stepname | starttime | endtime | batchstatus | exitstatus | executionexception | persistentuserdata | readcount | writecount | commitcount | rollbackcount | readskipcount | processskipcount | filtercount | writeskipcount | readercheckpointinfo | writercheckpointinfo -----------------+----------------+---------+----------+-------------------------+-------------------------+-------------+------------+--------------------------------------------------------------------------------------------------------------------------------+--------------------+-----------+------------+-------------+---------------+---------------+------------------+-------------+----------------+----------------------+---------------------- 34 | 21 | | step1 | 2014-02-13 17:09:14.002 | 2014-02-13 17:09:14.005 | COMPLETED | SUCCESS | | | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | | 35 | 21 | | step2 | 2014-02-13 17:09:14.007 | 2014-02-13 17:09:14.008 | COMPLETED | SUCCESS | | | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | | 36 | 21 | | step3 | 2014-02-13 17:09:14.011 | 2014-02-13 17:09:14.014 | FAILED | FAILED | java.lang.RuntimeException: true +| | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | | | | | | | | | | at org.nailedtothex.jbatch.example.aric.ExceptionBatchlet.process(ExceptionBatchlet.java:28) +| | | | | | | | | | | | | | | | | | | at org.jberet.runtime.runner.BatchletRunner.run(BatchletRunner.java:61) +| | | | | | | | | | | | | | | | | | | at org.jberet.runtime.runner.StepExecutionRunner.runBatchletOrChunk(StepExecutionRunner.java:207) +| | | | | | | | | | | | | | | | | | | at org.jberet.runtime.runner.StepExecutionRunner.run(StepExecutionRunner.java:131) +| | | | | | | | | | | | | | | | | | | at org.jberet.runtime.runner.CompositeExecutionRunner.runStep(CompositeExecutionRunner.java:162) +| | | | | | | | | | | | | | | | | | | at org.jberet.runtime.runner.CompositeExecutionRunner.runJobElement(CompositeExecutionRunner.java:126) +| | | | | | | | | | | | | | | | | | | at org.jberet.runtime.runner.StepExecutionRunner.run(StepExecutionRunner.java:177) +| | | | | | | | | | | | | | | | | | | at org.jberet.runtime.runner.CompositeExecutionRunner.runStep(CompositeExecutionRunner.java:162) +| | | | | | | | | | | | | | | | | | | at org.jberet.runtime.runner.CompositeExecutionRunner.runJobElement(CompositeExecutionRunner.java:126) +| | | | | | | | | | | | | | | | | | | at org.jberet.runtime.runner.StepExecutionRunner.run(StepExecutionRunner.java:177) +| | | | | | | | | | | | | | | | | | | at org.jberet.runtime.runner.CompositeExecutionRunner.runStep(CompositeExecutionRunner.java:162) +| | | | | | | | | | | | | | | | | | | at org.jberet.runtime.runner.CompositeExecutionRunner.runFromHeadOrRestartPoint(CompositeExecutionRunner.java:88) +| | | | | | | | | | | | | | | | | | | at org.jberet.runtime.runner.JobExecutionRunner.run(JobExecutionRunner.java:58) +| | | | | | | | | | | | | | | | | | | at org.wildfly.jberet.services.BatchEnvironmentService$WildFlyBatchEnvironment$1.run(BatchEnvironmentService.java:149)+| | | | | | | | | | | | | | | | | | | at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471) +| | | | | | | | | | | | | | | | | | | at java.util.concurrent.FutureTask.run(FutureTask.java:262) +| | | | | | | | | | | | | | | | | | | at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) +| | | | | | | | | | | | | | | | | | | at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) +| | | | | | | | | | | | | | | | | | | at java.lang.Thread.run(Thread.java:744) +| | | | | | | | | | | | | | | | | | | at org.jboss.threads.JBossThread.run(JBossThread.java:122) +| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 37 | 22 | | step1 | 2014-02-13 17:09:15.011 | 2014-02-13 17:09:15.013 | COMPLETED | SUCCESS | | | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | | 38 | 22 | | step3 | 2014-02-13 17:09:15.016 | 2014-02-13 17:09:15.017 | COMPLETED | SUCCESS | | | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | | (5 rows) jbatch=#
- 問題無さげ
- 初回実行時はstep1, step2, step3が動いて異常終了
- 再実行時はstep1, step3が動いて正常終了
参考文献
Tags: jbatch