Quantcast
Channel: Liquibase Forums
Viewing all articles
Browse latest Browse all 2993

rollbacks not working if Spring starts them even if runInTransaction=false

$
0
0
So, I have a lot of INSERTs that I wanna do inside a Spring-driven JUnit test.  My changesets look like:
  1.      < changeSet runInTransaction = "false" author = "me (generated)" id = "1413580824558-29" >
  2.          < insert tableName = "some_table" >
  3.              < column name = "id" valueNumeric = "10" />
  4.               < column name = "created" valueDate = "2014-10-17 10:25:55.0" />
  5.              < column name = "modified" valueDate = "2014-10-17 10:25:55.0" />
  6.          </ insert >


My Spring-driven JUnit test looks like:

  1. @RunWith (SpringJUnit4ClassRunner. class )
  2. @ContextConfiguration (classes= {PersistenceJPAConfig. class })
  3. @Transactional ()
  4. @TestExecutionListeners ({
  5.      DependencyInjectionTestExecutionListener. class ,
  6.      TransactionalTestExecutionListener. class
  7.      })
  8. @TransactionConfiguration (defaultRollback= true )
  9. public class DatabaseBasedIT {


I have a method that loads a changelog via the Spring-bean:

  1.      protected void loadLiquibaseChangelog(String changelogFilename ) throws LiquibaseException {
  2.          SpringLiquibase springLiquibase = new SpringLiquibase();
  3.          springLiquibase .setDataSource( ds );
  4.          springLiquibase .setChangeLog( changelogFilename );
  5.          springLiquibase .setResourceLoader( resourceLoader );
  6.          springLiquibase .afterPropertiesSet();
  7.     }


Spring says it rolled back the tx:


  1. INFO 10/22/14 10:16 PM: liquibase: Successfully released change log lock
  2. Oct 22, 2014 10:16:54 PM org.springframework.test.context.transaction.TransactionContext endTransaction
  3. INFO: Rolled back transaction for test context [DefaultTestContext@14af2ab6 testClass = DatabaseBasedIT, testInstance =DatabaseBasedIT@2e5e130a, testMethod = onlyLoadsChangeLogFromLiquibase@DatabaseBasedIT, testException = [null], mergedContextConfiguration = [MergedContextConfiguration@3f70f50e testClass = DatabaseBasedIT, locations = '{}', classes = '{class PersistenceJPAConfig}', contextInitializerClasses = '[]', activeProfiles = '{}', propertySourceLocations = '{}', propertySourceProperties = '{}', contextLoader = 'org.springframework.test.context.support.DelegatingSmartContextLoader', parent = [null]]].


But the data doesn't actually get rolled back because the data is still left over after the tests are done.  (If I manually INSERT the data using the DataSource that Spring gives me, that gets rolled back properly.


Looking at the code for liquibase.changelog. ChangeSet and setting some breakpoints, I can see that autocommit is set to true.  Could this be the reason that the liquibase data isn't rolled back?


P.S. I can create a small sample project if need be, but I'm hoping it's easy enough to figure out with that. ;) 


Viewing all articles
Browse latest Browse all 2993

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>