mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
配置和apache dbcp一致
git-svn-id: http://code.alibabatech.com/svn/druid/trunk@5 b9813039-fb51-4c41-a8b9-e21c2acb5095
This commit is contained in:
@@ -5,9 +5,18 @@
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>druid</artifactId>
|
||||
<version>0.2-SNAPSHOT</version>
|
||||
|
||||
|
||||
<name>druid</name>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>oracleReleases</id>
|
||||
<name>Oracle Released Java Packages</name>
|
||||
<url>http://download.oracle.com/maven</url>
|
||||
<layout>default</layout>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<!-- 配置源码编译要求JDK 1.6 -->
|
||||
|
||||
@@ -80,7 +80,7 @@ public class StatFilter extends FilterEventAdapter implements StatFilterMBean {
|
||||
|
||||
ConcurrentMap<String, JdbcDataSourceStat> dataSourceStats = JdbcStatManager.getInstance().getDataSources();
|
||||
|
||||
String url = dataSource.getJdbcUrl();
|
||||
String url = dataSource.getUrl();
|
||||
JdbcDataSourceStat stat = dataSourceStats.get(url);
|
||||
if (stat == null) {
|
||||
dataSourceStats.putIfAbsent(url, new JdbcDataSourceStat(dataSource.getName(), url));
|
||||
@@ -611,7 +611,7 @@ public class StatFilter extends FilterEventAdapter implements StatFilterMBean {
|
||||
|
||||
@Override
|
||||
public String getConnectionUrl() {
|
||||
return dataSource.getJdbcUrl();
|
||||
return dataSource.getUrl();
|
||||
}
|
||||
|
||||
public final JdbcSqlStat createSqlStat(StatementProxy statement, String sql) {
|
||||
@@ -620,7 +620,7 @@ public class StatFilter extends FilterEventAdapter implements StatFilterMBean {
|
||||
JdbcSqlStat newSqlStat = new JdbcSqlStat(sql);
|
||||
if (dataSourceStat.getSqlStatMap().putIfAbsent(sql, newSqlStat) == null) {
|
||||
newSqlStat.setId(JdbcStatManager.getInstance().generateSqlId());
|
||||
newSqlStat.setDataSource(this.dataSource.getJdbcUrl());
|
||||
newSqlStat.setDataSource(this.dataSource.getUrl());
|
||||
}
|
||||
|
||||
sqlStat = dataSourceStat.getSqlStatMap().get(sql);
|
||||
|
||||
@@ -277,11 +277,11 @@ public abstract class DruidDataAbstractSource implements DataSource, DataSourceP
|
||||
this.maxActive = maxActive;
|
||||
}
|
||||
|
||||
public String getUser() {
|
||||
public String getUsername() {
|
||||
return user;
|
||||
}
|
||||
|
||||
public void setUser(String user) {
|
||||
public void setUsername(String user) {
|
||||
if (inited) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
@@ -313,7 +313,7 @@ public abstract class DruidDataAbstractSource implements DataSource, DataSourceP
|
||||
this.properties = properties;
|
||||
}
|
||||
|
||||
public String getJdbcUrl() {
|
||||
public String getUrl() {
|
||||
return jdbcUrl;
|
||||
}
|
||||
|
||||
@@ -333,7 +333,7 @@ public abstract class DruidDataAbstractSource implements DataSource, DataSourceP
|
||||
return driverClass;
|
||||
}
|
||||
|
||||
public void setDriverClass(String driverClass) {
|
||||
public void setDriverClassName(String driverClass) {
|
||||
if (inited) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
@@ -402,14 +402,14 @@ public abstract class DruidDataAbstractSource implements DataSource, DataSourceP
|
||||
|
||||
public DruidPoolConnectionFactory(DruidDataAbstractSource dataSource){
|
||||
this.dataSource = dataSource;
|
||||
this.url = dataSource.getJdbcUrl();
|
||||
this.url = dataSource.getUrl();
|
||||
|
||||
Properties properties = dataSource.getProperties();
|
||||
String user;
|
||||
if (dataSource.getUserCallback() != null) {
|
||||
user = dataSource.getUserCallback().getName();
|
||||
} else {
|
||||
user = dataSource.getUser();
|
||||
user = dataSource.getUsername();
|
||||
}
|
||||
|
||||
String password;
|
||||
|
||||
@@ -15,11 +15,11 @@ public interface DruidDataSourceMBean {
|
||||
|
||||
int getInitialSize();
|
||||
|
||||
String getUser();
|
||||
String getUsername();
|
||||
|
||||
String getPassword();
|
||||
|
||||
String getJdbcUrl();
|
||||
String getUrl();
|
||||
|
||||
String getDriverClass();
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ public interface DataSourceProxy {
|
||||
|
||||
Driver getRawDriver();
|
||||
|
||||
String getJdbcUrl();
|
||||
String getUrl();
|
||||
|
||||
String getRawJdbcUrl();
|
||||
|
||||
|
||||
@@ -100,19 +100,13 @@ public class DataSourceProxyImpl implements DataSourceProxy, DataSourceProxyImpl
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUrl() {
|
||||
return this.config.getUrl();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return this.config.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getJdbcUrl() {
|
||||
public String getUrl() {
|
||||
return config.getUrl();
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
package com.alibaba.druid;
|
||||
|
||||
import java.lang.management.ManagementFactory;
|
||||
|
||||
import javax.management.MBeanServer;
|
||||
import javax.management.ObjectName;
|
||||
|
||||
public class TestUtil {
|
||||
public static long getYoungGC() {
|
||||
try {
|
||||
MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer();
|
||||
ObjectName objectName;
|
||||
if (mbeanServer.isRegistered(new ObjectName("java.lang:type=GarbageCollector,name=ParNew"))) {
|
||||
objectName = new ObjectName("java.lang:type=GarbageCollector,name=ParNew");
|
||||
} else if (mbeanServer.isRegistered(new ObjectName("java.lang:type=GarbageCollector,name=Copy"))) {
|
||||
objectName = new ObjectName("java.lang:type=GarbageCollector,name=Copy");
|
||||
} else {
|
||||
objectName = new ObjectName("java.lang:type=GarbageCollector,name=PS Scavenge");
|
||||
}
|
||||
|
||||
return (Long) mbeanServer.getAttribute(objectName, "CollectionCount");
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("error");
|
||||
}
|
||||
}
|
||||
|
||||
public static long getFullGC() {
|
||||
try {
|
||||
MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer();
|
||||
ObjectName objectName;
|
||||
|
||||
if (mbeanServer.isRegistered(new ObjectName("java.lang:type=GarbageCollector,name=ConcurrentMarkSweep"))) {
|
||||
objectName = new ObjectName("java.lang:type=GarbageCollector,name=ConcurrentMarkSweep");
|
||||
} else if (mbeanServer.isRegistered(new ObjectName("java.lang:type=GarbageCollector,name=MarkSweepCompact"))) {
|
||||
objectName = new ObjectName("java.lang:type=GarbageCollector,name=MarkSweepCompact");
|
||||
} else {
|
||||
objectName = new ObjectName("java.lang:type=GarbageCollector,name=PS MarkSweep");
|
||||
}
|
||||
|
||||
return (Long) mbeanServer.getAttribute(objectName, "CollectionCount");
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("error");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -43,10 +43,10 @@ public class Case0 extends TestCase {
|
||||
dataSource.setMinIdle(minPoolSize);
|
||||
dataSource.setMaxIdle(maxPoolSize);
|
||||
dataSource.setPoolPreparedStatements(true);
|
||||
dataSource.setDriverClass(driverClass);
|
||||
dataSource.setDriverClassName(driverClass);
|
||||
dataSource.setUrl(jdbcUrl);
|
||||
dataSource.setPoolPreparedStatements(true);
|
||||
dataSource.setUser(user);
|
||||
dataSource.setUsername(user);
|
||||
dataSource.setPassword(password);
|
||||
|
||||
final int LOOP_COUNT = 1000 * 1000;
|
||||
|
||||
@@ -41,10 +41,10 @@ public class ConcurrentTest extends TestCase {
|
||||
dataSource.setMinIdle(minPoolSize);
|
||||
dataSource.setMaxIdle(maxPoolSize);
|
||||
dataSource.setPoolPreparedStatements(true);
|
||||
dataSource.setDriverClass(driverClass);
|
||||
dataSource.setDriverClassName(driverClass);
|
||||
dataSource.setUrl(jdbcUrl);
|
||||
dataSource.setPoolPreparedStatements(true);
|
||||
dataSource.setUser(user);
|
||||
dataSource.setUsername(user);
|
||||
dataSource.setPassword(password);
|
||||
|
||||
final int THREAD_COUNT = 2;
|
||||
|
||||
@@ -16,7 +16,7 @@ public class TestDruidDataSource extends TestCase {
|
||||
|
||||
dataSource.setInitialSize(10);
|
||||
dataSource.setMaxIdle(10);
|
||||
dataSource.setDriverClass("com.alibaba.druid.mock.MockDriver");
|
||||
dataSource.setDriverClassName("com.alibaba.druid.mock.MockDriver");
|
||||
dataSource.setUrl("jdbc:mock:xxx");
|
||||
|
||||
Assert.assertEquals(0, dataSource.getConnectCount());
|
||||
|
||||
@@ -42,7 +42,7 @@ public class Test_C2 extends TestCase {
|
||||
dataSource.setMinIdle(minPoolSize);
|
||||
dataSource.setMaxIdle(maxPoolSize);
|
||||
dataSource.setPoolPreparedStatements(true);
|
||||
dataSource.setDriverClass(driverClass);
|
||||
dataSource.setDriverClassName(driverClass);
|
||||
dataSource.setUrl(jdbcUrl);
|
||||
dataSource.setPoolPreparedStatements(true);
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ import junit.framework.TestCase;
|
||||
|
||||
import org.apache.commons.dbcp.BasicDataSource;
|
||||
|
||||
import com.alibaba.druid.TestUtil;
|
||||
import com.alibaba.druid.pool.DruidDataSource;
|
||||
|
||||
public class Case0 extends TestCase {
|
||||
@@ -38,15 +39,16 @@ public class Case0 extends TestCase {
|
||||
dataSource.setMinIdle(minPoolSize);
|
||||
dataSource.setMaxIdle(maxPoolSize);
|
||||
dataSource.setPoolPreparedStatements(true);
|
||||
dataSource.setDriverClass(driverClass);
|
||||
dataSource.setDriverClassName(driverClass);
|
||||
dataSource.setUrl(jdbcUrl);
|
||||
dataSource.setPoolPreparedStatements(true);
|
||||
dataSource.setUser(user);
|
||||
dataSource.setUsername(user);
|
||||
dataSource.setPassword(password);
|
||||
|
||||
for (int i = 0; i < 10; ++i) {
|
||||
p0(dataSource);
|
||||
p0(dataSource, "druid");
|
||||
}
|
||||
System.out.println();
|
||||
}
|
||||
|
||||
public void test_1() throws Exception {
|
||||
@@ -64,18 +66,25 @@ public class Case0 extends TestCase {
|
||||
dataSource.setPassword(password);
|
||||
|
||||
for (int i = 0; i < 10; ++i) {
|
||||
p0(dataSource);
|
||||
p0(dataSource, "dbcp");
|
||||
}
|
||||
System.out.println();
|
||||
}
|
||||
|
||||
private void p0(DataSource dataSource) throws SQLException {
|
||||
private void p0(DataSource dataSource, String name) throws SQLException {
|
||||
long startMillis = System.currentTimeMillis();
|
||||
long startYGC = TestUtil.getYoungGC();
|
||||
long startFullGC = TestUtil.getFullGC();
|
||||
|
||||
final int COUNT = 1000 * 1000;
|
||||
for (int i = 0; i < COUNT; ++i) {
|
||||
Connection conn = dataSource.getConnection();
|
||||
conn.close();
|
||||
}
|
||||
long millis = System.currentTimeMillis() - startMillis;
|
||||
System.out.println(dataSource.getClass().getName() + " millis : " + NumberFormat.getInstance().format(millis));
|
||||
long ygc = TestUtil.getYoungGC() - startYGC;
|
||||
long fullGC = TestUtil.getFullGC() - startFullGC;
|
||||
|
||||
System.out.println(name + " millis : " + NumberFormat.getInstance().format(millis) + ", YGC " + ygc + " FGC " + fullGC);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user