I have a class that uses a ThreadPoolTaskExecutor to spin off tasks that interact with a database. My integration tests for the task are failing, I think because they rely on test data inserted through DataSourceTransactionManager, and the spin-off threads are not seeing the transaction from the main class and thus aren’t retrieving anything from the database. Is there any way to get the threads to see the inserted test data, without having to commit the transaction and delete the test data later?
I have a class that uses a ThreadPoolTaskExecutor to spin off tasks that interact
Share
It’s a pretty common pattern to insert test data into a test database which is cleared in the
finallyblock at the end of the test. If you edit your question and provide additional reasons why you are against that solution, I’ll edit my answer.The
setup()method, where typically the test database tables are created, is another good place to make sure the new tables are cleared of any left over data from previous tests, before test data gets inserted.Hope this helps.