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,712 thoughts on “Integration testing transactions and optimistic locking with Spring and JUnit

  1. united statesn roulette online fast, no deposit online australian casinos and new zealandn online pokies for real money, or casino silver (Latoya) age
    limit canada

  2. bulk poker chips united states, free pokie games united kingdom and
    interactive gambling canada, or all australian how to be a good casino
    dealer (Jackson) no deposit bonus codes

  3. how many online casinos in usa, united statesn foxwoods online
    casino app (Jens) casino legal and online
    australian pokies, or apple pay online casino united states

  4. are the top online pokies and casinos in new zealand
    right now, good gambling sites uk and free spins bonus usa, or best online rolling
    chips casino (Zachary) for slots uk

  5. mobile casino new united states, captain cooks gambling age at choctaw casino (Amelie) united states
    and paypal bingo sites uk, or is top online pokies and casinos
    united states pokies

  6. free chip no deposit all stars casino, Ivory, bonus united states, win real money online instantly
    usa and $5 minimum deposit casino australia 2021, or native united statesn casinos
    in montana

  7. Autodesk Maya is a professional 3D computer animation software that is widely used in the film and gaming industries. It offers a wide range of tools and features that enable animators to create highly detailed and realistic animations. Some of its key features include a robust character animation toolset a node-based workflow for creating visual effects and advanced simulation tools for creating realistic cloth hair and fluid simulations. With its wide range of tools and features Autodesk Maya is the go-to software for animators who want to create top-quality animations. I’m an amateur animator that creates hand-drawn cartoon shorts. Normally I’m hunched over my light box but had been looking for an app so I could work on projects while I’m out and about. A friend told me about Animatic and I love this app I like how the next frame has an imprint of the previous drawing for easy animating.— iPad User reviewing Animatic Apple App Store https://docs.lagonette.org/s/Nox1KGHxs CapCut Premium APK is one of the best video editing software programs that I personally use to make my videos professional. The 3D zoom transitions and blurry templates I love the most. By using these effects my videos got trending on Instagram and TikTok. When you see that your video is looking great export it in Ultra HD or 4k 60 fps quality. Video editor with professional features An easy-to-use powerful free video editor Free video editor without watermarks The Motion Blur Effects feature is also particularly impressive employing optical flow technology to create high quality motion blur effects. This adds a professional touch to your videos and enhances their overall visual appeal.  However take note that larger projects can take a long time to export. Similarly enough sizable high-quality files take longer to upload onto the app as well.

  8. Brush up on your fishing skills when playing Pragmatic Play’s Bigger Bass Bonanza online slot. The game’s got 12 paylines high volatility 96.71 RTP and a maximum win of 960000 coins. Read our full review to find out what else we uncovered while reviewing the game. Try to make the most out of the round stages on offer. If the total win during the round reaches 4000x the stake the feature will immediately end. Play this slot at Ladbrokes Online Casino. bigbassbonanza.bet4.3 While many online casinos offer Pragmatic Play games I’d recommend PokerStars as a great place to start. Besides having a fantastic reputation the site offers 100 up to £300 150 bonus spins as its welcome bonus. Remember to use the bonus code UK300 when placing your first deposit of £10 or more. While you’ll be limited as to which slots you can use the bonus spins on you’ll be able to use the bonus cash to explore the rest of the casino including the Bigger Bass Bonanza slot machine. https://docs.monadical.com/s/yTEapG3qQn 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. Perfect your animation effortlessly with In and Out Points. Easily mark sections for looped playback to refine your sequences until they’re just right. The simple and beautiful software for creating animation cartoons and animatics. What sets Vista Create apart from other animation apps is its user-friendly interface and intuitive workflow. Even if you have no prior experience in animation or design this app makes it simple for anyone to create animations in no time. Developed by WeirdHat RoughAnimator is the best whiteboard animation video maker because it is simple enough for beginners while also being professional enough for experts. It is possible to create a traditional hand-drawn frame-by-frame animation with it while unlimited layers and adjustable animation are just a quick game.

  9. united kingdom live casino, united kingdom pub pokies and play free games roulette table
    for sale in india (Edythe) real money uk, or best
    casino sign up offers uk

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>