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://paiza.io/projects/KtRg-xNYCo9v5Y08sVI8DA
платный нарколог на дом в ростове платный нарколог на дом в ростове .
купить сиалис в москве
1win balance kg вывод 1win balance kg вывод
mostbet natijani tekshirish http://mostbet28461.help/
https://telegra.ph/Stenovye-paneli-pvh-dlya-vnutrennej-otdelki-foto-i-cena-11-13
https://telegra.ph/Sajt-sudebnyh-pristavov-krasnodarskogo-kraya-11-18
https://zkotsn.zombeek.cz
https://site46700035.fo.team
виагра после 70 лет
https://usl8ku.zombeek.cz
https://site808929489.fo.team
история попперс
https://teletype.link/utilityvrs23
бездепозитные бонусы с выводом без пополнения в Грузии
купить сиалис софт Кемерово
https://site286664488.fo.team
п о п п е р с
https://snippet.host/xadtom
https://site129527448.fo.team
купить софт набор Сочи
https://rentry.co/fraiwttr
онлайн казино законно ли это в россии
https://www.bitsdujour.com/profiles/JRQUZA
https://telegra.ph/Sanatorij-sosnovyj-bor-oficialnyj-sajt-ceny-na-2017-god-01-06
попперс Волжский
https://teletype.link/enabledamv18
з а к а з а т ь
виагра стоимость брянск
речные прогулки по неве arenda-yakhty-spb-3.ru .
в
Казино в Грузии
mostbet blocare cont https://mostbet63218.help
купить попперс Рязань
pin-up bepul tikish 2026 http://www.pinup14278.help
вывод из запоя в стационаре в ростове на дону вывод из запоя в стационаре в ростове на дону .
https://malt-orden.info/userinfo.php?uid=448382
https://bfyqtv.zombeek.cz
https://kfmpix.zombeek.cz
https://telegra.ph/Talon-11-13-3
нарколог на дом ночью ростов-на-дону narkolog-na-dom-v-rostove-3.ru .
https://telegra.ph/Gaminator-klub-kazino-11-17-2
https://rh6idp.zombeek.cz
бездепозитные бонусы за регистрацию в Грузии
купить попперс Домодедово
сиалис дженерики ростов
https://teletype.link/modemspyj92
https://telegra.ph/Kak-prinimat-l-karnitin-dlya-pohudeniya-02-20
https://h158wt.zombeek.cz
https://site661592788.fo.team