mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
Druid连接池初始化时支持对驱动类遍历处理,避免ExceptionSorter空的问题
This commit is contained in:
+101
@@ -0,0 +1,101 @@
|
||||
package com.alibaba.druid.bvt.pool;
|
||||
|
||||
import com.alibaba.druid.mock.MockDriver;
|
||||
import com.alibaba.druid.mock.MockStatementBase;
|
||||
import com.alibaba.druid.pool.DruidDataSource;
|
||||
import com.alibaba.druid.pool.ExceptionSorter;
|
||||
import com.alibaba.druid.pool.vendor.MySqlExceptionSorter;
|
||||
import com.mysql.jdbc.Driver;
|
||||
import junit.framework.TestCase;
|
||||
import org.junit.Assert;
|
||||
|
||||
import java.sql.*;
|
||||
import java.util.Properties;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
* 这个场景测试exceptionSorter_extend
|
||||
*
|
||||
* @author xiaoying [caohongxi001@gmail.com]
|
||||
*/
|
||||
public class DruidDataSourceTest_exceptionSorter_extend extends TestCase {
|
||||
|
||||
public static class SubDriver extends com.mysql.jdbc.Driver{
|
||||
|
||||
/**
|
||||
* Construct a new driver and register it with DriverManager
|
||||
*
|
||||
* @throws SQLException if a database error occurs.
|
||||
*/
|
||||
public SubDriver() throws SQLException {
|
||||
}
|
||||
}
|
||||
public static class SubDriver1 implements java.sql.Driver{
|
||||
|
||||
/**
|
||||
* Construct a new driver and register it with DriverManager
|
||||
*
|
||||
* @throws SQLException if a database error occurs.
|
||||
*/
|
||||
public SubDriver1() throws SQLException {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Connection connect(String url, Properties info) throws SQLException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean acceptsURL(String url) throws SQLException {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DriverPropertyInfo[] getPropertyInfo(String url, Properties info) throws SQLException {
|
||||
return new DriverPropertyInfo[0];
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMajorVersion() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMinorVersion() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean jdbcCompliant() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Logger getParentLogger() throws SQLFeatureNotSupportedException {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试继承自com.mysql.jdbc.Driver的子类可以设置sorter
|
||||
* @throws Exception
|
||||
*/
|
||||
public void testExceptionSorter() throws Exception {
|
||||
DruidDataSource dataSource1 = new DruidDataSource();
|
||||
dataSource1.setDriverClassName(SubDriver.class.getName());
|
||||
dataSource1.init();
|
||||
Assert.assertNotNull(dataSource1.getExceptionSorter());
|
||||
Assert.assertEquals(MySqlExceptionSorter.class.getName(), dataSource1.getExceptionSorter().getClass().getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试实现自java.sql.Driver的类未设置sorter
|
||||
* @throws Exception
|
||||
*/
|
||||
public void testExceptionSorterNull() throws Exception {
|
||||
DruidDataSource dataSource1 = new DruidDataSource();
|
||||
dataSource1.setDriverClassName(SubDriver1.class.getName());
|
||||
dataSource1.init();
|
||||
Assert.assertEquals("sorter is not null",null,dataSource1.getExceptionSorter());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user