在 Spring-Batch 中测试作业流程的最佳方法是什么? [英] What is the best way to test job flow in Spring-Batch?

查看:41
本文介绍了在 Spring-Batch 中测试作业流程的最佳方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个复杂的批处理应用程序,我想测试我对流的假设是否正确.

I've got a complicated batch application, and I want to test that my assumptions about flow are correct.

这是我正在使用的简化版本:

Here's a much simplified version of what I'm working with:

<beans>
  <batch:job id="job1">
    <batch:step id="step1" next="step2">
      <batch:tasklet ref="someTask1"/>
    </batch:step>
    <batch:step id="step2.master">
      <batch:partition partitioner="step2Partitioner"
            step="step2" />
      <batch:next on="*" to="step3" />
      <batch:next on="FAILED" to="step4" />
    </batch:step>
    <batch:step id="step3" next="step3">
      <batch:tasklet ref="someTask1"/>
    </batch:step>
    <batch:step id="step4" next="step4">
      <batch:tasklet ref="someTask1"/>
    </batch:step>
  </batch:job>
  <batch:job id="job2">
    <batch:step id="failingStep">
      <batch:tasklet ref="failingTasklet"/>
    </batch:step>
  </batch:job>

  <bean id="step2Partitioner" class="org.springframework.batch.core.partition.support.MultiResourcePartitioner" scope="step">
    <property name="resources" value="file:${file.test.resources}/*" />
  </bean>

  <bean id="step2" class="org.springframework.batch.core.step.job.JobStep">
    <property name="job" ref="job2" />
    <property name="jobLauncher" ref="jobLauncher" />
    <property name="jobRepository" ref="jobRepository" />
  </bean>
</beans>

Job1 是我要测试的工作.我真的只想测试 step2.master 到 step3 或 step4 的过渡.我根本不想测试 step1...

Job1 is the job I want to test. I really only want to test the transition of step2.master to step3 or step4. I don't want to test step1 at all...

但是,我想保持 Job1 的规范不变,因为这个测试是测试配置,而不是底层操作.我已经有验收测试来测试端到端的东西.这个例子让我可以为小的变化编写有针对性的测试,而无需为每个边缘情况创建单独的端到端测试.

However, I want to keep Job1's specification intact, since this test is testing the configuration, not the underlying actions. I already have acceptance tests to test end-to-end stuff. This example is so I can write targeted tests for small variations without creating seperate end-to-end tests for each edge case.

我想测试的是,当 step2 中的作业失败时,step2.master 会将我转到第 4 步而不是第 3 步.有没有好的方法可以测试这个?

What I want to test is that when the job inside step2 fails, step2.master will forward me on to step 4 and not step 3. Is there a good way to test this?

推荐答案

你可以用一个总是失败的模拟实现替换 step2,并使用 StepExecutionListener 来检查 step3 和 step4 是否被调用.

You can replace step2 with a mock implementation that always fail and use a StepExecutionListener to check whether or not step3 and step4 were called.

这里有很好的例子:http://static.springsource.org/spring-batch/reference/html/testing.html#endToEndTesting

这篇关于在 Spring-Batch 中测试作业流程的最佳方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆