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 официальный сайт Бишкек http://mostbet21480.help/
melbet как скачать https://www.melbet72043.help
https://www.diggerslist.com/provekkg15/about
mostbetga qanday yuklab olish http://www.mostbet37150.help
https://espritgames.com/members/50483806/
мостбет lucky jet Кыргызстан mostbet83507.help
https://paiza.io/projects/0hGjhVV-z_Ng4GjMRQ1MaA
pin up lucky jet demo https://www.pinup69053.help
1win foydalanuvchi shartnomasi 1win foydalanuvchi shartnomasi
заказать букет москва с доставкой недорого https://zakazat-cveti-moskva.ru .
1xbet turkiye 1xbet-giris-29.com .
https://www.bitsdujour.com/profiles/UepGNy
Excellent post. I certainly love this website. Keep it up!
Visit my web site how Much money casino chips
top 10 casino in canada, new zealandn poker online free game and best slot sites australia,
or no deposit bonus aus casino
my page … goplayslots.net
1win MasterCard http://1win82430.help/
п о п п е р с
https://telegra.ph/Poppers-sposob-01-18
https://www.bitsdujour.com/profiles/G3Fg0U
https://um0dqc.zombeek.cz
https://theexplorers.com/user?id=1a961829-0fdd-4c2e-ac15-9e0be2781257
mostbet lucky jet https://mostbet21480.help/
https://site576841726.fo.team
https://paiza.io/projects/DcBLxcx_Eng1TvoG05y5xw
попперс 24
где в москве купить виагру
https://telegra.ph/Tokmo-11-13
https://snippet.host/wbfsgw
https://1sbegs.zombeek.cz
мелбет пополнение через карту мелбет пополнение через карту
1xbet giris 1xbet giris .
https://rentry.co/p64rysck
beste wettanbieter
Check out my website – basketball-wetten.com
apuestas futbol americano nfl
My web page; basketball-wetten.Com
mostbet karta bog‘lash http://mostbet37150.help/
pin-up Humo orqali pul yechish https://www.pinup69053.help
1xbet g?ncel 1xbet g?ncel .
online sportwetten paypal
my web-site – beste Wett tipps heute
sportwetten strategie ohne verlust
My site :: wett Prognosen
1win giriş tarixçəsi http://1win82430.help/
1xbet giri? yapam?yorum 1xbet-giris-27.com .
1xbet yeni giri? adresi 1xbet yeni giri? adresi .
дизайн интерьера загородных домов дизайнерский проект дома
Посмотреть на сайте: https://learningapps.org/watch?v=pnhh44o3a25
1 xbet giri? 1xbet-giris-28.com .
1x lite 1xbet-giris-34.com .
1xbet mobil giri? 1xbet-giris-29.com .
1xbet yeni adresi 1xbet-giris-32.com .
1xbet turkiye 1xbet turkiye .
мелбет пополнить с мбанк мелбет пополнить с мбанк
birxbet giri? 1xbet-giris-35.com .