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/Zov-atlantidy-igrat-onlajn-besplatno-sejchas-bez-registracii-11-11
https://paiza.io/projects/l3MAfkLrQ6-GntexFCWNgQ
https://paiza.io/projects/6DdkktVU6sjUbFpoQMOCaw
попперс самара доставка
купить попперс Грозный
https://telegra.ph/Sword-art-online-igra-na-pc-12-10
https://site498975458.fo.team
sms activate sms activate .
https://telegra.ph/Mozhno-li-kupit-viagru-v-apteke-bez-recepta-12-02
попперс Калининград
https://telegra.ph/Novye-kody-dohodov-i-vychetov-v-2016-godu-02-02
mostbet ставки приложение mostbet ставки приложение
попперс Симферополь
виагра аналоги рф
https://4o17ek.zombeek.cz
https://telegra.ph/Tvardovskogo-8-gibdd-11-08
https://telegra.ph/Liposakciya-cena-02-23
а н а л
https://snippet.host/wzwgxc
https://rentry.co/dyf2z3du
https://telegra.ph/Kak-izmenit-ip-11-13
https://telegra.ph/Soobshcheniya-v-vk-12-03
https://telegra.ph/4k-razreshenie-ehto-skolko-11-24
купить тадалафил Новороссийск
попперсы провоз в россию сочи
https://1mslfl.zombeek.cz
попперсы купить санкт петербург
https://paiza.io/projects/AU8BpDMeJwWVFXJ6VdBf4g
вредный ли попперс
https://telegra.ph/Viktoriya-tur-01-22
аванафил Сочи
mostbet KGS пополнение http://www.mostbet61527.help
https://telegra.ph/Boevoj-malysh-film-2015-11-19
https://telegra.ph/Zolotoj-myach-2017-kto-poluchil-02-20
https://ocjmte.zombeek.cz
https://paiza.io/projects/BslEGkLpqtLMhYrBv03gLg
https://telegra.ph/Maks-bruks-11-13
https://telegra.ph/We-are-young-12-31
попперс Ставрополь
https://paiza.io/projects/B_RR5NyQCc1Dvm3zrhzyDA
https://teletype.link/demonstratelmi454
https://telegra.ph/Igry-dlya-malchikov-agario-11-23
https://fsv6yv.zombeek.cz
https://site496996670.fo.team
Pure candy chaos on your screen sugar rush pragmatic play combines adorable graphics with massive win potential up to 5000x. One lucky spin changes everything
самый сильный попперс купить
https://telegra.ph/Split-skachat-torrent-v-horoshem-kachestve-hd-1080-01-13
https://4ytgks.zombeek.cz
https://paiza.io/projects/0ekwI1eQTUJltB2jsHHHIw
https://telegra.ph/Akmash-02-25