mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
add dynamic config support
This commit is contained in:
@@ -33,7 +33,6 @@ public class DataSourceTest3 extends TestCase {
|
||||
dataSource.setDriver(driver);
|
||||
dataSource.setInitialSize(1);
|
||||
dataSource.setMaxActive(2);
|
||||
dataSource.setMaxIdle(2);
|
||||
dataSource.setMinIdle(1);
|
||||
dataSource.setMinEvictableIdleTimeMillis(300 * 1000); // 300 / 10
|
||||
dataSource.setTimeBetweenEvictionRunsMillis(180 * 1000); // 180 / 10
|
||||
@@ -41,7 +40,7 @@ public class DataSourceTest3 extends TestCase {
|
||||
dataSource.setTestOnBorrow(true);
|
||||
dataSource.setTestOnReturn(true);
|
||||
dataSource.setValidationQuery("SELECT 1");
|
||||
dataSource.setFilters("stat,trace");
|
||||
dataSource.setFilters("stat");
|
||||
|
||||
JdbcStatContext context = new JdbcStatContext();
|
||||
context.setTraceEnable(true);
|
||||
@@ -137,36 +136,20 @@ public class DataSourceTest3 extends TestCase {
|
||||
dataSource.setPassword("xx");
|
||||
}
|
||||
|
||||
public void test_error_8() throws Exception {
|
||||
public void test_change_connectProperties() throws Exception {
|
||||
DruidPooledConnection conn = dataSource.getConnection().unwrap(DruidPooledConnection.class);
|
||||
|
||||
conn.close();
|
||||
|
||||
{
|
||||
Exception error = null;
|
||||
try {
|
||||
dataSource.setConnectProperties(new Properties());
|
||||
} catch (Exception ex) {
|
||||
error = ex;
|
||||
}
|
||||
Assert.assertNotNull(error);
|
||||
}
|
||||
dataSource.setConnectProperties(new Properties());
|
||||
}
|
||||
|
||||
public void test_error_9() throws Exception {
|
||||
public void test_change_connectProperties_2() throws Exception {
|
||||
DruidPooledConnection conn = dataSource.getConnection().unwrap(DruidPooledConnection.class);
|
||||
|
||||
conn.close();
|
||||
|
||||
{
|
||||
Exception error = null;
|
||||
try {
|
||||
dataSource.setConnectionProperties("x=12;;");
|
||||
} catch (Exception ex) {
|
||||
error = ex;
|
||||
}
|
||||
Assert.assertNotNull(error);
|
||||
}
|
||||
dataSource.setConnectionProperties("x=12;;");
|
||||
}
|
||||
|
||||
public void test_getValidConnectionCheckerClassName() throws Exception {
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
package com.alibaba.druid.bvt.pool.dynamic;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.sql.Connection;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import com.alibaba.druid.pool.DruidDataSource;
|
||||
import com.alibaba.druid.support.logging.Log;
|
||||
|
||||
public class ConnectPropertiesChangeTest extends TestCase {
|
||||
|
||||
private DruidDataSource dataSource;
|
||||
|
||||
private Log dataSourceLog;
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
Field logField = DruidDataSource.class.getDeclaredField("LOG");
|
||||
logField.setAccessible(true);
|
||||
dataSourceLog = (Log) logField.get(null);
|
||||
|
||||
dataSourceLog.resetStat();
|
||||
|
||||
dataSource = new DruidDataSource();
|
||||
dataSource.setUrl("jdbc:mock:xxx");
|
||||
dataSource.setTestOnBorrow(false);
|
||||
dataSource.setConnectionProperties("a=3;b=4");
|
||||
dataSource.init();
|
||||
|
||||
Assert.assertEquals(1, dataSourceLog.getInfoCount());
|
||||
}
|
||||
|
||||
protected void tearDown() throws Exception {
|
||||
dataSource.close();
|
||||
}
|
||||
|
||||
public void test_connectPropertiesChange() throws Exception {
|
||||
Assert.assertEquals(2, dataSource.getConnectProperties().size());
|
||||
|
||||
Assert.assertEquals("3", dataSource.getConnectProperties().getProperty("a"));
|
||||
Assert.assertEquals("4", dataSource.getConnectProperties().getProperty("b"));
|
||||
|
||||
Connection conn = dataSource.getConnection();
|
||||
conn.close();
|
||||
|
||||
dataSource.setConnectionProperties("b=5;c=6");
|
||||
|
||||
Assert.assertEquals(2, dataSourceLog.getInfoCount());
|
||||
|
||||
Assert.assertEquals(2, dataSource.getConnectProperties().size());
|
||||
|
||||
Assert.assertEquals("5", dataSource.getConnectProperties().getProperty("b"));
|
||||
Assert.assertEquals("6", dataSource.getConnectProperties().getProperty("c"));
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.alibaba.druid.bvt.pool;
|
||||
package com.alibaba.druid.bvt.pool.dynamic;
|
||||
|
||||
import java.sql.Connection;
|
||||
|
||||
Reference in New Issue
Block a user