Пример #1
0
  public void testPoolResetErrorHandling() throws Exception {
    if (log.isDebugEnabled()) {
      log.debug("*** Starting testPoolResetErrorHandling");
    }
    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
    pds.reset();

    try {
      MockitoXADataSource.setStaticGetXAConnectionException(
          new SQLException("getXAConnection fails because datasource broken"));
      pds.reset();
      fail("expected SQLException");
    } catch (SQLException ex) {
      assertEquals("getXAConnection fails because datasource broken", ex.getMessage());
      assertEquals(0, pool.inPoolSize());
    }

    MockitoXADataSource.setStaticGetXAConnectionException(null);
    pds.reset();
    assertEquals(1, pool.inPoolSize());
  }
Пример #2
0
  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());
  }
Пример #3
0
  public void testPoolReset() throws Exception {
    if (log.isDebugEnabled()) {
      log.debug("*** Starting testPoolReset");
    }

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

    pds.reset();

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