batch/scheduling tests not enough time to complete job execution
chengfang opened this issue · 1 comments
In org.javaee7.batch.samples.scheduling.TimerScheduleBatchTest#testTimeScheduleBatch, wait for 3 job executions to be executed:
MyTimerScheduleAlternative.timerScheduleCountDownLatch.await(90, TimeUnit.SECONDS); assertEquals(0, MyTimerScheduleAlternative.timerScheduleCountDownLatch.getCount()); assertEquals(3, MyTimerScheduleAlternative.executedBatchs.size());
but the 3rd job execution will not have enough time to complete. As soon as it is started in the ejb's schedule method, the latch is immediately counted down, and the above test will proceed to verify job execution result. The batch status of the 3rd job execution will still be STARTED, not COMPLETED.
Also, since the test only checks for 3 job executions, the ejb's schedule method should only start 3 job executions.
The logic here was indeed wrong, and this has been mostly rectified by adding a step listener that counts the latch down at a more appropriate time.