我怎样才能确认重试是否在弹簧批量实现中有效

时间:2013-03-14 11:21:08

标签: spring spring-batch

我有弹簧批处理,我想配置重试逻辑,我得到了以下配置:

<step id="roundUpMonthlyJobFetchUsers">
            <tasklet>
                <chunk reader="roundUpMonthlyItemReader" processor="roundUpMonthlyItemProcessor"
                       writer="roundUpMonthlyItemWriter" commit-interval="1" retry-limit="3" >
                    <retryable-exception-classes>
                        <include class="java.io.IOException" />
                    </retryable-exception-classes>
               </chunk>
            </tasklet>
         <end on="COMPLETED"/>
    <fail on="FAILED"/>
</step>

如何确认它实际上在遇到IOException时尝试至少执行3次操作

1 个答案:

答案 0 :(得分:0)

更改此课程roundUpMonthlyItemReader

要在条目上记录某些内容,然后每次都抛出IOException,然后检查日志:)

log.info("Reading Monthly round up");
throw new IOException("Dummy IOException");

如果您希望在单元测试中执行此操作,则应该可以使用Mockito

  • 模拟读者或作者抛出IOException
  • 确保将其调用3次