mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
add testcase & bug fixed
This commit is contained in:
@@ -0,0 +1,84 @@
|
||||
package com.alibaba.druid.bvt.pool;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.ResultSet;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.pool.DruidDataSource;
|
||||
import com.alibaba.druid.pool.DruidPooledPreparedStatement;
|
||||
|
||||
public class DruidPooledPreparedStatementTest extends TestCase {
|
||||
|
||||
private DruidDataSource dataSource;
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
dataSource = new DruidDataSource();
|
||||
dataSource.setUrl("jdbc:mock:xxx");
|
||||
dataSource.setTestOnBorrow(false);
|
||||
dataSource.setFilters("stat");
|
||||
dataSource.setPoolPreparedStatements(true);
|
||||
}
|
||||
|
||||
protected void tearDown() throws Exception {
|
||||
dataSource.close();
|
||||
}
|
||||
|
||||
public void test_hitCount() throws Exception {
|
||||
String sql = "select ?";
|
||||
{
|
||||
Connection conn = dataSource.getConnection();
|
||||
DruidPooledPreparedStatement stmt = (DruidPooledPreparedStatement) conn.prepareStatement(sql);
|
||||
|
||||
Assert.assertEquals(0, stmt.getFetchSize());
|
||||
Assert.assertEquals(0, stmt.getFetchDirection());
|
||||
Assert.assertEquals(0, stmt.getMaxRows());
|
||||
Assert.assertEquals(0, stmt.getMaxFieldSize());
|
||||
Assert.assertEquals(0, stmt.getQueryTimeout());
|
||||
Assert.assertEquals(sql, stmt.getSql());
|
||||
|
||||
stmt.setFetchSize(1);
|
||||
stmt.setFetchDirection(2);
|
||||
stmt.setMaxRows(3);
|
||||
stmt.setMaxFieldSize(4);
|
||||
stmt.setQueryTimeout(5);
|
||||
|
||||
Assert.assertEquals(1, stmt.getFetchSize());
|
||||
Assert.assertEquals(2, stmt.getFetchDirection());
|
||||
Assert.assertEquals(3, stmt.getMaxRows());
|
||||
Assert.assertEquals(4, stmt.getMaxFieldSize());
|
||||
Assert.assertEquals(5, stmt.getQueryTimeout());
|
||||
|
||||
stmt.setString(1, "xx");
|
||||
ResultSet rs = stmt.executeQuery();
|
||||
Assert.assertTrue(rs.next());
|
||||
Assert.assertFalse(rs.next());
|
||||
rs.close();
|
||||
conn.close();
|
||||
|
||||
Assert.assertEquals(0, stmt.getHitCount());
|
||||
}
|
||||
{
|
||||
Connection conn = dataSource.getConnection();
|
||||
DruidPooledPreparedStatement stmt = (DruidPooledPreparedStatement) conn.prepareStatement(sql);
|
||||
|
||||
Assert.assertEquals(0, stmt.getFetchSize());
|
||||
Assert.assertEquals(0, stmt.getFetchDirection());
|
||||
Assert.assertEquals(0, stmt.getMaxRows());
|
||||
Assert.assertEquals(0, stmt.getMaxFieldSize());
|
||||
Assert.assertEquals(0, stmt.getQueryTimeout());
|
||||
|
||||
stmt.setString(1, "xx");
|
||||
ResultSet rs = stmt.executeQuery();
|
||||
Assert.assertTrue(rs.next());
|
||||
Assert.assertFalse(rs.next());
|
||||
rs.close();
|
||||
conn.close();
|
||||
|
||||
Assert.assertEquals(1, stmt.getHitCount());
|
||||
Assert.assertNotNull(stmt.getKey());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user