mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
@@ -215,10 +215,9 @@ public final class DruidConnectionHolder {
|
||||
buf.append("\"");
|
||||
}
|
||||
|
||||
PreparedStatementPool statmentPool = this.getStatementPool();
|
||||
if (statmentPool != null && statmentPool.getMap().size() > 0) {
|
||||
if (statementPool != null && statementPool.getMap().size() > 0) {
|
||||
buf.append("\", CachedStatementCount:");
|
||||
buf.append(this.getStatementPool().getMap().size());
|
||||
buf.append(statementPool.getMap().size());
|
||||
}
|
||||
|
||||
buf.append("}");
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
package com.alibaba.druid.bvt.pool;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.sql.PreparedStatement;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.pool.DruidConnectionHolder;
|
||||
import com.alibaba.druid.pool.DruidDataSource;
|
||||
import com.alibaba.druid.pool.DruidPooledConnection;
|
||||
|
||||
public class DruidConnectionHolderTest4 extends TestCase {
|
||||
|
||||
private DruidDataSource dataSource;
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
dataSource = new DruidDataSource();
|
||||
dataSource.setUrl("jdbc:mock:xxx");
|
||||
dataSource.setTestOnBorrow(false);
|
||||
dataSource.setPoolPreparedStatements(true);
|
||||
|
||||
}
|
||||
|
||||
protected void tearDown() throws Exception {
|
||||
dataSource.close();
|
||||
}
|
||||
|
||||
public void test_toString() throws Exception {
|
||||
DruidPooledConnection conn = dataSource.getConnection();
|
||||
|
||||
DruidConnectionHolder holder = conn.getConnectionHolder();
|
||||
|
||||
Field field = DruidConnectionHolder.class.getDeclaredField("statementPool");
|
||||
field.setAccessible(true);
|
||||
Assert.assertNull(field.get(holder));
|
||||
|
||||
holder.toString();
|
||||
|
||||
Assert.assertNull(field.get(holder));
|
||||
|
||||
holder.getStatementPool();
|
||||
|
||||
Assert.assertNotNull(field.get(holder));
|
||||
|
||||
holder.toString();
|
||||
|
||||
PreparedStatement stmt = conn.prepareStatement("select 1");
|
||||
stmt.execute();
|
||||
stmt.close();
|
||||
|
||||
conn.close();
|
||||
|
||||
Assert.assertEquals(1, holder.getStatementPool().size());
|
||||
|
||||
holder.toString();
|
||||
}
|
||||
}
|
||||
@@ -160,4 +160,12 @@ public class DruidDataSourceFactoryTest1 extends TestCase {
|
||||
JdbcUtils.close(dataSource);
|
||||
}
|
||||
}
|
||||
|
||||
public void test_getObjectInstance() throws Exception {
|
||||
Assert.assertNull(new DruidDataSourceFactory().getObjectInstance(null, null, null, null));
|
||||
}
|
||||
|
||||
public void test_getObjectInstance_1() throws Exception {
|
||||
Assert.assertNull(new DruidDataSourceFactory().getObjectInstance(new Object(), null, null, null));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user