mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
add sharding visitor
This commit is contained in:
@@ -13,18 +13,6 @@
|
||||
<inceptionYear>2012</inceptionYear>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>oracleReleases</id>
|
||||
<name>Oracle Released Java Packages</name>
|
||||
<url>http://download.oracle.com/maven</url>
|
||||
<layout>default</layout>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>vars.sourceforge.net</id>
|
||||
<name>vars.sourceforge.net</name>
|
||||
<url>http://vars.sourceforge.net/maven2/</url>
|
||||
<layout>default</layout>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>bonecp</id>
|
||||
<name>bonecp</name>
|
||||
@@ -247,7 +235,7 @@
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
<version>5.0.4</version>
|
||||
<version>5.1.20</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.alibaba.druid.sql.visitor;
|
||||
|
||||
import com.alibaba.druid.sql.ast.SQLObject;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLInsertStatement;
|
||||
|
||||
public class SQLShardingVisitor extends SQLASTVisitorAdapter {
|
||||
|
||||
public void postVisit(SQLObject x) {
|
||||
}
|
||||
|
||||
public void preVisit(SQLObject x) {
|
||||
}
|
||||
|
||||
public boolean visit(SQLInsertStatement x) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package com.alibaba.druid.bvt.pool;
|
||||
|
||||
import java.lang.management.ManagementFactory;
|
||||
import java.sql.Connection;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import com.alibaba.druid.pool.DruidDataSource;
|
||||
import com.alibaba.druid.stat.DruidDataSourceStatManager;
|
||||
|
||||
public class TestActiveTrace extends TestCase {
|
||||
|
||||
private DruidDataSource dataSource;
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
Assert.assertEquals(0, DruidDataSourceStatManager.getInstance().getDataSourceList().size());
|
||||
|
||||
dataSource = new DruidDataSource();
|
||||
dataSource.setRemoveAbandoned(true);
|
||||
dataSource.setRemoveAbandonedTimeoutMillis(10);
|
||||
dataSource.setLogAbandoned(true);
|
||||
dataSource.setTimeBetweenEvictionRunsMillis(10);
|
||||
dataSource.setMinEvictableIdleTimeMillis(300 * 1000);
|
||||
dataSource.setUrl("jdbc:mock:xxx");
|
||||
|
||||
}
|
||||
|
||||
protected void tearDown() throws Exception {
|
||||
dataSource.close();
|
||||
Assert.assertEquals(0, DruidDataSourceStatManager.getInstance().getDataSourceList().size());
|
||||
}
|
||||
|
||||
public void test_activeTrace() throws Exception {
|
||||
for (int i = 0; i < 1000 * 1000; ++i) {
|
||||
dataSource.shrink();
|
||||
|
||||
Connection conn = dataSource.getConnection();
|
||||
conn.close();
|
||||
// Assert.assertEquals(1, dataSource.getPoolingCount());
|
||||
dataSource.shrink();
|
||||
Assert.assertEquals(0, dataSource.getPoolingCount());
|
||||
Assert.assertEquals(0, dataSource.getActiveConnections().size());
|
||||
|
||||
if (i % 5000 == 0) {
|
||||
System.out.println(ManagementFactory.getClassLoadingMXBean().getLoadedClassCount());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user