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,83 @@
|
||||
package com.alibaba.druid.bvt.pool;
|
||||
|
||||
import java.sql.Connection;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import com.alibaba.druid.pool.DruidDataSource;
|
||||
import com.alibaba.druid.pool.DruidPooledConnection;
|
||||
|
||||
public class DruidPooledConnectionTest extends TestCase {
|
||||
|
||||
private DruidDataSource dataSource;
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
dataSource = new DruidDataSource();
|
||||
dataSource.setUrl("jdbc:mock:xxx");
|
||||
dataSource.setTestOnBorrow(false);
|
||||
dataSource.setFilters("stat");
|
||||
}
|
||||
|
||||
protected void tearDown() throws Exception {
|
||||
dataSource.close();
|
||||
}
|
||||
|
||||
public void test_rollback() throws Exception {
|
||||
Connection conn = dataSource.getConnection();
|
||||
conn.rollback();
|
||||
conn.rollback(null);
|
||||
|
||||
conn.close();
|
||||
}
|
||||
|
||||
public void test_rollback_1() throws Exception {
|
||||
Connection conn = dataSource.getConnection();
|
||||
conn.setAutoCommit(false);
|
||||
|
||||
conn.close();
|
||||
conn.rollback();
|
||||
conn.rollback(null);
|
||||
}
|
||||
|
||||
public void test_getOwnerThread() throws Exception {
|
||||
DruidPooledConnection conn = (DruidPooledConnection) dataSource.getConnection();
|
||||
|
||||
Assert.assertEquals(Thread.currentThread(), conn.getOwnerThread());
|
||||
|
||||
conn.close();
|
||||
}
|
||||
|
||||
public void test_isDiable() throws Exception {
|
||||
DruidPooledConnection conn = (DruidPooledConnection) dataSource.getConnection();
|
||||
|
||||
Assert.assertEquals(false, conn.isDisable());
|
||||
|
||||
conn.close();
|
||||
|
||||
Assert.assertEquals(true, conn.isDisable());
|
||||
}
|
||||
|
||||
public void test_dupClose() throws Exception {
|
||||
DruidPooledConnection conn = (DruidPooledConnection) dataSource.getConnection();
|
||||
|
||||
conn.close();
|
||||
conn.close();
|
||||
}
|
||||
|
||||
public void test_disable() throws Exception {
|
||||
Assert.assertEquals(0, dataSource.getPoolingCount());
|
||||
Assert.assertEquals(0, dataSource.getActiveCount());
|
||||
|
||||
DruidPooledConnection conn = (DruidPooledConnection) dataSource.getConnection();
|
||||
conn.disable();
|
||||
Assert.assertEquals(true, conn.isDisable());
|
||||
|
||||
Assert.assertEquals(1, dataSource.getActiveCount());
|
||||
|
||||
conn.close();
|
||||
|
||||
Assert.assertEquals(0, dataSource.getPoolingCount());
|
||||
Assert.assertEquals(1, dataSource.getActiveCount());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user