Package com.alibaba.druid.bvt.pool

Source Code of com.alibaba.druid.bvt.pool.DruidConnectionHolderTest4

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();
    }
}
TOP

Related Classes of com.alibaba.druid.bvt.pool.DruidConnectionHolderTest4

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.