• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Spring TransactionalDataSource tests not being rolled back as expected

 
Ranch Hand
Posts: 188
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have several tests which extend AbstractTransactionalDataSourceSpringContextTests and they appear to not be rolling back as expected when I run more than one of them together, as in the case of my Maven build. I get tests failing because they expect the database tables to be in a clean state when they start, and instead there is data already present, making it impossible to assert that a certain number of records are present after using DAO classes to save/delete/etc.

I have confirmed that this behavior happens using both HSQLDB and Derby embedded databases.

Can anyone suggest something I can try to find the source of this problem?

Thanks in advance for any assistance.

--James
[ December 17, 2008: Message edited by: James Adams ]
 
James Adams
Ranch Hand
Posts: 188
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I just worked out my problem -- as is often the case it was caused by my own foolishness.

One of my tests which wasn't extending the Spring transactional data source test class is testing one component which contains/uses a DAO component, and this DAO isn't being mocked in the test but instead is coming from the application context, and it's writing to the database as part of the test execution. Since this test is not in a transaction which is rolled back the data remains in the database and the following tests don't pass, since they're expected empty database tables. My original premise that I was running all my DB-related tests within transactional test case classes was wrong, and once I made it so everything worked as expected.

--James
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by James Adams:
I just worked out my problem -- as is often the case it was caused by my own foolishness.

One of my tests which wasn't extending the Spring transactional data source test class is testing one component which contains/uses a DAO component, and this DAO isn't being mocked in the test but instead is coming from the application context, and it's writing to the database as part of the test execution. Since this test is not in a transaction which is rolled back the data remains in the database and the following tests don't pass, since they're expected empty database tables. My original premise that I was running all my DB-related tests within transactional test case classes was wrong, and once I made it so everything worked as expected.

--James





Mark
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic