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.
1xbet yeni adresi 1xbet yeni adresi .
мостбет как вывести выигрыш http://mostbet38195.help
мостбет скачать Кыргызстан мостбет скачать Кыргызстан
https://vfcszfpzcb.wordpress.com
1win mərc hesablanmır http://1win03748.help/
https://ijpsgtibdd.wordpress.com
https://ijpsgtibdd.wordpress.com
https://bbudktdhdo.wordpress.com
top casas de apuestas peru de apuestas deportivas en sevilla
apuestas para ganar la europa league (https://fr-Betting.com/) españa eurocopa
https://bbudktdhdo.wordpress.com
1win ставки на баскетбол Кыргызстан https://1win63197.help/
mostbet не устанавливается apk mostbet38195.help
мостбет android приложение скачать https://www.mostbet42395.help
ии для школьников и студентов nejroset-dlya-referatov-1.ru .
1win email təsdiqi 1win03748.help
apuestas fútbol que significa asiatico en las apuestas
vivo
нейросеть для рефератов нейросеть для рефератов .
умная нейросеть для учебы nejroset-dlya-referatov-2.ru .
https://tqjhrbjrzv.wordpress.com
https://tqjhrbjrzv.wordpress.com
нейросеть для учебы онлайн nejroset-dlya-referatov.ru .
1win depozit üçün KYC https://1win57196.help/
mostbet верификация сколько дней mostbet верификация сколько дней
pin up roʻyxatdan oʻtish email orqali http://pinup35741.help
мелбет ios app скачать https://melbet84062.help/
melbet скачать бесплатно https://melbet84062.help
1win о деньги пополнение 1win63197.help
https://txxbdjbcir.wordpress.com
mostbet kaszinó Magyarországról mostbet kaszinó Magyarországról
1win бесплатные вращения 1win бесплатные вращения
генерация nejroset-dlya-referatov-1.ru .
умная нейросеть для учебы nejroset-dlya-referatov-3.ru .
нейросеть реферат онлайн нейросеть реферат онлайн .
https://txxbdjbcir.wordpress.com
Все самое свежее здесь: https://armstroy72.ru
нейросеть для рефератов nejroset-dlya-referatov.ru .
https://ckbsqizjpk.wordpress.com
https://ckbsqizjpk.wordpress.com
1win xoş gəldin bonusu 1win xoş gəldin bonusu
купить цветы с бесплатной доставкой по москве https://www.dostavka-cvetov-moskva495.ru .
1вин visa пополнение 1вин visa пополнение
pinup Click orqali pul yechish pinup35741.help
нейросеть онлайн для учебы nejroset-dlya-referatov-3.ru .
чат нейросеть для учебы nejroset-dlya-referatov-2.ru .
мелбет ставки на теннис мелбет ставки на теннис
melbet приложение на русском melbet приложение на русском
melbet официальный адрес melbet официальный адрес
нейросеть для студентов нейросеть для студентов .
https://olyfufoizv.wordpress.com