mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
test
git-svn-id: http://code.alibabatech.com/svn/druid/trunk@720 b9813039-fb51-4c41-a8b9-e21c2acb5095
This commit is contained in:
@@ -10,10 +10,13 @@ import junit.framework.TestCase;
|
||||
|
||||
import com.alibaba.druid.mock.MockDriver;
|
||||
import com.alibaba.druid.pool.DruidDataSource;
|
||||
import com.alibaba.druid.stat.DruidDataSourceStatManager;
|
||||
|
||||
public class Case0 extends TestCase {
|
||||
|
||||
public void test_0() throws Exception {
|
||||
Assert.assertEquals(0, DruidDataSourceStatManager.getInstance().getDataSourceList().size());
|
||||
|
||||
final DruidDataSource dataSource = new DruidDataSource();
|
||||
|
||||
dataSource.setDriver(new MockDriver() {
|
||||
@@ -57,5 +60,6 @@ public class Case0 extends TestCase {
|
||||
Assert.assertTrue(completeLatch.await(1, TimeUnit.SECONDS));
|
||||
|
||||
dataSource.close();
|
||||
Assert.assertEquals(0, DruidDataSourceStatManager.getInstance().getDataSourceList().size());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ import junit.framework.TestCase;
|
||||
|
||||
import com.alibaba.druid.mock.MockStatement;
|
||||
import com.alibaba.druid.pool.DruidDataSource;
|
||||
import com.alibaba.druid.stat.DruidDataSourceStatManager;
|
||||
|
||||
public class Case3 extends TestCase {
|
||||
|
||||
@@ -39,6 +40,10 @@ public class Case3 extends TestCase {
|
||||
//
|
||||
// dataSource.close();
|
||||
// }
|
||||
|
||||
protected void tearDown() throws Exception {
|
||||
Assert.assertEquals(0, DruidDataSourceStatManager.getInstance().getDataSourceList().size());
|
||||
}
|
||||
|
||||
public void test_2() throws Exception {
|
||||
DruidDataSource dataSource = new DruidDataSource();
|
||||
|
||||
@@ -6,10 +6,14 @@ import junit.framework.Assert;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import com.alibaba.druid.pool.DruidDataSource;
|
||||
import com.alibaba.druid.stat.DruidDataSourceStatManager;
|
||||
import com.alibaba.druid.stat.JdbcStatManager;
|
||||
|
||||
public class DruidDataSourceFilterTest extends TestCase {
|
||||
|
||||
protected void tearDown() throws Exception {
|
||||
Assert.assertEquals(0, DruidDataSourceStatManager.getInstance().getDataSourceList().size());
|
||||
}
|
||||
|
||||
public void test_filter() throws Exception {
|
||||
DruidDataSource dataSource = new DruidDataSource();
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ import org.junit.Assert;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import com.alibaba.druid.pool.DruidDataSource;
|
||||
import com.alibaba.druid.stat.DruidDataSourceStatManager;
|
||||
|
||||
public class ManagedDataSourceTest extends TestCase {
|
||||
|
||||
@@ -21,6 +22,7 @@ public class ManagedDataSourceTest extends TestCase {
|
||||
|
||||
public void tearDown() throws Exception {
|
||||
dataSource.close();
|
||||
Assert.assertEquals(0, DruidDataSourceStatManager.getInstance().getDataSourceList().size());
|
||||
}
|
||||
|
||||
public void test_managed() throws Exception {
|
||||
|
||||
@@ -6,10 +6,14 @@ import junit.framework.Assert;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import com.alibaba.druid.pool.DruidDataSource;
|
||||
import com.alibaba.druid.stat.DruidDataSourceStatManager;
|
||||
import com.alibaba.druid.stat.JdbcStatManager;
|
||||
|
||||
public class ParamTest extends TestCase {
|
||||
|
||||
protected void tearDown() throws Exception {
|
||||
Assert.assertEquals(0, DruidDataSourceStatManager.getInstance().getDataSourceList().size());
|
||||
}
|
||||
|
||||
public void test_default() throws Exception {
|
||||
DruidDataSource dataSource = new DruidDataSource();
|
||||
dataSource.setUrl("jdbc:mock:");
|
||||
@@ -71,6 +75,8 @@ public class ParamTest extends TestCase {
|
||||
error = ex;
|
||||
}
|
||||
Assert.assertNotNull(error);
|
||||
|
||||
dataSource.close();
|
||||
}
|
||||
|
||||
public void test_1() throws Exception {
|
||||
@@ -94,5 +100,7 @@ public class ParamTest extends TestCase {
|
||||
}
|
||||
|
||||
Assert.assertEquals(10, JdbcStatManager.getInstance().getConnectionstat().getConnectCount());
|
||||
|
||||
dataSource.close();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,10 +15,13 @@ import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import com.alibaba.druid.filter.FilterAdapter;
|
||||
import com.alibaba.druid.filter.FilterChain;
|
||||
import com.alibaba.druid.proxy.jdbc.ConnectionProxy;
|
||||
import com.alibaba.druid.stat.DruidDataSourceStatManager;
|
||||
|
||||
public class SpringFilterTest extends TestCase {
|
||||
|
||||
public void test_spring() throws Exception {
|
||||
Assert.assertEquals(0, DruidDataSourceStatManager.getInstance().getDataSourceList().size());
|
||||
|
||||
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("com/alibaba/druid/pool/spring-config-1.xml");
|
||||
|
||||
DataSource dataSource = (DataSource) context.getBean("dataSource");
|
||||
@@ -29,6 +32,8 @@ public class SpringFilterTest extends TestCase {
|
||||
Assert.assertEquals(1, filter.getConnectCount());
|
||||
|
||||
context.close();
|
||||
|
||||
Assert.assertEquals(0, DruidDataSourceStatManager.getInstance().getDataSourceList().size());
|
||||
}
|
||||
|
||||
public static class TestFilter extends FilterAdapter {
|
||||
|
||||
@@ -7,6 +7,7 @@ import junit.framework.Assert;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import com.alibaba.druid.mock.MockDriver;
|
||||
import com.alibaba.druid.pool.DataSourceDisableException;
|
||||
import com.alibaba.druid.pool.DruidDataSource;
|
||||
import com.alibaba.druid.stat.DruidDataSourceStatManager;
|
||||
|
||||
@@ -51,6 +52,8 @@ public class TestDisable extends TestCase {
|
||||
try {
|
||||
startLatch.await();
|
||||
Connection conn = dataSource.getConnection();
|
||||
} catch (DataSourceDisableException e) {
|
||||
// skip
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
|
||||
@@ -8,8 +8,12 @@ import junit.framework.TestCase;
|
||||
import com.alibaba.druid.mock.MockConnection;
|
||||
import com.alibaba.druid.mock.MockDriver;
|
||||
import com.alibaba.druid.pool.DruidDataSource;
|
||||
import com.alibaba.druid.stat.DruidDataSourceStatManager;
|
||||
|
||||
public class TestIdle extends TestCase {
|
||||
protected void tearDown() throws Exception {
|
||||
Assert.assertEquals(0, DruidDataSourceStatManager.getInstance().getDataSourceList().size());
|
||||
}
|
||||
|
||||
public void test_idle() throws Exception {
|
||||
MockDriver driver = new MockDriver();
|
||||
|
||||
@@ -7,9 +7,14 @@ import junit.framework.TestCase;
|
||||
|
||||
import com.alibaba.druid.mock.MockDriver;
|
||||
import com.alibaba.druid.pool.DruidDataSource;
|
||||
|
||||
import com.alibaba.druid.stat.DruidDataSourceStatManager;
|
||||
|
||||
public class TestIdle2 extends TestCase {
|
||||
|
||||
protected void tearDown() throws Exception {
|
||||
Assert.assertEquals(0, DruidDataSourceStatManager.getInstance().getDataSourceList().size());
|
||||
}
|
||||
|
||||
public void test_idle2() throws Exception {
|
||||
MockDriver driver = new MockDriver();
|
||||
|
||||
@@ -25,11 +30,11 @@ public class TestIdle2 extends TestCase {
|
||||
dataSource.setTestWhileIdle(true);
|
||||
dataSource.setTestOnBorrow(false);
|
||||
dataSource.setValidationQuery("SELECT 1");
|
||||
|
||||
|
||||
{
|
||||
Assert.assertEquals(0, dataSource.getCreateCount());
|
||||
Assert.assertEquals(0, dataSource.getActiveCount());
|
||||
|
||||
|
||||
Connection conn = dataSource.getConnection();
|
||||
|
||||
Assert.assertEquals(dataSource.getInitialSize(), dataSource.getCreateCount());
|
||||
@@ -41,10 +46,10 @@ public class TestIdle2 extends TestCase {
|
||||
Assert.assertEquals(true, dataSource.getPoolingCount() == driver.getConnections().size());
|
||||
Assert.assertEquals(0, dataSource.getActiveCount());
|
||||
}
|
||||
|
||||
|
||||
String text = dataSource.toString();
|
||||
System.out.println(text);
|
||||
|
||||
|
||||
{
|
||||
int count = 14;
|
||||
Connection[] connections = new Connection[count];
|
||||
@@ -62,18 +67,18 @@ public class TestIdle2 extends TestCase {
|
||||
Assert.assertEquals(0, dataSource.getActiveCount());
|
||||
Assert.assertEquals(14, driver.getConnections().size());
|
||||
}
|
||||
|
||||
|
||||
for (int i = 0; i < 100; ++i) {
|
||||
Assert.assertEquals(0, dataSource.getActiveCount());
|
||||
Connection conn = dataSource.getConnection();
|
||||
|
||||
|
||||
Assert.assertEquals(1, dataSource.getActiveCount());
|
||||
|
||||
|
||||
Thread.sleep(1);
|
||||
conn.close();
|
||||
}
|
||||
Assert.assertEquals(true, dataSource.getPoolingCount() == dataSource.getMaxActive());
|
||||
|
||||
|
||||
dataSource.close();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ import junit.framework.TestCase;
|
||||
|
||||
import com.alibaba.druid.mock.MockDriver;
|
||||
import com.alibaba.druid.pool.DruidDataSource;
|
||||
import com.alibaba.druid.stat.DruidDataSourceStatManager;
|
||||
|
||||
public class TestIdle3_Concurrent_Starvation extends TestCase {
|
||||
|
||||
@@ -25,8 +26,8 @@ public class TestIdle3_Concurrent_Starvation extends TestCase {
|
||||
dataSource.setUrl("jdbc:mock:xxx");
|
||||
dataSource.setDriver(driver);
|
||||
dataSource.setInitialSize(1);
|
||||
dataSource.setMaxActive(1000);
|
||||
dataSource.setMaxIdle(1000);
|
||||
dataSource.setMaxActive(100);
|
||||
dataSource.setMaxIdle(100);
|
||||
dataSource.setMinIdle(1);
|
||||
dataSource.setMinEvictableIdleTimeMillis(300 * 1000); // 300 / 10
|
||||
dataSource.setTimeBetweenEvictionRunsMillis(180 * 1000); // 180 / 10
|
||||
@@ -39,6 +40,7 @@ public class TestIdle3_Concurrent_Starvation extends TestCase {
|
||||
|
||||
protected void tearDown() throws Exception {
|
||||
dataSource.close();
|
||||
Assert.assertEquals(0, DruidDataSourceStatManager.getInstance().getDataSourceList().size());
|
||||
}
|
||||
|
||||
public void test_idle2() throws Exception {
|
||||
@@ -62,12 +64,12 @@ public class TestIdle3_Concurrent_Starvation extends TestCase {
|
||||
}
|
||||
|
||||
for (int i = 0; i < 1; ++i) {
|
||||
final int threadCount = 1000;
|
||||
final int threadCount = 100;
|
||||
concurrent(threadCount);
|
||||
}
|
||||
|
||||
// 连续打开关闭单个连接
|
||||
for (int i = 0; i < 1000; ++i) {
|
||||
for (int i = 0; i < 100; ++i) {
|
||||
Assert.assertEquals(0, dataSource.getActiveCount());
|
||||
Connection conn = dataSource.getConnection();
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ import junit.framework.TestCase;
|
||||
import com.alibaba.druid.mock.MockDriver;
|
||||
import com.alibaba.druid.mock.MockPreparedStatement;
|
||||
import com.alibaba.druid.pool.DruidDataSource;
|
||||
import com.alibaba.druid.stat.DruidDataSourceStatManager;
|
||||
|
||||
public class TestPoolPreparedStatement extends TestCase {
|
||||
|
||||
@@ -36,6 +37,7 @@ public class TestPoolPreparedStatement extends TestCase {
|
||||
|
||||
protected void tearDown() throws Exception {
|
||||
dataSource.close();
|
||||
Assert.assertEquals(0, DruidDataSourceStatManager.getInstance().getDataSourceList().size());
|
||||
}
|
||||
|
||||
public void test_removeAbandoned() throws Exception {
|
||||
|
||||
@@ -7,6 +7,7 @@ import junit.framework.TestCase;
|
||||
|
||||
import com.alibaba.druid.mock.MockDriver;
|
||||
import com.alibaba.druid.pool.DruidDataSource;
|
||||
import com.alibaba.druid.stat.DruidDataSourceStatManager;
|
||||
|
||||
|
||||
public class TestRemoveAbandoned extends TestCase {
|
||||
@@ -35,7 +36,9 @@ public class TestRemoveAbandoned extends TestCase {
|
||||
|
||||
protected void tearDown() throws Exception {
|
||||
dataSource.close();
|
||||
Assert.assertEquals(0, DruidDataSourceStatManager.getInstance().getDataSourceList().size());
|
||||
}
|
||||
|
||||
|
||||
public void test_removeAbandoned() throws Exception {
|
||||
Connection conn = dataSource.getConnection();
|
||||
|
||||
@@ -16,6 +16,8 @@ public class TestStat extends TestCase {
|
||||
private DruidDataSource dataSource;
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
Assert.assertEquals(0, DruidDataSourceStatManager.getInstance().getDataSourceList().size());
|
||||
|
||||
dataSource = new DruidDataSource();
|
||||
dataSource.setUrl("jdbc:mock:xxx");
|
||||
dataSource.setName("com.alibaba.dragoon.monitor");
|
||||
|
||||
Reference in New Issue
Block a user