mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
61 lines
1.7 KiB
Java
61 lines
1.7 KiB
Java
package com.alibaba.druid.bvt.pool;
|
|
|
|
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 {
|
|
driver = new Driver();
|
|
|
|
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 {
|
|
if (dataSource != null) {
|
|
dataSource.close();
|
|
}
|
|
}
|
|
|
|
public void test_mysqlSyntaxError() throws Exception {
|
|
if (driver.getMajorVersion() == 5) {
|
|
dataSource.init();
|
|
|
|
dataSource.getConnection();
|
|
}
|
|
}
|
|
}
|