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://site561422715.fo.team
виагра продлит ли секс
попперс это что такое для мужчин
https://telegra.ph/Kupit-poppers-v-ekaterinburge-01-06
https://telegra.ph/Dzherard-11-19
виагра таблетки цена сиалис
https://telegra.ph/Furosemid-v-ampulah-01-05
Знакомтсво Ростов на дону
https://telegra.ph/Skachat-gapps-11-19
https://site496707702.fo.team
п о п п е р с
https://site746845744.fo.team
https://4vgie7.zombeek.cz
супер сиалис Якутск
https://telegra.ph/Lechenie-zubov-pod-narkozom-01-05
https://site750727740.fo.team
https://telegra.ph/Mosaic-odezhda-oficialnyj-sajt-12-02
https://telegra.ph/Preparat-dlya-uluchsheniya-ehrekcii-02-16
купить попперс саратове
https://paiza.io/projects/KuGCF7rHaHpFrcA8KeriHg
купить попперс в москве с доставкой
die besten wett tipps heute
Feel free to visit my homepage … basketball viertel wetten
попперс Каменск-Уральский
https://iojewt.zombeek.cz
О р с к
https://rentry.co/sowwwfx9
попперс Артём
https://site730077259.fo.team
https://telegra.ph/Andrej-bolkonskij-harakteristika-11-09
секс попперс
https://telegra.ph/Jooheon-12-11
включить виагра
https://paiza.io/projects/C287pPiL4bd_1nYAXrHXgQ
https://telegra.ph/Krasivaya-zhizn-film-1990-02-19
дженерик сиалис купить спб
https://telegra.ph/Viagra-tabletki-01-29
https://telegra.ph/Www-sima-land-ru-01-10
wettanbieter gratiswette
Feel free to visit my web blog :: Beste sportwetten anbieter
https://telegra.ph/Bongo-gems-12-14
https://telegra.ph/Olga-ostroumova-filmy-02-22
https://telegra.ph/Kak-narisovat-mashu-i-medvedya-11-21
женская виагра Каменск-Уральский
https://site819419576.fo.team
https://telegra.ph/Dual-ehto-02-01
сиалис в туле купить
https://telegra.ph/Sistema-yurist-11-17
https://telegra.ph/Robocopy-11-19
попперс Домодедово
https://telegra.ph/Adidas-diskont-volgograd-katalog-tovarov-oficialnyj-sajt-01-15
виагра Миасс