Announcement Announcement Module
Collapse
No announcement yet.
Unit Testing Spring Transactions Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Unit Testing Spring Transactions

    I have searched for the answer to my upcoming question but can't seem to get a good answer.

    I have a service layer method annotated with

    Code:
    @Transactional(readOnly = false, propagation = Propagation.REQUIRED
    This method calls several methods in my DAO which are also annotated with the same transaction statement listed above. My goal being that I want the several DAO methods to run as one unit of work (I know, the definition of a Transaction!).

    We had a specific problem where we were generating the same "thing" when several people pressed the submit button at the same time. My solution was to put a transaction on the service layer method as stated above.

    My question is how do I unit test to ensure that this specific problem is solved. In other words, how do I validate that the spring transaction is actually "doing its job"?

    Ultimately we will do an actual test with many people pressing the button at the same time but I want to verify by unit testing it first.

  • #2
    If you set the transaction in the service layer, there is no need to add the transactional annotation on DAO.

    If you want to do a test with 2 call, you will need to create 2 thread... But you cannot be sure when they start / run / finish...

    Comment

    Working...
    X