mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
Merge pull request #106 from wenshao/master
添加测试,修正executeQuery返回null时无法处理的bug。
This commit is contained in:
@@ -200,7 +200,7 @@ public class FilterChainImplTest extends TestCase {
|
||||
ResultSet rs = stmt.executeQuery();
|
||||
rs.next();
|
||||
|
||||
Assert.assertNull(rs.getURL(1));
|
||||
Assert.assertNull(rs.getRowId(1));
|
||||
|
||||
rs.close();
|
||||
stmt.close();
|
||||
@@ -215,7 +215,7 @@ public class FilterChainImplTest extends TestCase {
|
||||
ResultSet rs = stmt.executeQuery();
|
||||
rs.next();
|
||||
|
||||
Assert.assertNull(rs.getURL("1"));
|
||||
Assert.assertNull(rs.getRowId("1"));
|
||||
|
||||
rs.close();
|
||||
stmt.close();
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.alibaba.druid.bvt.filter;
|
||||
import java.sql.CallableStatement;
|
||||
import java.sql.Connection;
|
||||
import java.sql.Types;
|
||||
import java.util.Collections;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import junit.framework.TestCase;
|
||||
@@ -601,4 +602,48 @@ public class FilterChainImplTest2 extends TestCase {
|
||||
stmt.close();
|
||||
conn.close();
|
||||
}
|
||||
|
||||
public void test_getObject() throws Exception {
|
||||
Connection conn = dataSource.getConnection();
|
||||
CallableStatement stmt = conn.prepareCall("select ?");
|
||||
stmt.registerOutParameter(1, Types.VARCHAR);
|
||||
|
||||
Assert.assertNull(stmt.getObject(1));
|
||||
|
||||
stmt.close();
|
||||
conn.close();
|
||||
}
|
||||
|
||||
public void test_getObject_1() throws Exception {
|
||||
Connection conn = dataSource.getConnection();
|
||||
CallableStatement stmt = conn.prepareCall("select ?");
|
||||
stmt.registerOutParameter(1, Types.VARCHAR);
|
||||
|
||||
Assert.assertNull(stmt.getObject("1"));
|
||||
|
||||
stmt.close();
|
||||
conn.close();
|
||||
}
|
||||
|
||||
public void test_getObject_2() throws Exception {
|
||||
Connection conn = dataSource.getConnection();
|
||||
CallableStatement stmt = conn.prepareCall("select ?");
|
||||
stmt.registerOutParameter(1, Types.VARCHAR);
|
||||
|
||||
Assert.assertNull(stmt.getObject(1, Collections.<String, Class<?>>emptyMap()));
|
||||
|
||||
stmt.close();
|
||||
conn.close();
|
||||
}
|
||||
|
||||
public void test_getObject_3() throws Exception {
|
||||
Connection conn = dataSource.getConnection();
|
||||
CallableStatement stmt = conn.prepareCall("select ?");
|
||||
stmt.registerOutParameter(1, Types.VARCHAR);
|
||||
|
||||
Assert.assertNull(stmt.getObject("1", Collections.<String, Class<?>>emptyMap()));
|
||||
|
||||
stmt.close();
|
||||
conn.close();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,86 @@
|
||||
package com.alibaba.druid.bvt.filter;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.sql.Types;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import com.alibaba.druid.mock.MockCallableStatement;
|
||||
import com.alibaba.druid.mock.MockConnection;
|
||||
import com.alibaba.druid.mock.MockDriver;
|
||||
import com.alibaba.druid.mock.MockStatement;
|
||||
import com.alibaba.druid.mock.MockStatementBase;
|
||||
import com.alibaba.druid.pool.DruidDataSource;
|
||||
import com.alibaba.druid.util.JdbcUtils;
|
||||
|
||||
public class FilterChainImplTest3 extends TestCase {
|
||||
|
||||
private DruidDataSource dataSource;
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
dataSource = new DruidDataSource();
|
||||
|
||||
dataSource.setUrl("jdbc:mock:xxx");
|
||||
dataSource.setFilters("stat");
|
||||
|
||||
dataSource.setDriver(new MockDriver() {
|
||||
public ResultSet executeQuery(MockStatementBase stmt, String sql) throws SQLException {
|
||||
return null;
|
||||
}
|
||||
|
||||
public MockStatement createMockStatement(MockConnection conn) {
|
||||
return new MockStatement(conn) {
|
||||
public ResultSet getResultSet() throws SQLException {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
dataSource.init();
|
||||
}
|
||||
|
||||
protected void tearDown() throws Exception {
|
||||
JdbcUtils.close(dataSource);
|
||||
}
|
||||
|
||||
public void test_executeQuery() throws Exception {
|
||||
Connection conn = dataSource.getConnection();
|
||||
PreparedStatement stmt = conn.prepareStatement("select ?");
|
||||
stmt.setNull(1, Types.VARCHAR);
|
||||
Assert.assertNull(stmt.executeQuery());
|
||||
stmt.close();
|
||||
conn.close();
|
||||
}
|
||||
|
||||
public void test_executeQuery_2() throws Exception {
|
||||
Connection conn = dataSource.getConnection();
|
||||
PreparedStatement stmt = conn.prepareCall("select ?");
|
||||
stmt.setNull(1, Types.VARCHAR);
|
||||
Assert.assertNull(stmt.executeQuery());
|
||||
stmt.close();
|
||||
conn.close();
|
||||
}
|
||||
|
||||
public void test_executeQuery_3() throws Exception {
|
||||
Connection conn = dataSource.getConnection();
|
||||
Statement stmt = conn.createStatement();
|
||||
Assert.assertNull(stmt.executeQuery("select 1"));
|
||||
stmt.close();
|
||||
conn.close();
|
||||
}
|
||||
|
||||
public void test_execute() throws Exception {
|
||||
Connection conn = dataSource.getConnection();
|
||||
Statement stmt = conn.createStatement();
|
||||
stmt.execute("select 1");
|
||||
Assert.assertNull(stmt.getResultSet());
|
||||
stmt.close();
|
||||
conn.close();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package com.alibaba.druid.bvt.pool;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import com.alibaba.druid.pool.DruidDataSource;
|
||||
|
||||
public class TransactionTest extends TestCase {
|
||||
private DruidDataSource dataSource;
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
dataSource = new DruidDataSource();
|
||||
dataSource.setUrl("jdbc:mock:xxx");
|
||||
dataSource.setTestOnBorrow(false);
|
||||
}
|
||||
|
||||
protected void tearDown() throws Exception {
|
||||
dataSource.close();
|
||||
}
|
||||
|
||||
public void test_txn() throws Exception {
|
||||
Connection conn = dataSource.getConnection();
|
||||
|
||||
conn.setAutoCommit(false);
|
||||
for (int i = 0; i < 100; ++i) {
|
||||
PreparedStatement stmt = conn.prepareStatement("select + " + (i % 10));
|
||||
stmt.executeUpdate();
|
||||
stmt.close();
|
||||
}
|
||||
conn.commit();
|
||||
conn.close();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user