Maybe I'm doing something wrong, but I canβt find a good way out for the next situation.
I would like a unit test service that uses Spring Batch to complete tasks. Jobs run through the pre-configured AsyncTaskExecutor in separate threads. In my unit test, I would like:
- Create multiple domain objects and save them through the DAO
- Calling a service method to start a job
- Wait until the work is completed.
- Use DAO to retrieve domain objects and check their status
Obviously, all of the above should be performed within one transaction, but, unfortunately, transactions do not apply to new threads (I understand that the rationale for this).
Ideas that came to my mind:
- Commit transaction # 1 after step (1). Not good, because the state of the database should be discarded after the unit test.
- Use
Isolation.READ_UNCOMMITTED in the job configuration. But this requires two different configurations for testing and for production.
java spring multithreading transactions
dma_k
source share