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://telegra.ph/Sajt-chudesenka-11-23
попперсы купить секс шоп
https://webtrh.cz/members/250051-Michaelwbn
https://telegra.ph/Tata-varna-na-yutube-01-19
https://www.40billion.com/profile/205544649
https://telegra.ph/Pyatoe-koleso-zhurnal-02-06
https://paiza.io/projects/Sv40RLfotu6ktoyim2qPqg
лучшая виагра без побочек
http://pcbspeed.com/dis/home.php?mod=space&uid=323175
https://telegra.ph/Viagra-kupit-v-aptekah-moskvy-12-24
http://pcbspeed.com/dis/home.php?mod=space&uid=323483
https://telegra.ph/Novosti-i-proisshestviya-lipecka-i-oblasti-na-segodnya-11-18
https://forum.web.ru/memberlist.php?mode=viewprofile&u=84062
купить попперс Ковров
https://www.bitsdujour.com/profiles/naeLXN
https://lessons.drawspace.com/post/387575/album
https://magazin.orgsoft.ru/forum/user/50512/
женская виагра Балаково
сиалис софт Артём
попперс Сургут
https://www.sportchap.ru/user/Michaelgrw/
https://telegra.ph/Kak-poluchit-polis-oms-v-moskve-01-25
http://vlexati.beget.tech/index.php?option=com_k2&view=itemlist&task=user&id=225544
сколько принимать сиалис 5 мг
https://ctup8v.zombeek.cz
http://pcbspeed.com/dis/home.php?mod=space&uid=323417
5
http://mail.empyrethegame.com/forum/memberlist.php?mode=viewprofile&u=207585
https://site11671470.fo.team
http://www.52pg.net/home.php?mod=space&uid=126553
https://paiza.io/projects/s9zyQYOV-0e4ozkjcm9Y-A
https://www.plotterusati.it/user/aliciagreen
https://grkn2z.zombeek.cz
https://telegra.ph/Zarabotok-v-internete-bez-vlozhenij-na-klikah-qiwi-11-13
https://webtrh.cz/members/250055-Michaelqam
https://telegra.ph/Roflit-chto-ehto-znachit-01-08
https://lebanonhub.app/aliciagreen
сиалис отз
https://site378327938.fo.team
http://witiai.cn/home.php?mod=space&uid=22424
https://telegra.ph/SHapki-optom-ot-proizvoditelya-rossiya-11-16
https://telegra.ph/Iskusstvennaya-volna-01-22
https://marketplace.trinidadweddings.com/author/aliciagreen/
https://m64a82.zombeek.cz
https://lessons.drawspace.com/post/390155/100-1
https://u5rggr.zombeek.cz
https://site726272002.fo.team
http://zhwbn.com/bbs/space-uid-91524.html
https://telegra.ph/Ponyatie-socializacii-11-17
https://amaz0ns.com/forums/users/aliciagreen/