Package com.alibaba.druid.bvt.pool

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

package com.alibaba.druid.bvt.pool;

import java.sql.Connection;
import java.sql.PreparedStatement;

import org.junit.Assert;
import junit.framework.TestCase;

import com.alibaba.druid.pool.DruidDataSource;

/**
* 这个场景测试minIdle > maxActive
*
* @author wenshao<szujobs@hotmail.com>
*/
public class DruidDataSourceTest_clearCache 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_clearStatementCache() throws Exception {
        {
            Connection conn = dataSource.getConnection();
            PreparedStatement stmt = conn.prepareStatement("select 1");
            stmt.close();
            conn.close();
        }
        {
            Connection conn = dataSource.getConnection();
            PreparedStatement stmt = conn.prepareStatement("select 1, 2");
            stmt.close();
            conn.close();
        }
        Assert.assertEquals(2, dataSource.getCachedPreparedStatementCount());
       
        dataSource.clearStatementCache();
       
        Assert.assertEquals(0, dataSource.getCachedPreparedStatementCount());
    }
}
TOP

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

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.