forked from alibaba/druid
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
0.1.19-SNAPSHOT && add test && test library
- Loading branch information
Showing
9 changed files
with
340 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.alibaba.druid; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
|
||
public class TestForZY { | ||
public void foo() throws Exception { | ||
Map<String, Map.Entry<String, Boolean>> m = new HashMap<String, Map.Entry<String, Boolean>>(); | ||
} | ||
|
||
public static class A<T> { | ||
private T value; | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
src/test/java/com/alibaba/druid/TestLinkedTransferQueue.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.alibaba.druid; | ||
|
||
import junit.framework.TestCase; | ||
|
||
import com.alibaba.druid.util.LinkedTransferQueue; | ||
|
||
public class TestLinkedTransferQueue extends TestCase { | ||
|
||
public void test_LinkedTransferQueue() throws Exception { | ||
final LinkedTransferQueue<String> q = new LinkedTransferQueue<String>(); | ||
|
||
Thread thread = new Thread() { | ||
|
||
public void run() { | ||
for (;;) { | ||
try { | ||
q.take(); | ||
} catch (InterruptedException e) { | ||
// TODO Auto-generated catch block | ||
e.printStackTrace(); | ||
} | ||
} | ||
} | ||
}; | ||
thread.start(); | ||
q.put("1"); | ||
} | ||
} |
130 changes: 130 additions & 0 deletions
130
src/test/java/com/alibaba/druid/pool/bonecp/TestLRU.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
package com.alibaba.druid.pool.bonecp; | ||
|
||
import java.lang.reflect.Field; | ||
import java.sql.Connection; | ||
|
||
import javax.sql.DataSource; | ||
|
||
import junit.framework.TestCase; | ||
|
||
import org.apache.commons.dbcp.BasicDataSource; | ||
import org.logicalcobwebs.proxool.ProxoolDataSource; | ||
|
||
import com.alibaba.druid.mock.MockConnection; | ||
import com.alibaba.druid.pool.DruidDataSource; | ||
import com.jolbox.bonecp.BoneCPDataSource; | ||
import com.jolbox.bonecp.ConnectionHandle; | ||
import com.mchange.v2.c3p0.ComboPooledDataSource; | ||
import com.mchange.v2.c3p0.impl.NewProxyConnection; | ||
|
||
public class TestLRU extends TestCase { | ||
|
||
public void f_test_boneCP() throws Exception { | ||
BoneCPDataSource ds = new BoneCPDataSource(); | ||
ds.setJdbcUrl("jdbc:mock:test"); | ||
ds.setPartitionCount(1); | ||
ds.setMaxConnectionsPerPartition(10); | ||
ds.setMinConnectionsPerPartition(0); | ||
|
||
for (int i = 0; i < 10; ++i) { | ||
f(ds, 5); | ||
System.out.println("--------------------------------------------"); | ||
} | ||
} | ||
|
||
public void f_test_druid() throws Exception { | ||
DruidDataSource ds = new DruidDataSource(); | ||
ds.setUrl("jdbc:mock:test"); | ||
ds.setMaxIdle(10); | ||
|
||
for (int i = 0; i < 10; ++i) { | ||
f(ds, 5); | ||
System.out.println("--------------------------------------------"); | ||
} | ||
} | ||
|
||
public void f_test_dbcp() throws Exception { | ||
BasicDataSource ds = new BasicDataSource(); | ||
ds.setUrl("jdbc:mock:test"); | ||
ds.setMaxIdle(10); | ||
|
||
for (int i = 0; i < 10; ++i) { | ||
f(ds, 5); | ||
System.out.println("--------------------------------------------"); | ||
} | ||
} | ||
|
||
public void f_test_c3p0() throws Exception { | ||
ComboPooledDataSource ds = new ComboPooledDataSource(); | ||
ds.setJdbcUrl("jdbc:mock:test"); | ||
ds.setMaxPoolSize(10); | ||
ds.setMinPoolSize(0); | ||
|
||
for (int i = 0; i < 10; ++i) { | ||
f(ds, 5); | ||
System.out.println("--------------------------------------------"); | ||
} | ||
} | ||
|
||
public void f_test_proxool() throws Exception { | ||
ProxoolDataSource ds = new ProxoolDataSource(); | ||
ds.setDriver("com.alibaba.druid.mock.MockDriver"); | ||
ds.setDriverUrl("jdbc:mock:test"); | ||
ds.setMaximumConnectionCount(10); | ||
ds.setMinimumConnectionCount(0); | ||
ds.setUser("user"); | ||
ds.setPassword("password"); | ||
|
||
for (int i = 0; i < 10; ++i) { | ||
f(ds, 5); | ||
System.out.println("--------------------------------------------"); | ||
} | ||
} | ||
|
||
// public void test_jboss() throws Exception { | ||
// LocalTxDataSource ds = new LocalTxDataSource(); | ||
// ds.setDriverClass("com.alibaba.druid.mock.MockDriver"); | ||
// ds.setConnectionURL("jdbc:mock:test"); | ||
// ds.setMaxSize(10); | ||
// ds.setMinSize(0); | ||
// ds.setUserName("user"); | ||
// ds.setPassword("password"); | ||
// | ||
// for (int i = 0; i < 10; ++i) { | ||
// f(ds, 5); | ||
// System.out.println("--------------------------------------------"); | ||
// } | ||
// } | ||
|
||
public static void f(DataSource ds, int count) throws Exception { | ||
Connection[] connections = new Connection[count]; | ||
for (int i = 0; i < count; ++i) { | ||
connections[i] = ds.getConnection(); | ||
} | ||
|
||
for (int i = 0; i < count; ++i) { | ||
System.out.println(unwrap(connections[i]).getId()); | ||
} | ||
|
||
for (int i = count - 1; i >= 0; --i) { | ||
connections[i].close(); | ||
} | ||
} | ||
|
||
public static MockConnection unwrap(Connection conn) throws Exception { | ||
if (conn instanceof ConnectionHandle) { | ||
ConnectionHandle handle = (ConnectionHandle) conn; | ||
return (MockConnection) handle.getInternalConnection(); | ||
} | ||
if (conn instanceof NewProxyConnection) { | ||
NewProxyConnection handle = (NewProxyConnection) conn; | ||
|
||
Field field = NewProxyConnection.class.getDeclaredField("inner"); | ||
field.setAccessible(true); | ||
return (MockConnection) field.get(handle); | ||
} | ||
|
||
return conn.unwrap(MockConnection.class); | ||
} | ||
|
||
} |
129 changes: 129 additions & 0 deletions
129
src/test/java/com/alibaba/druid/pool/bonecp/TestPSCache.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
package com.alibaba.druid.pool.bonecp; | ||
|
||
import java.lang.reflect.Field; | ||
import java.sql.Connection; | ||
import java.sql.PreparedStatement; | ||
|
||
import javax.sql.DataSource; | ||
|
||
import junit.framework.TestCase; | ||
|
||
import org.apache.commons.dbcp.BasicDataSource; | ||
import org.logicalcobwebs.proxool.ProxoolDataSource; | ||
|
||
import com.alibaba.druid.mock.MockConnection; | ||
import com.alibaba.druid.mock.MockPreparedStatement; | ||
import com.alibaba.druid.pool.DruidDataSource; | ||
import com.jolbox.bonecp.BoneCPDataSource; | ||
import com.jolbox.bonecp.ConnectionHandle; | ||
import com.mchange.v2.c3p0.ComboPooledDataSource; | ||
import com.mchange.v2.c3p0.impl.NewProxyConnection; | ||
import com.mchange.v2.c3p0.impl.NewProxyPreparedStatement; | ||
|
||
public class TestPSCache extends TestCase { | ||
|
||
public void test_boneCP() throws Exception { | ||
BoneCPDataSource ds = new BoneCPDataSource(); | ||
ds.setJdbcUrl("jdbc:mock:test"); | ||
ds.setPartitionCount(1); | ||
ds.setMaxConnectionsPerPartition(10); | ||
ds.setMinConnectionsPerPartition(0); | ||
ds.setPreparedStatementsCacheSize(10); | ||
|
||
for (int i = 0; i < 10; ++i) { | ||
f(ds, 5); | ||
System.out.println("--------------------------------------------"); | ||
} | ||
} | ||
|
||
public void f_test_druid() throws Exception { | ||
DruidDataSource ds = new DruidDataSource(); | ||
ds.setUrl("jdbc:mock:test"); | ||
ds.setMaxIdle(10); | ||
|
||
for (int i = 0; i < 10; ++i) { | ||
f(ds, 5); | ||
System.out.println("--------------------------------------------"); | ||
} | ||
} | ||
|
||
public void f_test_dbcp() throws Exception { | ||
BasicDataSource ds = new BasicDataSource(); | ||
ds.setUrl("jdbc:mock:test"); | ||
ds.setMaxIdle(10); | ||
ds.setPoolPreparedStatements(true); | ||
ds.setMaxOpenPreparedStatements(10); | ||
|
||
for (int i = 0; i < 10; ++i) { | ||
f(ds, 5); | ||
System.out.println("--------------------------------------------"); | ||
} | ||
} | ||
|
||
public void f_test_c3p0() throws Exception { | ||
ComboPooledDataSource ds = new ComboPooledDataSource(); | ||
ds.setJdbcUrl("jdbc:mock:test"); | ||
ds.setMaxPoolSize(10); | ||
ds.setMinPoolSize(0); | ||
ds.setMaxStatements(10); | ||
|
||
for (int i = 0; i < 10; ++i) { | ||
f(ds, 5); | ||
System.out.println("--------------------------------------------"); | ||
} | ||
} | ||
|
||
public void f_test_proxool() throws Exception { | ||
ProxoolDataSource ds = new ProxoolDataSource(); | ||
ds.setDriver("com.alibaba.druid.mock.MockDriver"); | ||
ds.setDriverUrl("jdbc:mock:test"); | ||
ds.setMaximumConnectionCount(10); | ||
ds.setMinimumConnectionCount(0); | ||
ds.setUser("user"); | ||
ds.setPassword("password"); | ||
|
||
for (int i = 0; i < 10; ++i) { | ||
f(ds, 5); | ||
System.out.println("--------------------------------------------"); | ||
} | ||
} | ||
|
||
public static void f(DataSource ds, int count) throws Exception { | ||
Connection conn = ds.getConnection(); | ||
|
||
for (int i = 0; i < count; ++i) { | ||
PreparedStatement stmt = conn.prepareStatement("SELECT 1"); | ||
System.out.println(System.identityHashCode(unwrap(stmt))); | ||
stmt.close(); | ||
} | ||
|
||
conn.close(); | ||
} | ||
|
||
public static MockPreparedStatement unwrap(PreparedStatement stmt) throws Exception { | ||
if (stmt instanceof NewProxyPreparedStatement) { | ||
Field field = NewProxyPreparedStatement.class.getDeclaredField("inner"); | ||
field.setAccessible(true); | ||
return (MockPreparedStatement) field.get(stmt); | ||
} | ||
MockPreparedStatement mockStmt = stmt.unwrap(MockPreparedStatement.class); | ||
return mockStmt; | ||
} | ||
|
||
public static MockConnection unwrap(Connection conn) throws Exception { | ||
if (conn instanceof ConnectionHandle) { | ||
ConnectionHandle handle = (ConnectionHandle) conn; | ||
return (MockConnection) handle.getInternalConnection(); | ||
} | ||
if (conn instanceof NewProxyConnection) { | ||
NewProxyConnection handle = (NewProxyConnection) conn; | ||
|
||
Field field = NewProxyConnection.class.getDeclaredField("inner"); | ||
field.setAccessible(true); | ||
return (MockConnection) field.get(handle); | ||
} | ||
|
||
return conn.unwrap(MockConnection.class); | ||
} | ||
|
||
} |