2009-10-21 65 views
0

dbUnit有一个奇怪的问题。 我使用dbUnit 2.4.4,java 1.6,Spring(作为db连接池),Oracle 9为我的项目进行了大约50次单元测试。 对于他们中的一些(当我运行一整套测试),我得到这样的例外:dbUnit问题:java.sql.SQLException:已关闭语​​句

Closed Statement 
[junit] junit.framework.AssertionFailedError: Closed Statement 
[junit]  at com.myproj.DataAccess.Internal.BaseDAOTest.importToDb(Unknown Source) 
[junit]  at com.myproj.DataAccess.Internal.MyDAOTest.testGetBuyClientOrders(Unknown Source) 
[junit]  at org.eclipse.ant.internal.ui.antsupport.EclipseDefaultExecutor.executeTargets(EclipseDefaultExecutor.java:32) 
[junit]  at org.eclipse.ant.internal.ui.antsupport.InternalAntRunner.run(InternalAntRunner.java:423) 
[junit]  at org.eclipse.ant.internal.ui.antsupport.InternalAntRunner.main(InternalAntRunner.java:137) 

importToDb方法加载测试数据从XML文件通过DbUnit的DatabaseOperation.REFRESH.execute方法数据库,它在所有使用试验。 如果我单独运行这些测试问题,对他们来说没有任何问题。 你有什么想法吗?谢谢!

+0

我们可以看到importToDb代码清除超时?助教。 – 2009-10-21 15:03:11

+0

这里是http://pastebin.com/mf19de0a – dbf 2009-10-21 15:07:28

回答

1

我想你的一些测试在清理时会关闭数据库连接。下一个测试尝试再次使用此连接进行导入并失败。

+0

我没有在任何测试中明确关闭连接。他们都使用Spring DAO库中的jdbcTemplate,所以我不需要手动连接。导入功能中的连接已关闭,但对于所有测试,此功能都是相同的。 – dbf 2009-10-21 15:13:47

+0

你使用哪种数据源?它是'SingleConnectionDataSource'吗? – tangens 2009-10-21 16:21:17

+0

来自我的Spring配置的数据源描述: <属性名= “driverClassName” 值= “$ {jdbc.driver.class}”/> <属性名= “URL” 值= “$ {jdbc.url}”/> <属性名=“用户名“value =”$ {jdbc.username}“/> < property name =“maxOpenPreparedStatements”value =“20”/> dbf 2009-10-21 17:40:36

1

当这发生在我身上,我们已经明确地配置了连接高速缓存使用两个属性狙击持久连接:

AbandonedConnectionTimeout 
InactivityTimeout 

See Oracle's docs here regarding timeout properties

原来查询+处理时间只是跳过这两个属性的合并(AbandonedConnectionTimeout + InactivityTimeout <查询时间+结果集处理时间)。

为了解决这个问题,你可以提高你的超时限制,或者你可以将它们设置为0(默认值)