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://telegra.ph/Goryashchie-tury-moskva-11-21
https://telegra.ph/Boby-tonka-02-18
https://site187250825.fo.team
https://telegra.ph/Ranvir-02-26
дипоксетин
Eva Casino промокоды
https://telegra.ph/Truba-vojta-11-25
мостбет коэффициенты футбол Кыргызстан https://www.mostbet57193.help
купить попперс Балаково
mostbet oson http://mostbet84629.help
mostbet login xatolik https://www.mostbet84629.help
на сколько хватает попперса
курсовые купить курсовые купить .
попперс купить самаре
попперс купить в твери
сайт заказать курсовую работу сайт заказать курсовую работу .
https://telegra.ph/Kak-poschitat-obem-v-m3-11-20
mostbet kupon kodi http://mostbet28461.help
https://koocay.zombeek.cz
сиалис цена
https://rentry.co/r2dr44n2
мостбет поддержка Кыргызстан мостбет поддержка Кыргызстан
https://www.bitsdujour.com/profiles/rmQlrT
https://telegra.ph/Orgazm-ot-kunilingusa-11-23
https://telegra.ph/Otdyh-v-ispanii-v-2017-11-12
1win вывод без комиссии элсом 1win вывод без комиссии элсом
купить софт набор Тверь
https://www.bitsdujour.com/profiles/rvsVP9
https://telegra.ph/Komandor-sobaka-cena-11-10
дапоксетин последствия
https://site553693647.fo.team
https://telegra.ph/Kak-cherez-ajtyuns-skinut-muzyku-na-ajfon-12-17
https://qxfwoe.zombeek.cz
1win официальный сайт вход https://1win54038.help
https://telegra.ph/SHifonovyj-biskvit-recept-01-17
https://www.bitsdujour.com/profiles/pmppgh
https://telegra.ph/Bukkake-hd-11-09
https://telegra.ph/Fear-11-17-6
https://nor51y.zombeek.cz
помощь студентам курсовые kupit-kursovuyu-82.ru .
https://telegra.ph/Hram-dmitriya-donskogo-11-18
Eva Casino приветственные бонусы Зеркало Eva Casino предоставляет полный функционал основного сайта. Это означает что вы можете не только играть в любимые слоты и другие игры но и проводить финансовые операции обращаться в службу поддержки участвовать в акциях и турнирах. Интерфейс зеркала полностью идентичен оригинальному сайту что обеспечивает привычный и комфортный пользовательский опыт. Никаких компромиссов в качестве и доступности игр — только полноценный доступ ко всему спектру услуг.
https://snippet.host/dpoafn
https://telegra.ph/Top-telefonov-2017-12-12
мостбет пополнение с uzcard mostbet60172.help
п о п у л я р н ы й
mostbet shaxsiy kabinet kirish mostbet shaxsiy kabinet kirish
написание учебных работ kupit-kursovuyu-81.ru .
как получить фрибет mostbet https://www.mostbet60172.help
https://snippet.host/ocpeth