mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
完善mock和测试
git-svn-id: http://code.alibabatech.com/svn/druid/trunk@827 b9813039-fb51-4c41-a8b9-e21c2acb5095
This commit is contained in:
+1
-1
@@ -12,7 +12,7 @@ import com.alibaba.druid.pool.DruidDataSource;
|
||||
import com.alibaba.druid.stat.DruidDataSourceStatManager;
|
||||
import com.mysql.jdbc.ResultSet;
|
||||
|
||||
public class ConnectionStatementTest extends TestCase {
|
||||
public class ConnectionTest extends TestCase {
|
||||
|
||||
private MockDriver driver;
|
||||
private DruidDataSource dataSource;
|
||||
+1
-1
@@ -12,7 +12,7 @@ import com.alibaba.druid.pool.DruidDataSource;
|
||||
import com.alibaba.druid.stat.DruidDataSourceStatManager;
|
||||
import com.mysql.jdbc.ResultSet;
|
||||
|
||||
public class ConnectionStatementTest2 extends TestCase {
|
||||
public class ConnectionTest2 extends TestCase {
|
||||
|
||||
private MockDriver driver;
|
||||
private DruidDataSource dataSource;
|
||||
@@ -1,5 +1,8 @@
|
||||
package com.alibaba.druid.bvt.pool.basic;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.Properties;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
@@ -33,7 +36,7 @@ public class ConnectionTest5 extends TestCase {
|
||||
dataSource.setTestOnBorrow(false);
|
||||
dataSource.setValidationQuery("SELECT 1");
|
||||
dataSource.setFilters("stat,trace");
|
||||
|
||||
|
||||
JdbcStatContext context = new JdbcStatContext();
|
||||
context.setTraceEnable(true);
|
||||
JdbcStatManager.getInstance().setStatContext(context);
|
||||
@@ -42,26 +45,120 @@ public class ConnectionTest5 extends TestCase {
|
||||
protected void tearDown() throws Exception {
|
||||
dataSource.close();
|
||||
Assert.assertEquals(0, DruidDataSourceStatManager.getInstance().getDataSourceList().size());
|
||||
|
||||
|
||||
JdbcStatManager.getInstance().setStatContext(null);
|
||||
}
|
||||
|
||||
public void test_basic() throws Exception {
|
||||
PoolableConnection conn = (PoolableConnection) dataSource.getConnection();
|
||||
conn.close();
|
||||
|
||||
|
||||
Assert.assertEquals(true, dataSource.isResetStatEnable());
|
||||
dataSource.setResetStatEnable(false);
|
||||
Assert.assertEquals(false, dataSource.isResetStatEnable());
|
||||
Assert.assertEquals(1, dataSource.getConnectCount());
|
||||
dataSource.resetStat();
|
||||
Assert.assertEquals(1, dataSource.getConnectCount());
|
||||
|
||||
|
||||
dataSource.setResetStatEnable(true);
|
||||
dataSource.resetStat();
|
||||
Assert.assertEquals(0, dataSource.getConnectCount());
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void test_handleException() throws Exception {
|
||||
PoolableConnection conn = (PoolableConnection) dataSource.getConnection();
|
||||
conn.close();
|
||||
|
||||
SQLException error = new SQLException();
|
||||
try {
|
||||
conn.handleException(error);
|
||||
} catch (SQLException ex) {
|
||||
Assert.assertEquals(error, ex);
|
||||
}
|
||||
}
|
||||
|
||||
public void test_handleException_2() throws Exception {
|
||||
PoolableConnection conn = dataSource.getConnection().unwrap(PoolableConnection.class);
|
||||
conn.getConnection().close();
|
||||
|
||||
{
|
||||
SQLException error = null;
|
||||
try {
|
||||
conn.handleException(new RuntimeException());
|
||||
} catch (SQLException ex) {
|
||||
error = ex;
|
||||
}
|
||||
Assert.assertNotNull(error);
|
||||
}
|
||||
|
||||
conn.close();
|
||||
}
|
||||
|
||||
|
||||
public void test_handleException_3() throws Exception {
|
||||
PoolableConnection conn = dataSource.getConnection().unwrap(PoolableConnection.class);
|
||||
conn.getConnection().close();
|
||||
|
||||
{
|
||||
SQLException error = null;
|
||||
try {
|
||||
conn.handleException(new RuntimeException());
|
||||
} catch (SQLException ex) {
|
||||
error = ex;
|
||||
}
|
||||
Assert.assertNotNull(error);
|
||||
}
|
||||
|
||||
conn.close();
|
||||
}
|
||||
|
||||
public void test_handleException_4() throws Exception {
|
||||
PoolableConnection conn = dataSource.getConnection().unwrap(PoolableConnection.class);
|
||||
conn.getConnection().close();
|
||||
|
||||
{
|
||||
SQLException error = null;
|
||||
try {
|
||||
conn.prepareStatement("SELECT 1");
|
||||
} catch (SQLException ex) {
|
||||
error = ex;
|
||||
}
|
||||
Assert.assertNotNull(error);
|
||||
}
|
||||
|
||||
Assert.assertEquals(true, conn.isClosed());
|
||||
}
|
||||
|
||||
|
||||
public void test_setClientInfo() throws Exception {
|
||||
PoolableConnection conn = dataSource.getConnection().unwrap(PoolableConnection.class);
|
||||
conn.close();
|
||||
|
||||
{
|
||||
SQLException error = null;
|
||||
try {
|
||||
conn.setClientInfo("name", "xxx");
|
||||
} catch (SQLException ex) {
|
||||
error = ex;
|
||||
}
|
||||
Assert.assertNotNull(error);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void test_setClientInfo_1() throws Exception {
|
||||
PoolableConnection conn = dataSource.getConnection().unwrap(PoolableConnection.class);
|
||||
conn.close();
|
||||
|
||||
{
|
||||
SQLException error = null;
|
||||
try {
|
||||
conn.setClientInfo(new Properties());
|
||||
} catch (SQLException ex) {
|
||||
error = ex;
|
||||
}
|
||||
Assert.assertNotNull(error);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user