@After
  public void tearDown() throws Exception {
    int removeAllTasks = taskService.removeAllTasks();

    emf.close();
    ds.close();
  }
  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());
  }
Example #3
0
  /**
   * This method should be called in the @After method of a test to clean up the persistence unit
   * and datasource.
   *
   * @param context A HashMap generated by {@link org.drools.persistence.util.PersistenceUtil
   *     setupWithPoolingDataSource(String)}
   */
  public static void cleanUp(HashMap<String, Object> context) {
    if (context != null) {

      BitronixTransactionManager txm = TransactionManagerServices.getTransactionManager();
      if (txm != null) {
        txm.shutdown();
      }

      Object emfObject = context.remove(ENTITY_MANAGER_FACTORY);
      if (emfObject != null) {
        try {
          EntityManagerFactory emf = (EntityManagerFactory) emfObject;
          emf.close();
        } catch (Throwable t) {
          t.printStackTrace();
        }
      }

      Object ds1Object = context.remove(DATASOURCE);
      if (ds1Object != null) {
        try {
          PoolingDataSource ds1 = (PoolingDataSource) ds1Object;
          ds1.close();
        } catch (Throwable t) {
          t.printStackTrace();
        }
      }
    }
  }
 protected void onTearDown() throws Exception {
   taskSession.dispose();
   emfTaskJPA.close();
   if (useJTA) {
     ds.close();
   }
 }
 @After
 public void teardown() {
   if (manager != null) {
     manager.close();
   }
   pds.close();
 }
  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();
  }
Example #7
0
 protected void tearDown() throws Exception {
   if (taskSession != null) {
     taskSession.dispose();
   }
   emf.close();
   if (useJTA) {
     pds.close();
   }
 }
 @After
 public void tearDown() throws Exception {
   try {
     emf.close();
     ds1.close();
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
  public void testObjectProperties() throws Exception {
    pds.close();

    pds = new PoolingDataSource();
    pds.setUniqueName("pds");
    pds.setClassName(MockitoXADataSource.class.getName());
    pds.setMinPoolSize(1);
    pds.setMaxPoolSize(1);
    pds.getDriverProperties().put("uselessThing", new Object());
    pds.init();
  }
  @After
  public void tearDown() throws Exception {
    clearHistory();
    disposeRuntimeManager();

    if (emf != null) {
      emf.close();
      emf = null;
    }
    if (ds != null) {
      ds.close();
      ds = null;
    }
  }
Example #11
0
 @After
 public void tearDown() throws Exception {
   clearHistory();
   if (setupDataSource) {
     if (emf != null) {
       emf.close();
       emf = null;
     }
     if (ds != null) {
       ds.close();
       ds = null;
     }
   }
   if (!activeEngines.isEmpty()) {
     for (RuntimeEngine engine : activeEngines) {
       manager.disposeRuntimeEngine(engine);
     }
   }
   if (manager != null) {
     manager.close();
     manager = null;
   }
 }
 @After
 public void cleanup() {
   cleanDb();
   pds.close();
 }
Example #13
0
 @AfterClass
 public static void tearDown() {
   ds.close();
 }
  protected void tearDown() throws Exception {
    pds.close();

    TransactionManagerServices.getTransactionManager().shutdown();
  }
 protected void tearDown() throws Exception {
   poolingDataSource1.close();
   poolingDataSource2.close();
   btm.shutdown();
 }
 @After
 public void teardown() throws Throwable {
   emf.close();
   ds1.close();
 }
 @Override
 protected void tearDown() throws Exception {
   ds1.close();
 }