mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
补充Oracle测试
git-svn-id: http://code.alibabatech.com/svn/druid/trunk@889 b9813039-fb51-4c41-a8b9-e21c2acb5095
This commit is contained in:
@@ -423,5 +423,23 @@ public class MultiDataSourceStatement extends WrapperAdapter implements Statemen
|
||||
public boolean isPoolable() throws SQLException {
|
||||
return false;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public <T> T unwrap(Class<T> iface) throws SQLException {
|
||||
if (iface == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (iface.isInstance(this)) {
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
if (stmt != null) {
|
||||
return stmt.unwrap(iface);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -4,42 +4,82 @@ import java.sql.Connection;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.Statement;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import com.alibaba.druid.mock.MockStatement;
|
||||
import com.alibaba.druid.pool.DruidDataSource;
|
||||
import com.alibaba.druid.pool.ha.HADataSource;
|
||||
|
||||
|
||||
public class HADataSourceTest extends TestCase {
|
||||
|
||||
private DruidDataSource dataSourceA;
|
||||
private DruidDataSource dataSourceB;
|
||||
|
||||
private HADataSource dataSourceHA;
|
||||
|
||||
|
||||
private HADataSource dataSourceHA;
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
dataSourceA = new DruidDataSource();
|
||||
dataSourceA.setUrl("jdbc:mock:x1");
|
||||
|
||||
|
||||
dataSourceB = new DruidDataSource();
|
||||
dataSourceB.setUrl("jdbc:mock:x1");
|
||||
|
||||
|
||||
dataSourceHA = new HADataSource();
|
||||
dataSourceHA.addDataSource(dataSourceA);
|
||||
dataSourceHA.addDataSource(dataSourceB);
|
||||
}
|
||||
|
||||
|
||||
protected void tearDown() throws Exception {
|
||||
dataSourceHA.close();
|
||||
}
|
||||
|
||||
public void test_connect_close() throws Exception {
|
||||
|
||||
public void test_0() throws Exception {
|
||||
Connection conn = dataSourceHA.getConnection();
|
||||
|
||||
|
||||
Statement stmt = conn.createStatement();
|
||||
ResultSet rs = stmt.executeQuery("SELECT 1");
|
||||
rs.close();
|
||||
stmt.close();
|
||||
|
||||
conn.close();
|
||||
}
|
||||
|
||||
public void test_1() throws Exception {
|
||||
Connection conn = dataSourceHA.getConnection();
|
||||
|
||||
Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
|
||||
ResultSet rs = stmt.executeQuery("SELECT 1");
|
||||
rs.close();
|
||||
|
||||
MockStatement mockStmt = stmt.unwrap(MockStatement.class);
|
||||
Assert.assertEquals(ResultSet.TYPE_SCROLL_INSENSITIVE, mockStmt.getResultSetType());
|
||||
Assert.assertEquals(ResultSet.CONCUR_UPDATABLE, mockStmt.getResultSetConcurrency());
|
||||
Assert.assertEquals(ResultSet.TYPE_SCROLL_INSENSITIVE, stmt.getResultSetType());
|
||||
Assert.assertEquals(ResultSet.CONCUR_UPDATABLE, stmt.getResultSetConcurrency());
|
||||
stmt.close();
|
||||
|
||||
conn.close();
|
||||
}
|
||||
|
||||
public void test_2() throws Exception {
|
||||
Connection conn = dataSourceHA.getConnection();
|
||||
|
||||
Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE,
|
||||
ResultSet.CLOSE_CURSORS_AT_COMMIT);
|
||||
ResultSet rs = stmt.executeQuery("SELECT 1");
|
||||
rs.close();
|
||||
|
||||
MockStatement mockStmt = stmt.unwrap(MockStatement.class);
|
||||
Assert.assertEquals(ResultSet.TYPE_SCROLL_INSENSITIVE, mockStmt.getResultSetType());
|
||||
Assert.assertEquals(ResultSet.CONCUR_UPDATABLE, mockStmt.getResultSetConcurrency());
|
||||
Assert.assertEquals(ResultSet.CLOSE_CURSORS_AT_COMMIT, mockStmt.getResultSetHoldability());
|
||||
Assert.assertEquals(ResultSet.TYPE_SCROLL_INSENSITIVE, stmt.getResultSetType());
|
||||
Assert.assertEquals(ResultSet.CONCUR_UPDATABLE, stmt.getResultSetConcurrency());
|
||||
Assert.assertEquals(ResultSet.CLOSE_CURSORS_AT_COMMIT, stmt.getResultSetHoldability());
|
||||
|
||||
stmt.close();
|
||||
|
||||
conn.close();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user