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:
@@ -2027,6 +2027,20 @@ public abstract class DruidAbstractDataSource extends WrapperAdapter implements
|
||||
return onFatalError;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ since 1.1.11
|
||||
*/
|
||||
public boolean isInitExceptionThrow() {
|
||||
return initExceptionThrow;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ since 1.1.11
|
||||
*/
|
||||
public void setInitExceptionThrow(boolean initExceptionThrow) {
|
||||
this.initExceptionThrow = initExceptionThrow;
|
||||
}
|
||||
|
||||
public static class PhysicalConnectionInfo {
|
||||
private Connection connection;
|
||||
private long connectStartNanos;
|
||||
|
||||
@@ -887,7 +887,7 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
|
||||
initedTime = new Date();
|
||||
registerMbean();
|
||||
|
||||
if (connectError != null && poolingCount == 0) {
|
||||
if (connectError != null && poolingCount == 0 && !(initExceptionThrow && !asyncInit)) {
|
||||
throw connectError;
|
||||
}
|
||||
|
||||
|
||||
@@ -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