Announcement Announcement Module
Collapse
No announcement yet.
An odd-ball dao test that is not rolling back Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • An odd-ball dao test that is not rolling back

    I'm having a really frustrating time with this one test case. When I'm deleting from the db through hibernate, the test case is not rolling back... even though the other 100 tests in the suite are rolling back just fine. I'm totally at a loss.

    This is a big problem because, of course, when this row gets deleted... a whole bunch of other crap gets deleted too and then the state of the database is totally messed up, causing a bunch of other tests to fail. It also means I have to restore the state of the database (which just so happened to be done manually since I didn't back up the test database......)

    Help?

    Code:
    @RunWith( SpringJUnit4ClassRunner.class )
    @ContextConfiguration( locations = ObjectMother.APPLICATION_CONTEXT )
    @Transactional
    public class QuestionDaoTests {
    
    	@Autowired
    	private QuestionDao questionDao;
    
    	....
    
    	@Test
    	public void testDelete() {
    		questionDao.delete( questionDao.find( 1 ) );
    
    		Assert.assertNull( questionDao.find( 1 ) );
    	}
    
            ....
    
    }
    The delete method is pretty simple. I have to remove the question from the task in order to prevent Hibernate from re-saving the question on the cascade.
    Code:
    	public void delete( Question question ) {
    		question.getTask().removeQuestion( question );
    
    		sessionFactory.getCurrentSession().delete( question );
    	}
    Here's some DEBUG log info. As you can see, it's getting rolled-back... but the database from postgres is nuked 100%

    Code:
    DEBUG [org.springframework.test.context.junit4.SpringMethodRoadie] - Test method [public void jobprep.dao.QuestionDaoTests.testDelete()] threw exception: null
    DEBUG [org.springframework.test.context.transaction.TransactionalTestExecutionListener] - Retrieved @TransactionConfiguration [null] for test class [class jobprep.dao.QuestionDaoTests]
    DEBUG [org.springframework.test.context.transaction.TransactionalTestExecutionListener] - Retrieved TransactionConfigurationAttributes [[TransactionConfigurationAttributes@17748d3 transactionManagerName = 'transactionManager', defaultRollback = true]] for class [class jobprep.dao.QuestionDaoTests]
    DEBUG [org.springframework.test.context.transaction.TransactionalTestExecutionListener] - Method-level @Rollback(true) overrides default rollback [true] for test context [[TestContext@1d99a4d testClass = QuestionDaoTests, locations = array<String>['file:war/WEB-INF/applicationContext.xml'], testInstance = jobprep.dao.QuestionDaoTests@12152e6, testMethod = testDelete@QuestionDaoTests, testException = [null]]]
    DEBUG [org.springframework.jdbc.datasource.DataSourceTransactionManager] - Initiating transaction rollback
    DEBUG [org.springframework.jdbc.datasource.DataSourceTransactionManager] - Rolling back JDBC transaction on Connection [jdbc:postgresql://localhost:5432/jobprep, UserName=postgres, PostgreSQL Native Driver]
    DEBUG [org.springframework.orm.hibernate3.SessionFactoryUtils] - Closing Hibernate Session
    DEBUG [org.hibernate.jdbc.ConnectionManager] - releasing JDBC connection [ (open PreparedStatements: 0, globally: 0) (open ResultSets: 0, globally: 0)]
    DEBUG [org.hibernate.jdbc.ConnectionManager] - transaction completed on session with on_close connection release mode; be sure to close the session to release JDBC resources!
    DEBUG [org.springframework.jdbc.datasource.DataSourceTransactionManager] - Releasing JDBC Connection [jdbc:postgresql://localhost:5432/jobprep, UserName=postgres, PostgreSQL Native Driver] after transaction
    DEBUG [org.springframework.jdbc.datasource.DataSourceUtils] - Returning JDBC Connection to DataSource
    INFO [org.springframework.test.context.transaction.TransactionalTestExecutionListener] - Rolled back transaction after test execution for test context [[TestContext@1d99a4d testClass = QuestionDaoTests, locations = array<String>['file:war/WEB-INF/applicationContext.xml'], testInstance = jobprep.dao.QuestionDaoTests@12152e6, testMethod = testDelete@QuestionDaoTests, testException = [null]]]
    DEBUG [org.springframework.test.context.support.DirtiesContextTestExecutionListener] - After test method: context [[TestContext@1d99a4d testClass = QuestionDaoTests, locations = array<String>['file:war/WEB-INF/applicationContext.xml'], testInstance = jobprep.dao.QuestionDaoTests@12152e6, testMethod = testDelete@QuestionDaoTests, testException = [null]]], dirtiesContext [false].
    INFO [org.springframework.context.support.GenericApplicationContext] - Closing [email protected]4cb: display name [[email protected]4cb]; startup date [Mon May 25 00:55:03 EDT 2009]; root of context hierarchy
    INFO [org.springframework.beans.factory.support.DefaultListableBeanFactory] - Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@182da3d: defining beans [dataSource,sessionFactory,transactionManager,org.springframework.aop.config.internalAutoProxyCreator,userServiceMethods,org.springframework.aop.support.DefaultBeanFactoryPointcutAdvisor#0,transactionAdvice,activeModuleDaoImpl,activeQuestionDaoImpl,categoryAnswerDaoImpl,categoryDaoImpl,educationFacilityDaoImpl,hintDaoImpl,moduleDaoImpl,questionDaoImpl,taskDaoImpl,textAnswerDaoImpl,userDaoImpl,jobPrepServiceImpl,userServiceImpl,org.springframework.context.annotation.internalPersistenceAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor]; root of factory hierarchy
    DEBUG [org.springframework.beans.factory.support.DefaultListableBeanFactory] - Retrieved dependent beans for bean 'taskDaoImpl': [jobprep.dao.QuestionDaoTests]
    DEBUG [org.springframework.beans.factory.support.DefaultListableBeanFactory] - Retrieved dependent beans for bean '(inner bean)': [transactionAdvice]
    DEBUG [org.springframework.beans.factory.support.DisposableBeanAdapter] - Invoking destroy() on bean with name 'sessionFactory'
    INFO [org.springframework.orm.hibernate3.LocalSessionFactoryBean] - Closing Hibernate SessionFactory
    INFO [org.hibernate.impl.SessionFactoryImpl] - closing
    DEBUG [org.springframework.beans.factory.support.DisposableBeanAdapter] - Invoking destroy method 'close' on bean with name 'dataSource'

  • #2
    Does anyone use the transactional tests like I'm doing? How are you doing tests if you're not doing them this way? This is really frustrating me, as I'm actually starting to think this is a bug in spring, hibernate or postgres... or the interaction between the 3. Is DBUnit needed to solve this problem now? Is that really my last resort?

    Comment

    Working...
    X