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.
beste quoten bei sportwetten
Here is my web-site: App FüR Private Wetten, Gratis-Wetten.Com,
https://iws9ym.zombeek.cz
https://telegra.ph/Multiki-v-kinoteatrah-02-16
купить сиалис
https://telegra.ph/Follaut-porno-12-10
https://site115428854.fo.team
https://site534290187.fo.team
https://telegra.ph/Zima-holoda-odinokie-doma-11-13
https://site846271501.fo.team
https://site902537679.fo.team
sweet bonanza retiro 24 horas sweet-bonanza18364.help
супер виагра Нижневартовск
wettseiten schweiz
Also visit my web site; wetten Dass Gewinne
https://rumscg.zombeek.cz
https://telegra.ph/Perevod-pesni-stressed-out-01-04
https://telegra.ph/Benbuzal-konfety-02-23
попперс наркотик ли
melbet терминал пополнение http://melbet36290.help/
https://site49028966.fo.team
https://site697920087.fo.team
сиалис белгород
download 1win app http://1win76138.help/
https://telegra.ph/Prime-dice-11-29
набор виагра сиалис
internetagentur seo internetagentur seo .
купить попперс Таганрог
https://site423816806.fo.team
https://site382182138.fo.team
https://teletype.link/emergingoch3265
https://snippet.host/moweyp
купить сиалис для мужчин в москве
продвижение сайта в google омск продвижение сайта в google омск .
https://rentry.co/7934ickh
лучший попперс для секса
https://telegra.ph/Kak-poluchit-voditelskie-prava-11-14
https://snippet.host/rqwjuc
1win futbol tikish 1win5768.help
https://site920087879.fo.team
сео фирмы сео фирмы .
мелбет баргардонидани маблағ http://melbet20856.help/
https://snippet.host/nnygje
https://site210825063.fo.team
Дополнительная информация: https://l-parfum.ru/catalog/jimmy-choo/eau-de-parfum/
https://paiza.io/projects/M1YYP-9iTK8gbIIMUf4g7w
https://snippet.host/fqfesw
https://telegra.ph/Lada-tolyatti-oficialnyj-sajt-avtomobili-v-nalichii-12-29
мостбет пополнить счет Кыргызстан https://www.mostbet27541.help
https://telegra.ph/Kupit-poppers-Ryazan-12-19
https://telegra.ph/Zemelnye-uchastki-pod-izhs-11-09
сиалис кто применял