public void testPoolShrinkErrorHandling() throws Exception {
    if (log.isDebugEnabled()) {
      log.debug("*** Starting testPoolShrinkErrorHandling");
    }

    Field poolField = pds.getClass().getDeclaredField("pool");
    poolField.setAccessible(true);
    XAPool pool = (XAPool) poolField.get(pds);

    pds.setMinPoolSize(0);
    pds.reset();
    pds.setMinPoolSize(1);
    MockitoXADataSource.setStaticCloseXAConnectionException(
        new SQLException("close fails because datasource broken"));
    pds.reset();

    // the pool is now loaded with one connection which will throw an exception when closed
    Thread.sleep(1100); // leave enough time for the ide connections to expire
    TransactionManagerServices.getTaskScheduler().interrupt(); // wake up the task scheduler
    Thread.sleep(100); // leave enough time for the scheduled shrinking task to do its work
    assertEquals(1, pool.inPoolSize());

    MockitoXADataSource.setStaticGetXAConnectionException(
        new SQLException("getXAConnection fails because datasource broken"));
    Thread.sleep(1100); // leave enough time for the ide connections to expire
    TransactionManagerServices.getTaskScheduler().interrupt(); // wake up the task scheduler
    Thread.sleep(100); // leave enough time for the scheduled shrinking task to do its work
    assertEquals(0, pool.inPoolSize());

    MockitoXADataSource.setStaticGetXAConnectionException(null);
    Thread.sleep(1100); // leave enough time for the ide connections to expire
    TransactionManagerServices.getTaskScheduler().interrupt(); // wake up the task scheduler
    Thread.sleep(100); // leave enough time for the scheduled shrinking task to do its work
    assertEquals(1, pool.inPoolSize());
  }
  public void testPoolShrink() throws Exception {
    if (log.isDebugEnabled()) {
      log.debug("*** Starting testPoolShrink");
    }
    Field poolField = pds.getClass().getDeclaredField("pool");
    poolField.setAccessible(true);
    XAPool pool = (XAPool) poolField.get(pds);

    assertEquals(1, pool.inPoolSize());
    assertEquals(1, pool.totalPoolSize());

    Connection c1 = pds.getConnection();
    assertEquals(0, pool.inPoolSize());
    assertEquals(1, pool.totalPoolSize());

    Connection c2 = pds.getConnection();
    assertEquals(0, pool.inPoolSize());
    assertEquals(2, pool.totalPoolSize());

    c1.close();
    c2.close();

    Thread.sleep(1100); // leave enough time for the idle connections to expire
    TransactionManagerServices.getTaskScheduler().interrupt(); // wake up the task scheduler
    Thread.sleep(1200); // leave enough time for the scheduled shrinking task to do its work

    if (log.isDebugEnabled()) {
      log.debug("*** checking pool sizes");
    }
    assertEquals(1, pool.inPoolSize());
    assertEquals(1, pool.totalPoolSize());
  }