content: package com.alibaba.druid.bvt.pool;
  
  import com.alibaba.druid.pool.DruidDataSource;
  import junit.framework.TestCase;
  
  import java.sql.Connection;
  import java.sql.PreparedStatement;
  
  /**
   * 这个场景测试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();
          }
          assertEquals(2, dataSource.getCachedPreparedStatementCount());
  
          dataSource.clearStatementCache();
  
          assertEquals(0, dataSource.getCachedPreparedStatementCount());
      }
  }
  