mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
HA
This commit is contained in:
@@ -35,7 +35,7 @@ public class Bug_for_happyday517_2 extends TestCase {
|
||||
|
||||
public Connection connect(String url, Properties info) throws SQLException {
|
||||
super.connect(url, info);
|
||||
return new MockConnection(driver, info) {
|
||||
return new MockConnection(driver, url, info) {
|
||||
|
||||
public PreparedStatement prepareStatement(String sql) throws SQLException {
|
||||
return mockStatement;
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
package com.alibaba.druid.bvt.pool.ha;
|
||||
|
||||
import java.sql.Connection;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import com.alibaba.druid.mock.MockConnection;
|
||||
import com.alibaba.druid.pool.DruidDataSource;
|
||||
import com.alibaba.druid.pool.ha.HADataSource;
|
||||
import com.alibaba.druid.stat.DruidDataSourceStatManager;
|
||||
|
||||
public class HADataSourceTest2 extends TestCase {
|
||||
|
||||
private DruidDataSource dataSourceA;
|
||||
private DruidDataSource dataSourceB;
|
||||
|
||||
private HADataSource dataSourceHA;
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
Assert.assertEquals(0, DruidDataSourceStatManager.getInstance().getDataSourceList().size());
|
||||
|
||||
dataSourceA = new DruidDataSource();
|
||||
dataSourceA.setUrl("jdbc:mock:ha1");
|
||||
dataSourceA.setFilters("trace");
|
||||
|
||||
dataSourceB = new DruidDataSource();
|
||||
dataSourceB.setUrl("jdbc:mock:ha2");
|
||||
dataSourceB.setFilters("stat");
|
||||
|
||||
dataSourceHA = new HADataSource();
|
||||
dataSourceHA.setMaster(dataSourceA);
|
||||
dataSourceHA.setSlave(dataSourceB);
|
||||
}
|
||||
|
||||
protected void tearDown() throws Exception {
|
||||
dataSourceHA.close();
|
||||
|
||||
for (DruidDataSource dataSource : DruidDataSourceStatManager.getDruidDataSourceInstances()) {
|
||||
dataSource.close();
|
||||
}
|
||||
|
||||
Assert.assertEquals(0, DruidDataSourceStatManager.getInstance().getDataSourceList().size());
|
||||
}
|
||||
|
||||
public void test_switch() throws Exception {
|
||||
Connection conn = dataSourceHA.getConnection();
|
||||
|
||||
MockConnection mockConn = conn.unwrap(MockConnection.class);
|
||||
conn.close();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user