git-svn-id: http://code.alibabatech.com/svn/druid/trunk@711 b9813039-fb51-4c41-a8b9-e21c2acb5095
This commit is contained in:
wenshao
2011-09-09 17:17:53 +00:00
parent 855c960172
commit 1871aaf77a
@@ -0,0 +1,63 @@
package com.alibaba.druid.bvt.pool;
import java.sql.Connection;
import java.sql.PreparedStatement;
import junit.framework.Assert;
import junit.framework.TestCase;
import com.alibaba.druid.mock.MockDriver;
import com.alibaba.druid.mock.MockPreparedStatement;
import com.alibaba.druid.pool.DruidDataSource;
public class TestPoolPreparedStatement extends TestCase {
private MockDriver driver;
private DruidDataSource dataSource;
protected void setUp() throws Exception {
driver = new MockDriver();
dataSource = new DruidDataSource();
dataSource.setUrl("jdbc:mock:xxx");
dataSource.setDriver(driver);
dataSource.setInitialSize(1);
dataSource.setMaxActive(2);
dataSource.setMaxIdle(2);
dataSource.setMinIdle(1);
dataSource.setMinEvictableIdleTimeMillis(300 * 1000); // 300 / 10
dataSource.setTimeBetweenEvictionRunsMillis(10); // 180 / 10
dataSource.setTestWhileIdle(true);
dataSource.setTestOnBorrow(false);
dataSource.setValidationQuery("SELECT 1");
dataSource.setFilters("stat");
dataSource.setPoolPreparedStatements(true);
}
protected void tearDown() throws Exception {
dataSource.close();
}
public void test_removeAbandoned() throws Exception {
MockPreparedStatement raw;
{
Connection conn = dataSource.getConnection();
PreparedStatement stmt = conn.prepareStatement("SELECT ?");
raw = stmt.unwrap(MockPreparedStatement.class);
stmt.close();
conn.close();
}
{
Connection conn = dataSource.getConnection();
PreparedStatement stmt = conn.prepareStatement("SELECT ?");
Assert.assertTrue(raw == stmt.unwrap(MockPreparedStatement.class));
stmt.close();
conn.close();
}
Assert.assertEquals(0, dataSource.getActiveCount());
Assert.assertEquals(1, dataSource.getPoolingCount());
}
}