add testcase & bug fixed

This commit is contained in:
wenshao
2012-08-25 15:25:25 +08:00
parent 76eced3873
commit 10de685d05
4 changed files with 202 additions and 150 deletions
@@ -0,0 +1,60 @@
package com.alibaba.druid.bvt.pool;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.Properties;
import org.junit.Assert;
import junit.framework.TestCase;
import com.alibaba.druid.filter.FilterAdapter;
import com.alibaba.druid.filter.FilterChain;
import com.alibaba.druid.pool.DruidDataSource;
import com.alibaba.druid.proxy.jdbc.ConnectionProxy;
/**
* 这个场景测试minIdle > maxActive
*
* @author wenshao<szujobs@hotmail.com>
*/
public class DruidDataSourceTest_lastCreateError extends TestCase {
private DruidDataSource dataSource;
protected void setUp() throws Exception {
dataSource = new DruidDataSource();
dataSource.setUrl("jdbc:mock:xxx");
dataSource.setTestOnBorrow(false);
dataSource.getProxyFilters().add(new FilterAdapter() {
public ConnectionProxy connection_connect(FilterChain chain, Properties info) throws SQLException {
throw new SQLException();
}
});
}
protected void tearDown() throws Exception {
dataSource.close();
}
public void test_error() throws Exception {
Assert.assertNull(dataSource.getLastCreateError());
Assert.assertNull(dataSource.getLastCreateErrorTime());
Assert.assertEquals(0, dataSource.getLastCreateErrorTimeMillis());
Exception error = null;
try {
dataSource.getConnection(100);
} catch (Exception e) {
error = e;
}
Assert.assertNotNull(error);
Assert.assertNotNull(dataSource.getLastCreateError());
Assert.assertNotNull(dataSource.getLastCreateErrorTime());
Assert.assertEquals(true, dataSource.getLastCreateErrorTimeMillis() > 0);
}
}
@@ -0,0 +1,62 @@
package com.alibaba.druid.bvt.pool;
import java.sql.Connection;
import java.sql.SQLException;
import org.junit.Assert;
import junit.framework.TestCase;
import com.alibaba.druid.filter.FilterAdapter;
import com.alibaba.druid.filter.FilterChain;
import com.alibaba.druid.pool.DruidDataSource;
import com.alibaba.druid.proxy.jdbc.ConnectionProxy;
/**
* 这个场景测试minIdle > maxActive
*
* @author wenshao<szujobs@hotmail.com>
*/
public class DruidDataSourceTest_lastError extends TestCase {
private DruidDataSource dataSource;
protected void setUp() throws Exception {
dataSource = new DruidDataSource();
dataSource.setUrl("jdbc:mock:xxx");
dataSource.setTestOnBorrow(false);
dataSource.getProxyFilters().add(new FilterAdapter() {
public void connection_setAutoCommit(FilterChain chain, ConnectionProxy connection, boolean autoCommit)
throws SQLException {
throw new SQLException();
}
});
}
protected void tearDown() throws Exception {
dataSource.close();
}
public void test_error() throws Exception {
Assert.assertNull(dataSource.getLastError());
Assert.assertNull(dataSource.getLastErrorTime());
Assert.assertEquals(0, dataSource.getLastErrorTimeMillis());
Connection conn = dataSource.getConnection();
Exception error = null;
try {
conn.setAutoCommit(false);
} catch (Exception e) {
error = e;
}
Assert.assertNotNull(error);
Assert.assertNotNull(dataSource.getLastError());
Assert.assertNotNull(dataSource.getLastErrorTime());
Assert.assertEquals(true, dataSource.getLastErrorTimeMillis() > 0);
}
}
@@ -35,10 +35,16 @@ public class DruidDataSourceTest_oracle2 extends TestCase {
dataSource.close();
}
public void test_error() throws Exception {
public void test_oracle() throws Exception {
Assert.assertNull(dataSource.getConnectProperties().get("oracle.jdbc.FreeMemoryOnEnterImplicitCache"));
dataSource.init();
Assert.assertTrue(dataSource.isOracle());
Assert.assertEquals("true", dataSource.getConnectProperties().get("oracle.jdbc.FreeMemoryOnEnterImplicitCache"));
dataSource.setUseOracleImplicitCache(false);
Assert.assertNull(dataSource.getConnectProperties().get("oracle.jdbc.FreeMemoryOnEnterImplicitCache"));
dataSource.setUseOracleImplicitCache(true);
Assert.assertEquals("true", dataSource.getConnectProperties().get("oracle.jdbc.FreeMemoryOnEnterImplicitCache"));
}
}