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.
https://rentry.co/yip5umy5
https://1cytji.zombeek.cz
женская виагра Щёлково
https://www.investagrams.com/Profile/shanno3666373
https://telegra.ph/Perezagruzka-03-06
mostbet slotlar bepul mostbet slotlar bepul
компания seo reiting-seo-kompaniy.ru .
отзыв сиалис
gute wettanbieter
Here is my website; basketball wett tipps Heute (basketball-wetten.com)
мелбет apk download http://melbet81573.help/
https://k3eolb.zombeek.cz
https://site749714169.fo.team
mostbet скачать приложение с официального сайта http://mostbet4151.ru
https://paiza.io/projects/CvAWmli21TcEDTK73d7EXw
https://oyful8.zombeek.cz
https://www.bitsdujour.com/profiles/zDkSXN
раскрутка сайта москва раскрутка сайта москва .
магазин попперс в москве
гибридная структура сайта seo-kejsy17.ru .
vavada aktualna strona http://vavada56378.help
купить попперс в москва
https://ganc64.zombeek.cz
wett-tipps heute
Feel free to visit my site welcher wettanbieter ist der beste (gratis-wetten.com)
mostbetda registratsiya https://mostbet24618.help/
купить попперс Саратов
1win ios tələblər http://www.1win34861.help
https://gzezni.zombeek.cz
https://snippet.host/gwtpjt
заказать сео анализ сайта пушка заказать сео анализ сайта пушка .
gratiswette code
Here is my web-site; deutschland ungarn wett tipp
технического аудита сайта технического аудита сайта .
mostbet bank kartasiga yechish mostbet bank kartasiga yechish
wetten dass tickets gewinnen
my blog :: besten sportwetten bonus
vavada gry mobilne vavada gry mobilne
vavada aplikacja zakłady https://vavada56378.help/
https://telegra.ph/Smenit-11-30
https://www.diggerslist.com/adjustableedl63/about
раскрутка и продвижение сайта раскрутка и продвижение сайта .
попперс купить во владивостоке
попперс rush ultra strong
продвижение сайта франция продвижение сайта франция .
https://site620435829.fo.team
сиалис тадалафил применение
https://rentry.co/tn3rh7im
агентство seo агентство seo .
мелбет регистрация на русском melbet81573.help
можно ли использовать виагра с алкоголем
поисковое seo в москве поисковое seo в москве .
mostbet sayt kirish muammo mostbet24618.help
https://telegra.ph/Ne-za-chto-ili-ne-za-chto-kak-pravilno-vikipediya-11-17