I did some badness today.
I wanted an integration test to check to see if my @Transactional method actually did rollback on an optimistic lock failure. It’s a pretty business critical method so I wanted to be sure that the whole @Transactional and @Version annotation voodoo actually works.
The approach I took was to inject, what I called a “slowRepository” into the object with the @Transactional method. The slowRepository is just a mockito mock of the object which “answers” (using “thenAnswer”) to the “findBy…” with some custom code.
The idea is that at some point during the @Transactional method the slowRepository is called and the “answer” code is invoked. In the test, the answer code follows along the lines of:
1. Grab the data it requires from the (not slow) repository (the repository the slowRepository is mocking)
2. Switch back the slowRepository for the not slow repository
3. Invoke the @Transactional method again on a separate thread
4. Sleep for a bit
5. Wake up and return the data from step 1
The @Transactional call on the separate thread completes and commits before slowRepository wakes up. When it does, slowRepository returns stale data and the @Transactional method then fails accordingly.
The problem I encountered was using the setters for my @Autowired dependencies on the bean with the @Transactional method. I needed to use the setters so that I could switch in and out the slowRepository, but couldn’t because Spring AOP proxies are implementations of an interface, not subclasses (by default – yes I realise you can get Spring to proxy the target class using CGLIB). I found this blog post which explains how to get at the target object behind a Spring proxy. I converted it to Scala:
…which is pretty ninja.
mostbet kupon kodu daxil et http://mostbet85214.help/
https://telegra.ph/Bolt-tv-programma-11-15
https://site861689192.fo.team
https://site595425127.fo.team
mostbet ilovasi rasmiy mostbet ilovasi rasmiy
https://rentry.co/uc8akpwz
https://site553566938.fo.team
$5 deposit pokies australia, fastest paying casino usa and united statesn casino guide blackjack chart, or free spin casino no deposit united states
My blog … earn money online surveys singapore (Lily)
сео фирмы сео фирмы .
заказать суши заказать суши .
успешные seo кейсы санкт петербург успешные seo кейсы санкт петербург .
mostbet hesabı deaktiv etmək mostbet hesabı deaktiv etmək
mostbet cashback hesablanmır https://www.mostbet85214.help
рейтинг digital компаний luchshie-digital-agencstva.ru .
https://telegra.ph/Kupit-zhurnaly-po-ohrane-truda-01-06
как продавать сайты как продавать сайты .
https://paiza.io/projects/FvwATcQZVjbOcsWaMXfR1A
https://rentry.co/5g4d3q3r
https://snippet.host/iszprr
купить дженерик Дзержинск
продвижение по трафику сео prodvizhenie-sajtov-po-trafiku10.ru .
https://e6h4us.zombeek.cz
https://teletype.link/distinguishedwhz939
сео портала увеличить трафик специалисты prodvizhenie-sajtov-po-trafiku11.ru .
попперс адрес
mostbet кэшбэк https://www.mostbet34518.help
https://site811175842.fo.team
https://rentry.co/73amcmvr
сиалис в рязани цена
отравление попперсом
https://rentry.co/vrvga5kb
https://rentry.co/6r5gesz4
левитра Ачинск
рейтинг спортивных сайтов рейтинг спортивных сайтов .
топ сео компаний топ сео компаний .
продажа сайта kak-prodat-sajt.ru .
https://paiza.io/projects/zR8Ce8pPOiqhNPPXRxKejg
отзывы о препаратах повышающих потенцию
https://www.bitsdujour.com/profiles/J4nNJ4
https://site361304892.fo.team
мелбет кз зеркало если сайт заблокирован http://www.melbet39518.help
https://site102278285.fo.team
https://vcook.jp/users/77739
биржа сайтов биржа сайтов .
https://lnaayg.zombeek.cz
попперс reds
https://telegra.ph/Kak-dokazat-chto-treugolnik-pryamougolnyj-11-19
https://paiza.io/projects/4jbguQYqtNKlh2USS4bLrQ
сиалис 5 мг Саратов
купить попперс Якутск