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://f0fsvz.zombeek.cz
https://snippet.host/jtctjd
melbet app download iphone melbet app download iphone .
попперс amsterdam special
https://site319192637.fo.team
https://sekufs.zombeek.cz
http://www.1gmoli.com/home.php?mod=space&uid=439796
https://paiza.io/projects/sbAsfsQ3k68lbGdKWq2LLw
http://bbs.51pinzhi.cn/home.php?mod=space&uid=7715835
мелбет личный кабинет мелбет личный кабинет .
http://www.1gmoli.com/home.php?mod=space&uid=439776
https://bqcajl.zombeek.cz
https://snippet.host/fsfave
официальный сайт melbet официальный сайт melbet .
http://www.inforientation.free.fr/profile.php?id=6915
http://bbs.hy2001.com/home.php?mod=space&uid=962830
https://www.bitsdujour.com/profiles/Li41Qx
http://seafishzone.com/home.php?mod=space&uid=2727364
https://telegra.ph/Kokcidioz-11-18
http://asresin.cn/home.php?mod=space&uid=624685
https://telegra.ph/Poppers-lady-01-06
http://www.qingdaomop.com/space-uid-188437.html
https://snippet.host/ktrqjk
http://iawbs.com/home.php?mod=space&uid=945886
http://bbs.51pinzhi.cn/home.php?mod=space&uid=7715821
https://paiza.io/projects/BdvQZUcA_G33aRLcqnsOdA
http://bbs.hy2001.com/home.php?mod=space&uid=962866
https://telegra.ph/SHkola-vyzhivaniya-ot-odinokoj-zhenshchiny-s-tremya-detmi-v-usloviyah-krizisa-02-28
https://57ii2d.zombeek.cz
http://www.xgmoli.com/bbs/home.php?mod=space&uid=30240
http://bbs.51pinzhi.cn/home.php?mod=space&uid=7715790
http://shichaoliuluntan.com/home.php?mod=space&uid=417190
https://8djuyx.zombeek.cz
сиалис дженерики купить екатеринбург
http://www.jcdqzdh.com/home.php?mod=space&uid=902784
аренда яхты arenda-yakhty-spb-2.ru .
с к о л ь к о
http://georgiantheatre.ge/user/Jamesclind/
https://www.bitsdujour.com/profiles/PD3PM7
https://www.9kuan9.com/home.php?mod=space&uid=4127025
http://forum-travel2.freero.org/space-uid-44270.html
https://paiza.io/projects/wxuuJ1RpU80mXTxAbQf_mA
http://ragnarokneon.online/home.php?mod=space&uid=36859
https://site800705830.fo.team
http://app.aqlife.com/home.php?mod=space&uid=547725
а п т е к е
https://ig869.com/home.php?mod=space&uid=174260
https://teletype.link/termqnw861
https://bbs.sanesoft.cn/home.php?mod=space&uid=1386599
http://www.dbgjjs.com/home.php?mod=space&uid=550901