dbUnit 问题:java.sql.SQLException:已关闭语句
我对 dbUnit 有一个奇怪的问题。 我的项目使用了 dbUnit 2.4.4、java 1.6、Spring(作为数据库连接池)、Oracle 9,进行了大约 50 个单元测试。 对于其中一些(当我运行整套测试时)我得到这样的异常:
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 方法通过 dbUnit 的 DatabaseOperation.REFRESH.execute 方法将测试数据从 XML 文件加载到数据库,并且在所有测试中使用。 如果我单独运行这些有问题的测试,那么它们就没有问题。 你有什么想法吗?谢谢!
I have a strange problem with dbUnit.
I use dbUnit 2.4.4, java 1.6, Spring (as db connection pool), Oracle 9 for my project with about 50 unit tests.
For some of them (when I run whole set of tests) I get such exception:
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 method loads test data from XML file to database via dbUnit's DatabaseOperation.REFRESH.execute method and it is used in ALL tests.
If I run these tests with problems separately, there is no problems for them.
Do you have any ideas? Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我猜你的一些测试在清理时会关闭数据库连接。下一个测试尝试再次使用此连接进行导入,但失败。
I guess some of your tests close the database connection when they clean up. The next test tries to use this connection again for the import and fails.
当这种情况发生在我身上时,我们已显式配置连接缓存以使用两个属性来狙击持久连接:
请参阅此处有关超时属性的 Oracle 文档
事实证明,查询+处理时间只是跳过了两个属性组合的尖点(AbandonedConnectionTimeout + InactivityTimeout < 查询时间+ 结果集处理时间)。
要解决此问题,您可以提高超时限制,也可以通过将超时限制设置为 0(默认)来删除超时
When this happened to me, we had explicitly configured our connection cache to snipe long-lasting connections using two properties:
See Oracle's docs here regarding timeout properties
It turned out that the query+processing time was just jumping the cusp of the two properties combined (AbandonedConnectionTimeout + InactivityTimeout < query time + resultset processing time).
To fix the issue, you can either raise your timeout limits or you can remove the timeout by setting them to 0 (the default)