完善mock和测试

git-svn-id: http://code.alibabatech.com/svn/druid/trunk@836 b9813039-fb51-4c41-a8b9-e21c2acb5095
This commit is contained in:
wenshao
2011-09-18 07:00:02 +00:00
parent 4ed95e9e0f
commit a5d592933b
5 changed files with 115 additions and 52 deletions
@@ -746,10 +746,10 @@ public abstract class DruidAbstractDataSource extends WrapperAdapter implements
// 兼容JBOSS
public void setExceptionSorterClassName(String exceptionSorter) throws Exception {
this.setExceptionSoter(exceptionSorter);
this.setExceptionSorter(exceptionSorter);
}
public void setExceptionSoter(String exceptionSorter) throws Exception {
public void setExceptionSorter(String exceptionSorter) throws Exception {
if (exceptionSorter == null) {
this.exceptionSoter = NullExceptionSorter.getInstance();
return;
@@ -284,12 +284,12 @@ public class DruidDataSourceFactory implements ObjectFactory {
value = properties.getProperty(PROP_EXCEPTION_SORTER);
if (value != null) {
dataSource.setExceptionSoter(value);
dataSource.setExceptionSorter(value);
}
value = properties.getProperty(PROP_EXCEPTION_SORTER_CLASS_NAME);
if (value != null) {
dataSource.setExceptionSoter(value);
dataSource.setExceptionSorter(value);
}
value = properties.getProperty(PROP_INITCONNECTIONSQLS);
@@ -1,13 +1,18 @@
package com.alibaba.druid.bvt.pool.basic;
import java.util.Collections;
import java.util.Properties;
import javax.security.auth.callback.PasswordCallback;
import junit.framework.Assert;
import junit.framework.TestCase;
import com.alibaba.druid.mock.MockDriver;
import com.alibaba.druid.pool.DruidDataSource;
import com.alibaba.druid.pool.PoolableConnection;
import com.alibaba.druid.pool.vendor.MySqlValidConnectionChecker;
import com.alibaba.druid.pool.vendor.NullExceptionSorter;
import com.alibaba.druid.stat.DruidDataSourceStatManager;
import com.alibaba.druid.stat.JdbcStatContext;
import com.alibaba.druid.stat.JdbcStatManager;
@@ -64,12 +69,12 @@ public class DataSourceTest3 extends TestCase {
Assert.assertNotNull(error);
}
}
public void test_error_1() throws Exception {
PoolableConnection conn = dataSource.getConnection().unwrap(PoolableConnection.class);
conn.close();
{
Exception error = null;
try {
@@ -80,12 +85,12 @@ public class DataSourceTest3 extends TestCase {
Assert.assertNotNull(error);
}
}
public void test_error_2() throws Exception {
PoolableConnection conn = dataSource.getConnection().unwrap(PoolableConnection.class);
conn.close();
{
Exception error = null;
try {
@@ -96,12 +101,12 @@ public class DataSourceTest3 extends TestCase {
Assert.assertNotNull(error);
}
}
public void test_error_3() throws Exception {
PoolableConnection conn = dataSource.getConnection().unwrap(PoolableConnection.class);
conn.close();
{
Exception error = null;
try {
@@ -112,12 +117,12 @@ public class DataSourceTest3 extends TestCase {
Assert.assertNotNull(error);
}
}
public void test_error_4() throws Exception {
PoolableConnection conn = dataSource.getConnection().unwrap(PoolableConnection.class);
conn.close();
{
Exception error = null;
try {
@@ -128,12 +133,12 @@ public class DataSourceTest3 extends TestCase {
Assert.assertNotNull(error);
}
}
public void test_error_5() throws Exception {
PoolableConnection conn = dataSource.getConnection().unwrap(PoolableConnection.class);
conn.close();
{
Exception error = null;
try {
@@ -144,12 +149,12 @@ public class DataSourceTest3 extends TestCase {
Assert.assertNotNull(error);
}
}
public void test_error_6() throws Exception {
PoolableConnection conn = dataSource.getConnection().unwrap(PoolableConnection.class);
conn.close();
{
Exception error = null;
try {
@@ -160,12 +165,12 @@ public class DataSourceTest3 extends TestCase {
Assert.assertNotNull(error);
}
}
public void test_error_7() throws Exception {
PoolableConnection conn = dataSource.getConnection().unwrap(PoolableConnection.class);
conn.close();
{
Exception error = null;
try {
@@ -176,12 +181,12 @@ public class DataSourceTest3 extends TestCase {
Assert.assertNotNull(error);
}
}
public void test_error_8() throws Exception {
PoolableConnection conn = dataSource.getConnection().unwrap(PoolableConnection.class);
conn.close();
{
Exception error = null;
try {
@@ -192,57 +197,55 @@ public class DataSourceTest3 extends TestCase {
Assert.assertNotNull(error);
}
}
public void test_error_9() throws Exception {
PoolableConnection conn = dataSource.getConnection().unwrap(PoolableConnection.class);
conn.close();
{
Exception error = null;
try {
dataSource.setConnectionProperties("x=12");
dataSource.setConnectionProperties("x=12;;");
} catch (Exception ex) {
error = ex;
}
Assert.assertNotNull(error);
}
}
public void test_getValidConnectionCheckerClassName() throws Exception {
PoolableConnection conn = dataSource.getConnection().unwrap(PoolableConnection.class);
conn.close();
dataSource.getValidConnectionCheckerClassName();
}
public void test_setConnectionInitSqls() throws Exception {
PoolableConnection conn = dataSource.getConnection().unwrap(PoolableConnection.class);
conn.close();
dataSource.setConnectionInitSqls(null);
}
public void test_setConnectionProperties() throws Exception {
dataSource.setConnectionProperties(null);
dataSource.setLogWriter(null);
dataSource.getLogWriter();
PoolableConnection conn = dataSource.getConnection().unwrap(PoolableConnection.class);
conn.close();
}
public void test_error_10() throws Exception {
PoolableConnection conn = dataSource.getConnection().unwrap(PoolableConnection.class);
conn.close();
{
Exception error = null;
try {
@@ -253,14 +256,14 @@ public class DataSourceTest3 extends TestCase {
Assert.assertNotNull(error);
}
}
public void test_error_11() throws Exception {
PoolableConnection conn = dataSource.getConnection().unwrap(PoolableConnection.class);
conn.close();
dataSource.getUrl();
{
Exception error = null;
try {
@@ -271,4 +274,64 @@ public class DataSourceTest3 extends TestCase {
Assert.assertNotNull(error);
}
}
public void test_setConnectionInitSqls_2() throws Exception {
dataSource.setConnectionInitSqls(Collections.emptyList());
dataSource.setConnectionInitSqls(Collections.singleton(null));
}
public void test_ValidConnectionChecker() throws Exception {
dataSource.getValidConnectionCheckerClassName();
dataSource.setValidConnectionChecker(new MySqlValidConnectionChecker());
Assert.assertEquals(MySqlValidConnectionChecker.class.getName(),
dataSource.getValidConnectionCheckerClassName());
}
public void test_setConnectionInitSqls_1() throws Exception {
dataSource.setConnectionInitSqls(Collections.emptyList());
dataSource.setConnectionInitSqls(Collections.singleton(null));
}
public static class MyPasswordCallbackClassName extends PasswordCallback {
public MyPasswordCallbackClassName(){
super("password", false);
}
/**
*
*/
private static final long serialVersionUID = 1L;
}
public void test_setPasswordCallbackClassName() throws Exception {
dataSource.setPasswordCallbackClassName(MyPasswordCallbackClassName.class.getName());
}
public void test_error_12() throws Exception {
PoolableConnection conn = dataSource.getConnection().unwrap(PoolableConnection.class);
conn.close();
{
Exception error = null;
try {
dataSource.setDriverClassName("");
} catch (Exception ex) {
error = ex;
}
Assert.assertNotNull(error);
}
}
public void test_setExceptionSorter() throws Exception {
dataSource.setExceptionSorter(NullExceptionSorter.class.getName());
}
public void test_setProxyFilters() throws Exception {
dataSource.setProxyFilters(null);
dataSource.setFilters(null);
dataSource.setFilters("");
}
}
@@ -27,7 +27,7 @@ public class MySqlValdConnectionTest extends TestCase {
dataSource.setUsername(user);
dataSource.setPassword(password);
dataSource.setFilters("stat");
dataSource.setExceptionSoter(MySqlExceptionSorter.class.getName());
dataSource.setExceptionSorter(MySqlExceptionSorter.class.getName());
Connection conn = dataSource.getConnection();
conn.close();
@@ -33,7 +33,7 @@ public class TestOracle_DruidDataSource extends TestCase {
dataSource.setUsername(user);
dataSource.setPassword(password);
dataSource.setFilters("stat");
dataSource.setExceptionSoter(OracleExceptionSorter.class.getName());
dataSource.setExceptionSorter(OracleExceptionSorter.class.getName());
final int COUNT = 100 * 100;
final int THREAD_COUNT = 10;