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/EuIPqMbaFxZEK8MPGp-CqA
попперс Ковров
https://defx69.zombeek.cz
Заказать цветы с доставкой в москве дешево
Пионовидные розы Эквадор 60 см в наличии
попперс Барнаул
Цветы дешево купить
Интересные факты о флористике для клиентов
https://site880448133.fo.team
https://telegra.ph/Onlajn-registratura-ryazan-11-11
попперс купить калининград
для чего виагра форте для мужчин
https://dfipcw.zombeek.cz
ароматизатор попперс
https://telegra.ph/L-kakoj-razmer-na-russkij-02-06
https://paiza.io/projects/DRAa0wu02iZPg8sO3dV4bQ
https://telegra.ph/CHto-sdelat-iz-farsha-bystro-i-vkusno-11-24
https://wmrque.zombeek.cz
https://site188803111.fo.team
К и р о в
купить в москве сиалис дешево
https://telegra.ph/Mertvaya-tishina-trejler-11-19
https://telegra.ph/Lechenie-gepatita-s-v-rossii-besplatno-v-2016-godu-12-19
сиалис что делать
https://rentry.co/ydv6ci6o
https://snippet.host/mbusdh
попперс Прокопьевск
https://telegra.ph/Lekarstvennaya-allergiya-11-10
https://telegra.ph/Gokukoku-11-17
https://telegra.ph/Reshebnik-po-in-yazu-7-klass-11-27
попперс характеристики
https://ewglxt.zombeek.cz
попперс характеристики
https://teletype.link/implementingntg31
купить попперс Курган
виагра секрет императора
https://paiza.io/projects/X9WhQrMpa1cJ1dEEtczXZg
https://site956744333.fo.team
https://site416343764.fo.team
в
с и а л и с
https://telegra.ph/God-petuha-dlya-drakona-02-04
https://telegra.ph/Mama-synom-seks-11-30
https://rentry.co/5f4mc5rx
https://www.bitsdujour.com/profiles/yEnNbC
https://telegra.ph/Halva-mtbank-lichnyj-kabinet-vojti-12-25
https://site745467093.fo.team
https://www.bitsdujour.com/profiles/yD9lmV