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://site798217471.fo.team
купить виагра Салават
https://telegra.ph/Karaoke-kamedi-klab-11-18
продажа виагра
https://3pkiex.zombeek.cz
wettbüro freiburg
My webpage … sportwetten beste anbieter
https://iduobr.zombeek.cz
https://upzsdy.zombeek.cz
https://zdawxh.zombeek.cz
https://site108100608.fo.team
промокод на melbet промокод на melbet .
https://telegra.ph/Planeta-yaponiya-stavropol-12-10
купить набор для влюбленных Ноябрьск
попперс челябинск
https://telegra.ph/Lolita-lichnaya-zhizn-11-09
deutsche wettanbieter
Here is my web site: Wetten Basketball; Https://Basketball-Wetten.Com/,
https://telegra.ph/Salaty-i-zakuski-na-prazdnichnyj-stol-prostye-i-vkusnye-11-11
https://9uuhqn.zombeek.cz
дженерик виагра
https://snippet.host/phdhaw
Good post. I learn something totally new and challenging on sites I stumbleupon every day. It’s always exciting to read content from other writers and practice a little something from their websites.
попперс новосибирск
https://teletype.link/thomsoniih659
https://snippet.host/swyzgj
https://telegra.ph/Umnica-rannee-razvitie-11-12
к у п и т ь
https://wipdcf.zombeek.cz
https://site610663731.fo.team
https://paiza.io/projects/hfUc5qLwgN4eG3vwyQHh7w
попперс химки
https://telegra.ph/Sport-igrok-11-13
https://b7sgqw.zombeek.cz
https://site824130577.fo.team
wettquoten bayern dortmund
Here is my blog :: wetten bonus code – Michale -
виагра для здоровых мужчин
сделать попперсы
https://vbo09x.zombeek.cz
попперсы рф
wetten quoten vergleich
my web page wett prognosen
https://ilvtoz.zombeek.cz
https://teletype.link/russianqxq45
https://snippet.host/uihusu
https://telegra.ph/Igrat-v-igry-ogon-i-voda-na-2-igrokov-besplatno-12-12
https://telegra.ph/Ulrih-11-23
https://telegra.ph/Uniderm-01-29
попперс Армавир
https://www.bitsdujour.com/profiles/gHjNld
https://site842104221.fo.team
https://rentry.co/iomtky3a
https://site110645485.fo.team