add more error info.

This commit is contained in:
wenshao
2018-09-21 16:24:21 +08:00
parent 4d0980dc14
commit 6ce53e3203
4 changed files with 90 additions and 0 deletions
@@ -0,0 +1,46 @@
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 junit.framework.TestCase;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.Properties;
public class MaxWaitTest extends TestCase {
protected DruidDataSource dataSource;
protected void setUp() throws Exception {
dataSource = new DruidDataSource();
dataSource.setUrl("jdbc:mock:driver");
dataSource.setMaxWait(100);
dataSource.setDriver(new MockDriver() {
@Override
public Connection connect(String url, Properties info) throws SQLException {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// skip
}
return super.connect(url, info);
}
});
}
protected void tearDown() throws Exception {
dataSource.close();
}
public void test_wait() throws Exception {
Exception error = null;
try {
DruidPooledConnection conn = dataSource.getConnection();
conn.close();
} catch (SQLException ex) {
error = ex;
}
assertTrue(error.getMessage().contains("createElapseMillis "));
}
}
@@ -0,0 +1,31 @@
package com.alibaba.druid.bvt.pool;
import com.alibaba.druid.pool.DruidDataSource;
import com.alibaba.druid.pool.DruidPooledConnection;
import junit.framework.TestCase;
import java.sql.SQLException;
public class UrlNotSetTest extends TestCase {
protected DruidDataSource dataSource;
protected void setUp() throws Exception {
dataSource = new DruidDataSource();
dataSource.setMaxWait(10);
}
protected void tearDown() throws Exception {
dataSource.close();
}
public void test_wait() throws Exception {
Exception error = null;
try {
DruidPooledConnection conn = dataSource.getConnection();
conn.close();
} catch (SQLException ex) {
error = ex;
}
assertEquals("url not set", error.getMessage());
}
}