mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
@@ -23,6 +23,7 @@ import java.sql.Blob;
|
||||
import java.sql.CallableStatement;
|
||||
import java.sql.Clob;
|
||||
import java.sql.NClob;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.Ref;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.RowId;
|
||||
@@ -1076,7 +1077,7 @@ public class DruidPooledCallableStatement extends DruidPooledPreparedStatement i
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> T unwrap(Class<T> iface) throws SQLException {
|
||||
if (iface == CallableStatement.class) {
|
||||
if (iface == CallableStatement.class || iface == PreparedStatement.class) {
|
||||
if (stmt instanceof CallableStatementProxy) {
|
||||
return stmt.unwrap(iface);
|
||||
}
|
||||
|
||||
@@ -612,7 +612,7 @@ public class CallableStatementProxyImpl extends PreparedStatementProxyImpl imple
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> T unwrap(Class<T> iface) throws SQLException {
|
||||
if (iface == PreparedStatement.class) {
|
||||
if (iface == PreparedStatement.class || iface == CallableStatement.class) {
|
||||
return (T) statement;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.alibaba.druid.bvt.pool;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import com.alibaba.druid.pool.DataSourceDisableException;
|
||||
|
||||
public class DataSourceDisableExceptionTest extends TestCase {
|
||||
public void test_0() throws Exception {
|
||||
DataSourceDisableException ex = new DataSourceDisableException();
|
||||
Assert.assertEquals(null, ex.getMessage());
|
||||
}
|
||||
|
||||
public void test_1() throws Exception {
|
||||
DataSourceDisableException ex = new DataSourceDisableException("XXX");
|
||||
Assert.assertEquals("XXX", ex.getMessage());
|
||||
}
|
||||
|
||||
public void test_2() throws Exception {
|
||||
DataSourceDisableException ex = new DataSourceDisableException(new IllegalStateException());
|
||||
Assert.assertTrue(ex.getCause() instanceof IllegalStateException);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package com.alibaba.druid.bvt.pool;
|
||||
|
||||
import java.sql.Connection;
|
||||
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;
|
||||
|
||||
public class DruidConnectionHolderTest extends TestCase {
|
||||
|
||||
private DruidDataSource dataSource;
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
dataSource = new DruidDataSource();
|
||||
dataSource.setUrl("jdbc:mock:xxx");
|
||||
dataSource.setTestOnBorrow(false);
|
||||
dataSource.setPoolPreparedStatements(true);
|
||||
dataSource.getProxyFilters().add(new FilterAdapter() {
|
||||
|
||||
public int connection_getTransactionIsolation(FilterChain chain, ConnectionProxy connection)
|
||||
throws SQLException {
|
||||
throw new com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException();
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
protected void tearDown() throws Exception {
|
||||
dataSource.close();
|
||||
}
|
||||
|
||||
public void test_mysqlSyntaxError() throws Exception {
|
||||
Connection conn = dataSource.getConnection();
|
||||
conn.close();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,149 @@
|
||||
package com.alibaba.druid.bvt.pool;
|
||||
|
||||
import java.sql.CallableStatement;
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.SQLFeatureNotSupportedException;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.filter.FilterAdapter;
|
||||
import com.alibaba.druid.filter.FilterChain;
|
||||
import com.alibaba.druid.mock.MockCallableStatement;
|
||||
import com.alibaba.druid.pool.DruidDataSource;
|
||||
import com.alibaba.druid.pool.DruidPooledCallableStatement;
|
||||
import com.alibaba.druid.proxy.jdbc.CallableStatementProxy;
|
||||
|
||||
public class DruidPooledCallableStatementTest extends TestCase {
|
||||
|
||||
private DruidDataSource dataSource;
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
dataSource = new DruidDataSource();
|
||||
|
||||
dataSource.setUrl("jdbc:mock:xxx");
|
||||
dataSource.setTestOnBorrow(false);
|
||||
dataSource.setInitialSize(1);
|
||||
|
||||
dataSource.getProxyFilters().add(new FilterAdapter() {
|
||||
|
||||
public boolean callableStatement_wasNull(FilterChain chain, CallableStatementProxy statement)
|
||||
throws SQLException {
|
||||
throw new SQLException();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
protected void tearDown() throws Exception {
|
||||
dataSource.close();
|
||||
}
|
||||
|
||||
public void test_wasNull() throws Exception {
|
||||
Connection conn = dataSource.getConnection();
|
||||
CallableStatement stmt = conn.prepareCall("select 1");
|
||||
stmt.execute();
|
||||
|
||||
Assert.assertEquals(0, dataSource.getErrorCount());
|
||||
|
||||
Exception error = null;
|
||||
try {
|
||||
stmt.wasNull();
|
||||
} catch (Exception e) {
|
||||
error = e;
|
||||
}
|
||||
Assert.assertNotNull(error);
|
||||
|
||||
Assert.assertEquals(1, dataSource.getErrorCount());
|
||||
|
||||
stmt.close();
|
||||
conn.close();
|
||||
|
||||
Assert.assertEquals(1, dataSource.getPoolingCount());
|
||||
}
|
||||
|
||||
public void test_getObject() throws Exception {
|
||||
Connection conn = dataSource.getConnection();
|
||||
DruidPooledCallableStatement stmt = (DruidPooledCallableStatement) conn.prepareCall("select 1");
|
||||
stmt.execute();
|
||||
|
||||
Assert.assertEquals(0, dataSource.getErrorCount());
|
||||
|
||||
Exception error = null;
|
||||
try {
|
||||
stmt.getObject(1, String.class);
|
||||
} catch (SQLFeatureNotSupportedException e) {
|
||||
error = e;
|
||||
}
|
||||
Assert.assertNotNull(error);
|
||||
|
||||
Assert.assertEquals(0, dataSource.getErrorCount());
|
||||
|
||||
stmt.close();
|
||||
conn.close();
|
||||
|
||||
Assert.assertEquals(1, dataSource.getPoolingCount());
|
||||
}
|
||||
|
||||
public void test_getObject_1() throws Exception {
|
||||
Connection conn = dataSource.getConnection();
|
||||
DruidPooledCallableStatement stmt = (DruidPooledCallableStatement) conn.prepareCall("select 1");
|
||||
stmt.execute();
|
||||
|
||||
Assert.assertEquals(0, dataSource.getErrorCount());
|
||||
|
||||
Exception error = null;
|
||||
try {
|
||||
stmt.getObject("1", String.class);
|
||||
} catch (SQLFeatureNotSupportedException e) {
|
||||
error = e;
|
||||
}
|
||||
Assert.assertNotNull(error);
|
||||
|
||||
Assert.assertEquals(0, dataSource.getErrorCount());
|
||||
|
||||
stmt.close();
|
||||
conn.close();
|
||||
|
||||
Assert.assertEquals(1, dataSource.getPoolingCount());
|
||||
}
|
||||
|
||||
public void test_wrap() throws Exception {
|
||||
|
||||
Connection conn = dataSource.getConnection();
|
||||
CallableStatement stmt = conn.prepareCall("select 1");
|
||||
|
||||
Assert.assertNotNull(stmt.unwrap(CallableStatement.class));
|
||||
Assert.assertEquals(MockCallableStatement.class, stmt.unwrap(CallableStatement.class).getClass());
|
||||
|
||||
stmt.close();
|
||||
conn.close();
|
||||
}
|
||||
|
||||
public void test_wrap_1() throws Exception {
|
||||
|
||||
Connection conn = dataSource.getConnection();
|
||||
CallableStatement stmt = conn.prepareCall("select 1");
|
||||
|
||||
Assert.assertNotNull(stmt.unwrap(PreparedStatement.class));
|
||||
Assert.assertEquals(MockCallableStatement.class, stmt.unwrap(CallableStatement.class).getClass());
|
||||
|
||||
stmt.close();
|
||||
conn.close();
|
||||
}
|
||||
|
||||
public void test_wrap_2() throws Exception {
|
||||
dataSource.getProxyFilters().clear();
|
||||
|
||||
Connection conn = dataSource.getConnection();
|
||||
CallableStatement stmt = conn.prepareCall("select 1");
|
||||
|
||||
Assert.assertNotNull(stmt.unwrap(PreparedStatement.class));
|
||||
Assert.assertEquals(MockCallableStatement.class, stmt.unwrap(CallableStatement.class).getClass());
|
||||
|
||||
stmt.close();
|
||||
conn.close();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.alibaba.druid.bvt.support.json;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import com.alibaba.druid.support.json.JSONUtils;
|
||||
import com.alibaba.druid.util.IOUtils;
|
||||
|
||||
public class JSONParserTest2 extends TestCase {
|
||||
public void test_parse() throws Exception {
|
||||
String text = IOUtils.readFromResource("bvt/sql.json");
|
||||
Map<String, Object> result = (Map<String, Object>)JSONUtils.parse(text);
|
||||
List<Map<String, Object>> sqlList = (List<Map<String, Object>>) result.get("Content");
|
||||
Assert.assertEquals(82, sqlList.size());
|
||||
}
|
||||
}
|
||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user