Perhaps, I am doing something wrong, but I can't find a good way out for the following situation.
I would like to unit test a service that uses Spring Batch underneath to execute jobs. The jobs are executed via pre-configured AsyncTaskExecutor
in separate threads. In my unit test I would like to:
- Create few domain objects and persist them via DAO
- Invoke the service method to launch the job
- Wait until the job is completed
- Use DAO to retrieve domain objects and check their state
Obviously, all above should be executed within one transaction, but unfortunately, transactions are not propagated to new threads (I understand the rationale behind this).
Ideas that came to my mind:
- Commit the transaction#1 after step (1). Is not good, as the DB state should be rolled back after the unit test.
- Use
Isolation.READ_UNCOMMITTED
in job configuration. But this requires two different configurations for test and for production.