0
我正在运行一些单元测试,但我看到一些奇怪的行为,关于连接在使用后没有被释放到池中(这不可避免地导致单元测试在测试次数达到时挂起池大小)Groovy SQL连接没有被关闭
为了证明,我创建了一个非常简单的单元测试:
@Before void setUp(){
sql = new Sql(getDataSource())
println getDataSource().getNumActive()
}
@After void tearDown(){
sql.close()
}
@Test void test1(){
println sql.rows("select 1")
}
@Test void test2(){
println sql.rows("select 1")
}
@Test void test3(){
println sql.rows("select 1")
}
@Test void test4(){
println sql.rows("select 1")
}
在我的设置方法,我的了getDataSource()方法只返回一个静态的,初始化的BasicDataSource(所以这是每次相同的数据源)。
我也明确地调用close在拆卸方法,我的SQL对象上,即使Groovy中说,在其docs是你没有用DataSource构建您的SQL对象时
public Sql(javax.sql.DataSource dataSource)
Constructs an SQL instance using the given DataSource. Each operation will use a Connection from the DataSource pool and close it when the operation is completed putting it back into the pool.
。然而,当我运行测试,活动连接的数量继续增加,如果我将最大池大小设置为2,那么将在第二次测试后无限期地挂起。
任何人都可以建议为什么连接不被返回?
谢谢。