Integration testing transactions and optimistic locking with Spring and JUnit

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.

16,624 thoughts on “Integration testing transactions and optimistic locking with Spring and JUnit

  1. Unfortunately the Pro version of Alight Motion is paid but don’t worry because our website is providing you with the Mod Version of Alight Motion with all premium features unlocked. So you can use the application without paying any cost. The app allows its users all pro features for free. They can download the Alight Motion MOD APK Latest Version and enjoy their Pro unlocked features without any paid subscription. You should use all of these features and make your images or videos professional and look very attractive. One of the biggest limitations of the Google Play version of Alight Motion is the intrusive watermark baked into exports. This prominently displays the Alight Motion logo and branding throughout your video projects. The developers intentionally added the free app to incentivize upgrading to the paid pro subscription. They want to restrict professional feature usage to paid users only. https://forum.melanoma.org/user/cipufcentpa1973/profile/ While it makes sense to use dedicated desktop apps for pragmatic animation but if you just want to do small animation on your Android tablet to sketch out ideas here are some of the best animation apps for the Android platform that will help. These apps are also super useful for your kids helping them channelize their creative energy. How it works: When the app launches you can choose between three different story modes. Short classic and science report. The app will guide you nicely through the process. Choose a setting background props characters and so on. I liked the spooky camp. Comes with strange and funny looking monsters and robotic dogs. You can move around characters while everything is being recorded. There are different moods with their respective intensity. When you are done save and share.

  2. Views: 44455437 DOWNLOAD CORRUPTION OF CHAMPIONS MOD APK Copyright 2020 All Hashtag #freeporn Web Site PORN HD VIDEOS Big boobs xxx video. Hot hindi bfxxx bhabhi mms and sexy videos Big boobs xxx video. I hope you downloaded the Corruption of Champions Mod APK on your mobile device. If you need any help regarding any mod apps then you can knock me on Facebook for a quick response. Don’t forget to share this post with your loved ones. Mast sexy Hindi bf videos dekhe aap ki pasandida Indian porn clips ki sites par. Aap yaha bhabhi girls aur aunties ke boobs chut aur gaand fucking ke mast xxx mms dekhe. Dehati aur amateur Indian sex videos ka bhi ek bada collection he hamare is Indian blue films site par. Sunny leone xxx sexy films aur English ladies bhi section he aap ke lie 51 secApk-Porno – https://scolrechfightat1984.tearosediner.net/https-truefortunelogin-uk-com Autodesk Maya is a 3D animation software free that is widely used for creating high-quality 3D animations visual effects simulations and rendering. It is one of the industry-standard software applications in the field of 3D animation and is commonly used in film television video games and other industries that require advanced 3D content creation. Get an Animiz account as the beginning of making a cartoon animation video Whiteboard animation is a style of video designed to look like it’s being drawn on a whiteboard. It’s a powerful way of visualizing information in an engaging way and improves memory retention by 15 versus talking head videos research from Dr. Richard Wiseman. MotionBook – Draw & Animate You can animate clothing and other objects link objects together to move them as one warp an object to exaggerate its animation even perform freeform deformations. That’s an impressive toolkit with the software working with both bitmap graphics and vector images.

  3. Люди помогите советом Брат снова сорвался Соседи стучат в стену Нужен врач прямо сейчас Короче только это реально спасло — нарколог дом с осмотром Через пару часов человек пришёл в себя В общем не потеряйте контакты — нарколог на дом вывод из запоя нарколог на дом вывод из запоя Звоните прямо сейчас Перешлите тем кто в такой же ситуации

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>