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/qcfVHqSdv1KV-DFG6QGBUw
заказать кухню под размеры заказать кухню под размеры .
лендинг виагры
купить попперс Стерлитамак
https://www.bitsdujour.com/profiles/k0buCA
quotenvergleich sportwetten prognosen
дапоксетин Норильск
https://site205606482.fo.team
1win apk MD 1win apk MD
https://site97785769.fo.team
услуги печати https://telegra.ph/kak-sozdat-broshyuru-k-vystavke-sovremennogo-iskusstva-02-17 .
https://telegra.ph/Solenye-limony-12-28
https://site948474766.fo.team
1win cashback necə alınır https://www.1win5763.help
проект перепланировки квартиры проект перепланировки квартиры .
п о п п е р с
попперс вечеринка
starslot55 never goes out of style. Expanding wild respins create epic moments. Both directions pay — timeless classic.
https://6keu7w.zombeek.cz
Лучшие онлайн казино Лучшие онлайн казино .
заказать кухню заказать кухню .
узаконивание перепланировки квартиры sites.google.com/view/dokument-dlya-pereplan/главная-страница .
заказать кухню по индивидуальному заказу заказать кухню по индивидуальному заказу .
99 down caiu.site .
https://telegra.ph/Pogoda-v-berline-na-10-dnej-11-11
https://lddoyr.zombeek.cz
Казино онлайн топ Казино онлайн топ .
https://site281981535.fo.team
https://telegra.ph/Rabota-vahta-sever-12-14
https://telegra.ph/Vitaminy-dlya-zhenshchin-posle-30-kakie-luchshe-kupit-otzyvy-02-25
https://telegra.ph/Statya-112-uk-rf-11-19
дженерик сиалис купить дешево
мостбет баскетбол ставки mostbet52718.help
попперсы заказать москва
https://www.bitsdujour.com/profiles/fjuvuL
1win md casino http://www.1win5805.help
https://telegra.ph/Statya-426-gk-rf-11-19
заказать кухню в рассрочку zakazat-kuhnyu-3.ru .
https://4yj6mg.zombeek.cz
https://snippet.host/vkipau
магазин попперсов
заказать кухню заказать кухню .
https://rentry.co/u96rv6dg
заказать кухню по размерам zakazat-kuhnyu-1.ru .
https://snippet.host/dupmuj
https://iophsr.zombeek.cz
типография изготовление http://maraforum.iboards.ru/viewtopic.php?f=10&t=9428 .
попперс новосибирск
настоящий попперс
купить женская виагра Бийск