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.
berlin wettbüro
Feel free to surf to my homepage; alle wettanbieter online [Mary]
Thank you for the good writeup. It in fact was a amusement account it.
Look advanced to far added agreeable from you! By the way, how can we communicate?
Low bank transfer value keeps dominating fast entries.
buchmacher österreich
Feel free to surf to my website Basketball wetten nba (basketball-wetten.com)
Hello there, You have done an incredible job. I will certainly digg
it and personally recommend to my friends. I am confident they will
be benefited from this website.
1win плинко https://www.1win72951.help
1win card Victoriabank http://1win60823.help
Hello very cool blog Guy .. Excellent .. Superb .. Ill bookmark your blog and take the feeds also? I am satisfied to seek out so many useful information here in the put up wed like work out extra techniques in this regard thanks for sharing. . . . . . Candy Blitz Bombs
Very good website you have here but I was curious about if you knew of any forums that cover
the same topics talked about in this article? I’d really love to be a part
of online community where I can get responses from other knowledgeable people that share the same interest.
If you have any recommendations, please let me know. Bless you!
1win бонус на депозит казино http://1win56183.help
That is very fascinating You are a very professional blogger. I have joined your rss feed and look forward to searching for extra of your great post. Additionally I have shared your web site in my social networks Candy Blitz Bombs
I do not even know how I ended up here, but I thought
Cheers!
this post was great. I do not know who you are but definitely you’re going to a famous blogger if you are not already
wettanbieter mit sitz in deutschland
Also visit my webpage: deutsche wettseiten (Abbey)
мостбет удалить аккаунт мостбет удалить аккаунт
1win бонусы ставок http://www.1win94317.help
mostbet lucky jet pe telefon https://mostbet13829.help/
1win чат не отвечает https://1win92486.help
mostbet aplikacja samsung http://mostbet2002.help/
melbet результаты матчей http://melbet45163.help/
1win условия вывода 1win условия вывода
mostbet depozit qilish usullari https://www.mostbet59371.help
Players who request self-exclusion must also report any other accounts and must not open new ones during
the exclusion period.
Hi my loved one! I wish to say that this article is amazing, great written and include approximately all significant infos.
I’d like to see extra posts like this .
мостбет пополнить счет mostbet09654.help
1win рабочее зеркало Кыргызстан http://1win94317.help/
mostbet bilet combinat http://mostbet13829.help/
Зацепил материал про Актуальные события и жизнь Липецкой области сегодня.
Вот, делюсь ссылкой:
https://48media.ru
Fortune Tiger leads in popularity.
Hi there, i read your blog from time to time and i own a similar one and
i was just wondering if you get a lot of spam remarks?
If so how do you reduce it, any plugin or anything you can suggest?
I get so much lately it’s driving me insane so any help is very much appreciated.
bayar bayar bayar bayar bayar bayarbayar bayar bayar
bayar bayar bayarbayar bayar bayar bayar bayar bayar bayar bayar
bayar bayar bayar bayarbayar bayar bayar bayar bayar bayarbayar bayar bayar
bayar bayar bayar bayar bayar bayar bayar bayar bayarbayar bayar bayar bayar bayar
bayarbayar bayar bayar bayar bayar bayar bayar bayar bayar bayar bayar bayarbayar bayar bayar bayar
bayar bayar
Howdy! This is my first comment here so I just wanted to give a quick shout out and tell you I truly
enjoy reading your posts. Can you suggest any other
blogs/websites/forums that go over the same subjects?
Appreciate it!
I blog quite often and I seriously thank you for your content.
The article has really peaked my interest.
I will bookmark your website and keep checking for new
information about once a week. I subscribed to your
Feed too.
1win краш https://1win92486.help/