Results 1 to 2 of 2

Thread: Unit Testing Spring Transactions

  1. #1

    Default 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. #2
    Join Date
    Apr 2011
    Posts
    107

    Default

    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...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •