mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
@@ -1,5 +1,6 @@
|
||||
package com.alibaba.druid.bvt.pool;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
@@ -74,6 +75,11 @@ public class DruidDataSourceTest_recycle2 extends TestCase {
|
||||
error = e;
|
||||
}
|
||||
Assert.assertNull(error);
|
||||
|
||||
{
|
||||
Connection conn2 = dataSource.getConnection();
|
||||
conn2.close();
|
||||
}
|
||||
|
||||
Assert.assertEquals(1, dataSource.getPoolingCount());
|
||||
Assert.assertEquals(0, dataSource.getActiveCount());
|
||||
|
||||
@@ -17,9 +17,10 @@ package com.alibaba.druid.bvt.pool;
|
||||
|
||||
import java.sql.Connection;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.mock.MockConnection;
|
||||
import com.alibaba.druid.mock.MockDriver;
|
||||
import com.alibaba.druid.pool.DruidDataSource;
|
||||
@@ -43,7 +44,7 @@ public class TestIdle extends TestCase {
|
||||
dataSource.setDriver(driver);
|
||||
dataSource.setInitialSize(2);
|
||||
dataSource.setMaxActive(4);
|
||||
dataSource.setMaxIdle(4);
|
||||
// dataSource.setMaxIdle(4);
|
||||
dataSource.setMinIdle(1);
|
||||
dataSource.setMinEvictableIdleTimeMillis(50 * 1);
|
||||
dataSource.setTimeBetweenEvictionRunsMillis(10);
|
||||
@@ -118,11 +119,11 @@ public class TestIdle extends TestCase {
|
||||
Assert.assertEquals(count - i - 1, dataSource.getActiveCount());
|
||||
}
|
||||
Assert.assertEquals(4, driver.getConnections().size());
|
||||
Assert.assertEquals(0, dataSource.getActiveCount());
|
||||
Assert.assertEquals("activeCount not zero", 0, dataSource.getActiveCount());
|
||||
|
||||
dataSource.shrink();
|
||||
Assert.assertEquals(0, dataSource.getActiveCount());
|
||||
Assert.assertEquals(dataSource.getMinIdle(), driver.getConnections().size());
|
||||
Assert.assertEquals("activeCount not zero", 0, dataSource.getActiveCount());
|
||||
Assert.assertEquals("minIdle not equal physical", dataSource.getMinIdle(), driver.getConnections().size());
|
||||
}
|
||||
|
||||
dataSource.close();
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
package com.alibaba.druid.bvt.proxy.filter;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.Statement;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.pool.DruidDataSource;
|
||||
import com.alibaba.druid.stat.JdbcDataSourceStat;
|
||||
import com.alibaba.druid.stat.JdbcStatManager;
|
||||
import com.alibaba.druid.util.JdbcUtils;
|
||||
|
||||
public class GlobalStatTest1 extends TestCase {
|
||||
|
||||
private DruidDataSource dataSourceA;
|
||||
private DruidDataSource dataSourceB;
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
Assert.assertEquals(0, JdbcStatManager.getInstance().getSqlList().size());
|
||||
|
||||
dataSourceA = new DruidDataSource();
|
||||
dataSourceA.setUrl("jdbc:mock:xx_A");
|
||||
dataSourceA.setFilters("stat");
|
||||
dataSourceA.setUseGloalDataSourceStat(true);
|
||||
|
||||
dataSourceB = new DruidDataSource();
|
||||
dataSourceB.setUrl("jdbc:mock:xx_A");
|
||||
dataSourceB.setFilters("stat");
|
||||
dataSourceB.setUseGloalDataSourceStat(true);
|
||||
}
|
||||
|
||||
protected void tearDown() throws Exception {
|
||||
JdbcUtils.close(dataSourceA);
|
||||
JdbcUtils.close(dataSourceB);
|
||||
|
||||
JdbcDataSourceStat.setGlobal(null);
|
||||
|
||||
Assert.assertEquals(0, JdbcStatManager.getInstance().getSqlList().size());
|
||||
}
|
||||
|
||||
public void test_execute() throws Exception {
|
||||
{
|
||||
Connection conn = dataSourceA.getConnection();
|
||||
Statement stmt = conn.createStatement();
|
||||
ResultSet rs = stmt.executeQuery("SELECT 1");
|
||||
while (rs.next()) {
|
||||
|
||||
}
|
||||
rs.close();
|
||||
stmt.close();
|
||||
conn.close();
|
||||
}
|
||||
{
|
||||
Connection conn = dataSourceB.getConnection();
|
||||
PreparedStatement stmt = conn.prepareStatement("SELECT 1");
|
||||
ResultSet rs = stmt.executeQuery();
|
||||
while (rs.next()) {
|
||||
|
||||
}
|
||||
rs.close();
|
||||
stmt.close();
|
||||
conn.close();
|
||||
}
|
||||
|
||||
Assert.assertSame(JdbcDataSourceStat.getGlobal(), dataSourceA.getDataSourceStat());
|
||||
Assert.assertSame(JdbcDataSourceStat.getGlobal(), dataSourceB.getDataSourceStat());
|
||||
|
||||
Assert.assertEquals(1, JdbcStatManager.getInstance().getSqlList().size());
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user