mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
HAPoolTest
git-svn-id: http://code.alibabatech.com/svn/druid/trunk@816 b9813039-fb51-4c41-a8b9-e21c2acb5095
This commit is contained in:
@@ -92,6 +92,11 @@ public class TestDataSourceBasic extends TestCase {
|
||||
|
||||
public void test_wrap() throws Exception {
|
||||
Assert.assertTrue(!dataSource.isWrapperFor(Date.class));
|
||||
Assert.assertTrue(!dataSource.isWrapperFor(null));
|
||||
Assert.assertTrue(dataSource.isWrapperFor(DataSource.class));
|
||||
|
||||
Assert.assertTrue(dataSource.unwrap(Date.class) == null);
|
||||
Assert.assertTrue(dataSource.unwrap(null) == null);
|
||||
Assert.assertTrue(dataSource.unwrap(DataSource.class) != null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
package com.alibaba.druid.bvt.pool.ha;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.Statement;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
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;
|
||||
|
||||
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 {
|
||||
Connection conn = dataSourceHA.getConnection();
|
||||
|
||||
Statement stmt = conn.createStatement();
|
||||
ResultSet rs = stmt.executeQuery("SELECT 1");
|
||||
rs.close();
|
||||
stmt.close();
|
||||
|
||||
conn.close();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user