mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
DruidDataSource add keepAlive support.
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
package com.alibaba.druid.bvt.pool;
|
||||
|
||||
import com.alibaba.druid.pool.DruidDataSource;
|
||||
import com.alibaba.druid.util.JdbcUtils;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
* Created by wenshao on 21/01/2017.
|
||||
*/
|
||||
public class KeepAliveTest extends TestCase {
|
||||
private DruidDataSource dataSource;
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
dataSource = new DruidDataSource();
|
||||
dataSource.setUrl("jdbc:mock:x1");
|
||||
dataSource.setPoolPreparedStatements(true);
|
||||
dataSource.setMinIdle(10);
|
||||
dataSource.setMaxActive(20);
|
||||
// dataSource.setMinEvictableIdleTimeMillis(30000);
|
||||
// dataSource.setMaxEvictableIdleTimeMillis(30000);
|
||||
dataSource.setTimeBetweenEvictionRunsMillis(10);
|
||||
dataSource.setFilters("log4j");
|
||||
dataSource.setValidationQuery("select 1");
|
||||
|
||||
Properties properties = new Properties();
|
||||
properties.put("druid.keepAlive", "true");
|
||||
dataSource.configFromPropety(properties);
|
||||
}
|
||||
|
||||
protected void tearDown() throws Exception {
|
||||
JdbcUtils.close(dataSource);
|
||||
}
|
||||
|
||||
public void test_keepAlive() throws Exception {
|
||||
assertTrue(dataSource.isKeepAlive());
|
||||
|
||||
Connection[] connections = new Connection[dataSource.getMaxActive()];
|
||||
for (int i = 0; i < connections.length; ++i) {
|
||||
connections[i] = dataSource.getConnection();
|
||||
}
|
||||
for (int i = 0; i < connections.length; ++i) {
|
||||
connections[i].close();
|
||||
}
|
||||
// assertEquals(dataSource.getMaxActive(), dataSource.getPoolingCount());
|
||||
|
||||
|
||||
|
||||
// Thread.sleep(1000 * 1000);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user