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.
ремонт бетонных конструкций выезд специалиста remont-betona-1.ru .
https://telegra.ph/SHkola-34-ryazan-oficialnyj-sajt-ryazan-11-25
https://www.bitsdujour.com/profiles/BfOjBM
basketball wetten Prognosen (https://basketball-wetten.com) österreich
https://site397152660.fo.team
https://telegra.ph/Na-kakoj-den-test-pokazhet-beremennost-11-08
купить букет цветов с доставкой в москве https://zakazat-cveti-moskva.ru/ .
https://telegra.ph/Trikolor-stoimost-paketa-edinyj-na-2017-god-12-31
https://paiza.io/projects/UKj4ktGBjKEW1zkWY_7nog
1xbet yeni adresi 1xbet yeni adresi .
https://telegra.ph/Zaponki-foto-01-25
bester wettanbieter deutschland
Here is my web site – wettbüro nähe (Marcia)
мостбет lucky jet 2026 https://www.mostbet21480.help
wetten die ich immer gewinne
Here is my page :: sportwetten app mit bonus
самые продолжительные попперсы
1win slots balans https://1win82430.help/
https://site103394397.fo.team
https://li67he.zombeek.cz
wettanbieter österreich
Also visit my webpage – Sportwetten wettbüro
1win ios kazino https://www.1win5765.help
виагра купить в аптеках
https://paiza.io/projects/8JtE-LEWWspeqVTAq-v1aQ
mostbet теннис ставки mostbet теннис ставки
wettbüro bonn
Feel free to visit my homepage – quoten bei wetten dass
(Clarissa)
1xbet guncel 1xbet guncel .
1xbet ?ye ol 1xbet-giris-27.com .
https://telegra.ph/Ryazanskij-kreml-01-29
1win karta orqali depozit 1win5765.help
1win apk 2026 https://1win5765.help
https://rentry.co/4facnos9
mostbet вывести деньги 2026 http://mostbet78063.help
1xbet tr giri? 1xbet-giris-29.com .
цены виагры
ремонт бетонных конструкций монолитный remont-betona-1.ru .
1xbet yeni adresi 1xbet yeni adresi .
купить сиалис казань
https://site993193239.fo.team
1xbet giri? 2025 1xbet giri? 2025 .
1win bonus Azərbaycan https://1win82430.help/
мелбет приложение Казахстан скачать мелбет приложение Казахстан скачать
https://vsozwa.zombeek.cz
мелбет кз ограничения аккаунта мелбет кз ограничения аккаунта
мелбет кз скачать приложение последняя версия мелбет кз скачать приложение последняя версия
https://telegra.ph/Skachat-volchonok-5-sezon-cherez-torrent-11-08
попперс buzz
попперс новосибирске
xbet xbet .
melbet не приходит sms melbet не приходит sms
дешевый попперс купить
1xbet yeni giri? 1xbet yeni giri? .