mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
DruidDataSource support initExceptionThrow config.
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
package com.alibaba.druid.bvt.pool;
|
||||
|
||||
import com.alibaba.druid.mock.MockDriver;
|
||||
import com.alibaba.druid.pool.DruidDataSource;
|
||||
import com.alibaba.druid.pool.DruidPooledConnection;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Properties;
|
||||
|
||||
public class InitExceptionThrowTest extends TestClone {
|
||||
private DruidDataSource dataSource = new DruidDataSource();
|
||||
|
||||
private int connectCount = 0;
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
dataSource.setInitExceptionThrow(true);
|
||||
dataSource.setUrl("jdbc:mock:xxx");
|
||||
dataSource.setDriver(new MockDriver() {
|
||||
public Connection connect(String url, Properties info) throws SQLException {
|
||||
if (connectCount++ < 1) {
|
||||
throw new SQLException("");
|
||||
}
|
||||
return super.connect(url, info);
|
||||
}
|
||||
});
|
||||
dataSource.setInitialSize(2);
|
||||
}
|
||||
|
||||
protected void tearDown() throws Exception {
|
||||
dataSource.close();
|
||||
}
|
||||
|
||||
public void test_pool() throws Exception {
|
||||
DruidPooledConnection conn = dataSource.getConnection();
|
||||
conn.close();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user