if config incorrect, log error

This commit is contained in:
wenshao
2012-08-07 07:51:15 +08:00
parent f458f31edb
commit 0c4b481c01
9 changed files with 127 additions and 3 deletions
@@ -2,6 +2,7 @@ package com.alibaba.druid.bvt.pool;
import java.sql.Connection;
import junit.framework.Assert;
import junit.framework.TestCase;
import com.alibaba.druid.pool.DruidDataSource;
@@ -21,8 +22,12 @@ public class ConfigErrorTest extends TestCase {
}
public void test_connect() throws Exception {
Connection conn = dataSource.getConnection();
DruidDataSource.LOG.resetStat();
Assert.assertEquals(0, DruidDataSource.LOG.getErrorCount());
Connection conn = dataSource.getConnection();
conn.close();
Assert.assertEquals(1, DruidDataSource.LOG.getErrorCount());
}
}
@@ -0,0 +1,35 @@
package com.alibaba.druid.bvt.pool;
import java.sql.Connection;
import junit.framework.Assert;
import junit.framework.TestCase;
import com.alibaba.druid.pool.DruidDataSource;
public class ConfigErrorTest2 extends TestCase {
private DruidDataSource dataSource;
protected void setUp() throws Exception {
dataSource = new DruidDataSource();
dataSource.setUrl("jdbc:wrap-jdbc:jdbc:mock:xxx");
dataSource.setTestOnBorrow(false);
dataSource.setTestOnReturn(false);
dataSource.setTestWhileIdle(false);
}
protected void tearDown() throws Exception {
dataSource.close();
}
public void test_connect() throws Exception {
DruidDataSource.LOG.resetStat();
Assert.assertEquals(0, DruidDataSource.LOG.getErrorCount());
Connection conn = dataSource.getConnection();
conn.close();
Assert.assertEquals(1, DruidDataSource.LOG.getErrorCount());
}
}
@@ -0,0 +1,32 @@
package com.alibaba.druid.bvt.pool;
import junit.framework.Assert;
import junit.framework.TestCase;
import com.alibaba.druid.pool.DruidDataSource;
public class ConfigErrorTest3 extends TestCase {
private DruidDataSource dataSource;
protected void setUp() throws Exception {
dataSource = new DruidDataSource();
dataSource.setUrl("jdbc:mysql:xxx");
dataSource.setTestOnBorrow(false);
dataSource.setTestOnReturn(false);
dataSource.setTestWhileIdle(false);
dataSource.setInitialSize(0);
dataSource.setPoolPreparedStatements(true);
}
protected void tearDown() throws Exception {
dataSource.close();
}
public void test_connect() throws Exception {
DruidDataSource.LOG.resetStat();
Assert.assertEquals(0, DruidDataSource.LOG.getErrorCount());
dataSource.init();
Assert.assertEquals(1, DruidDataSource.LOG.getErrorCount());
}
}