Exemplo n.º 1
0
  public void testInitFailure() throws Exception {
    if (log.isDebugEnabled()) {
      log.debug("*** Starting testInitFailure");
    }
    pds.close();

    pds = new PoolingDataSource();
    pds.setMinPoolSize(0);
    pds.setMaxPoolSize(2);
    pds.setMaxIdleTime(1);
    pds.setClassName(MockitoXADataSource.class.getName());
    pds.setUniqueName("pds");
    pds.setAllowLocalTransactions(true);
    pds.setAcquisitionTimeout(1);

    TransactionManagerServices.getTransactionManager().begin();

    MockitoXADataSource.setStaticGetXAConnectionException(new SQLException("not yet started"));
    try {
      pds.init();
      fail("expected ResourceConfigurationException");
    } catch (ResourceConfigurationException ex) {
      Throwable rootCause = ex.getCause().getCause();
      assertEquals(SQLException.class, rootCause.getClass());
      assertEquals("not yet started", rootCause.getMessage());
    }

    MockitoXADataSource.setStaticGetXAConnectionException(null);
    pds.init();

    pds.getConnection().prepareStatement("");

    TransactionManagerServices.getTransactionManager().commit();
  }
Exemplo n.º 2
0
  public void testPoolNotStartingTransactionManager() throws Exception {
    if (log.isDebugEnabled()) {
      log.debug("*** Starting testPoolNotStartingTransactionManager");
    }
    // make sure TM is not running
    TransactionManagerServices.getTransactionManager().shutdown();

    PoolingDataSource pds = new PoolingDataSource();
    pds.setMinPoolSize(1);
    pds.setMaxPoolSize(2);
    pds.setMaxIdleTime(1);
    pds.setClassName(MockitoXADataSource.class.getName());
    pds.setUniqueName("pds2");
    pds.setAllowLocalTransactions(true);
    pds.setAcquisitionTimeout(1);
    pds.init();

    assertFalse(TransactionManagerServices.isTransactionManagerRunning());

    Connection c = pds.getConnection();
    Statement stmt = c.createStatement();
    stmt.close();
    c.close();

    assertFalse(TransactionManagerServices.isTransactionManagerRunning());

    pds.close();

    assertFalse(TransactionManagerServices.isTransactionManagerRunning());
  }
Exemplo n.º 3
0
  protected void setUp() throws Exception {
    TransactionManagerServices.getConfiguration().setJournal("null").setGracefulShutdownInterval(2);
    TransactionManagerServices.getTransactionManager();

    MockitoXADataSource.setStaticCloseXAConnectionException(null);
    MockitoXADataSource.setStaticGetXAConnectionException(null);

    pds = new PoolingDataSource();
    pds.setMinPoolSize(1);
    pds.setMaxPoolSize(2);
    pds.setMaxIdleTime(1);
    pds.setClassName(MockitoXADataSource.class.getName());
    pds.setUniqueName("pds");
    pds.setAllowLocalTransactions(true);
    pds.setAcquisitionTimeout(1);
    pds.init();
  }