Ejemplo n.º 1
0
  public void test_f() throws Exception {
    final DruidDataSource dataSource = new DruidDataSource();
    dataSource.setTimeBetweenConnectErrorMillis(100);

    final long startTime = System.currentTimeMillis();
    final long okTime = startTime + 1000 * 1;

    dataSource.setDriver(
        new MockDriver() {

          @Override
          public Connection connect(String url, Properties info) throws SQLException {
            if (System.currentTimeMillis() < okTime) {
              throw new SQLException();
            }

            return super.connect(url, info);
          }
        });
    dataSource.setUrl("jdbc:mock:");

    dataSource.setMinIdle(0);
    dataSource.setMaxActive(2);
    dataSource.setMaxIdle(2);

    Connection conn = dataSource.getConnection();
    conn.close();

    dataSource.close();
  }
Ejemplo n.º 2
0
 /** 关闭所有连接池 */
 public static synchronized void closeAll() {
   Collection<DruidDataSource> values = dsMap.values();
   for (DruidDataSource dds : values) {
     if (dds != null) {
       dds.close();
     }
   }
   dsMap.clear();
   SSHUtil.closeAll();
 }
Ejemplo n.º 3
0
 /** 注销 */
 @Override
 public void unInitialize() {
   try {
     if (dataSource != null) dataSource.close();
   } catch (Exception e) {
     throw new JdbcException(String.format("DruidSessionMgr uninitialize fail (%s)", e));
   } finally {
     super.unInitialize();
   }
 }
Ejemplo n.º 4
0
  protected void tearDown() throws Exception {
    try {
      dropTable();
    } catch (SQLException e) {
      e.printStackTrace();
    }

    if (dataSource != null) {
      dataSource.close();
    }
  }
 @Override
 public boolean destroyDataSource(DataSource datasource) {
   if (datasource != null && datasource instanceof DruidDataSource) {
     try {
       ((DruidDataSource) datasource).close();
       return true;
     } catch (Throwable ex) {
       log.error("close datasource error : ", ex);
     }
   }
   return false;
 }
Ejemplo n.º 6
0
 /**
  * ***************************************
  * <li>描 述:关闭 <br>
  * <li>时 间:2013-12-16 上午11:10:22 <br>
  * <li>参数: <br>
  *     ***************************************
  */
 public void destroy() {
   druidDataSource.close();
 }
 protected void tearDown() throws Exception {
   dataSource.close();
   Assert.assertEquals(0, DruidDataSourceStatManager.getInstance().getDataSourceList().size());
 }
  protected void tearDown() throws Exception {
    dataSource.close();

    System.clearProperty("druid.mysql.usePingMethod");
  }
 protected void tearDown() throws Exception {
   dataSource.close();
 }