support mysql_driver_6.0.x

This commit is contained in:
wenshao
2016-08-05 22:30:31 +08:00
parent 165eefe9a9
commit 1f48919743
12 changed files with 181 additions and 255 deletions
@@ -1,40 +1,60 @@
package com.alibaba.druid.bvt.pool;
import java.sql.SQLException;
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;
import com.mysql.jdbc.Driver;
import junit.framework.TestCase;
import java.sql.SQLException;
public class DruidConnectionHolderTest extends TestCase {
Driver driver;
private DruidDataSource dataSource;
private Class exceptionClass;
protected void setUp() throws Exception {
dataSource = new DruidDataSource();
dataSource.setUrl("jdbc:mock:xxx");
dataSource.setTestOnBorrow(false);
dataSource.setInitialSize(1);
dataSource.getProxyFilters().add(new FilterAdapter() {
driver = new Driver();
public int connection_getTransactionIsolation(FilterChain chain, ConnectionProxy connection)
throws SQLException {
throw new com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException();
}
});
if (driver.getMajorVersion() == 5) {
exceptionClass = Class.forName("com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException");
dataSource = new DruidDataSource();
dataSource.setUrl("jdbc:mock:xxx");
dataSource.setTestOnBorrow(false);
dataSource.setInitialSize(1);
dataSource.getProxyFilters().add(new FilterAdapter() {
public int connection_getTransactionIsolation(FilterChain chain, ConnectionProxy connection)
throws SQLException {
throw createSyntaxException();
}
});
}
}
protected SQLException createSyntaxException() {
try {
return (SQLException) exceptionClass.newInstance();
} catch (Exception e) {
throw new IllegalStateException();
}
}
protected void tearDown() throws Exception {
dataSource.close();
if (dataSource != null) {
dataSource.close();
}
}
public void test_mysqlSyntaxError() throws Exception {
dataSource.init();
dataSource.getConnection();
if (driver.getMajorVersion() == 5) {
dataSource.init();
dataSource.getConnection();
}
}
}