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://site573817862.fo.team
https://telegra.ph/Akkumulyatory-18650-kupit-12-12
https://rentry.co/3anm5486
melbet ставка на спорт киргизия https://melbet76815.help/
apuestas Virtuales futbol mundial brasil
https://telegra.ph/Levitra-soft-Nizhnij-Novgorod-12-16
https://site786724861.fo.team
las casas de apuestas Con Tarjeta de debito pagan impuestos
https://telegra.ph/Kamennyj-gorod-11-08
melbet скачать без блокировки https://www.melbet76815.help
comparacion cuotas casas de apuestas – Kit,
de apuestas con esports
женская виагра Михайловск
установка газового пожаротушения цена установка газового пожаротушения цена .
установка газового пожаротушения москва montazh-gazovogo-pozharotusheniya-1.ru .
https://rentry.co/uq7uobeo
seo partners seo partners .
https://telegra.ph/Besplatnyj-sajt-sozdat-12-17
мелбет изменить почту melbet54187.help
melbet приложение киргизия http://melbet54187.help
установка газового пожаротушения москва montazh-gazovogo-pozharotusheniya-3.ru .
melbet как получить бонус http://www.melbet54187.help
попперс кофе
https://teletype.link/mealsawj29
мелбет apk киргизия скачать http://melbet76815.help
https://telegra.ph/Skachat-megafon-internet-11-18
plinko mostbet http://mostbet39081.help/
компании занимающиеся продвижением сайтов компании занимающиеся продвижением сайтов .
https://telegra.ph/Konstantin-onlajn-11-16
газовое пожаротушение монтаж с гарантией montazh-gazovogo-pozharotusheniya-2.ru .
melbet mastercard пополнение https://melbet54187.help/
монтаж газового пожаротушения для склада montazh-gazovogo-pozharotusheniya-1.ru .
газоблок цена купить газобетон в краснодаре
https://paiza.io/projects/goyaMXIdl_GmYx0r2VAgWw
продвижение в google prodvizhenie-sajtov-v-moskve9.ru .
melbet aviator на деньги https://www.melbet76815.help
https://www.bitsdujour.com/profiles/j25DDr
https://telegra.ph/Proverka-tranzistora-02-02
https://teletype.link/touchedldv649
https://paiza.io/projects/zh9htZ3PhVVEJl1rb3tNjg
https://telegra.ph/Strastnye-nebesa-dorama-01-09
монтаж газовой системы пожаротушения под ключ монтаж газовой системы пожаротушения под ключ .
abc попперсы
https://telegra.ph/Uslugi-raskrutka-sajta-moskva-11-29
https://site652764227.fo.team
попперс Санкт-Петербург
https://uu6vkv.zombeek.cz
https://telegra.ph/Soglasovannye-i-nesoglasovannye-opredeleniya-02-01
https://telegra.ph/Mirovoj-sudebnyj-uchastok-17-sovetskogo-rajona-g-bryanska-02-15
усиление ссылок переходами prodvizhenie-sajtov-v-moskve10.ru .