@Override public void doBeforeTransactionCompletion(SessionImplementor session) { try { // Wait for the transaction to be rolled back by the Reaper thread. final Transaction transaction = TestingJtaPlatformImpl.transactionManager().getTransaction(); while ( transaction.getStatus() != Status.STATUS_ROLLEDBACK ) Thread.sleep( 10 ); } catch ( Exception e ) { // we aren't concerned with this. } } }
@Override public TransactionBatch createBatch() { if (this.tm == null) return NON_TX_BATCH; TransactionBatch batch = getCurrentBatch(); try { if ((batch != null) && (batch.getState() == Batch.State.ACTIVE)) { return batch.interpose(); } this.tm.suspend(); this.tm.begin(); Transaction tx = this.tm.getTransaction(); tx.registerSynchronization(CURRENT_BATCH_SYNCHRONIZATION); batch = new InfinispanBatch(tx); setCurrentBatch(batch); return batch; } catch (RollbackException | SystemException | NotSupportedException e) { throw new CacheException(e); } }
@After public void tearDown() throws Exception { javax.transaction.TransactionManager txm = com.arjuna.ats.jta.TransactionManager.transactionManager(); assertTrue("There is still a transaction running!", txm.getTransaction() == null ); cleanUp(context); }
@Test public void testTxManagerCommitDissassociatesThread() throws Exception { // don't wait for ages, has to be set before TX is begun tm.setTransactionTimeout(TRANSACTION_TIMEOUT_SECONDS); tm.begin(); Transaction tx = tm.getTransaction(); assertNotNull("Transaction should have started.", tx); assertEquals("TX should have been active", Status.STATUS_ACTIVE, tx.getStatus()); tm.commit(); assertNull("Committing via TX Manager should have disassociated TX from the current thread.", tm.getTransaction()); }
@Override public Void doWork(Void context, int batchSize, Measurement<Void> measurement) { for (int i = 0; i < batchSize; i++) { try { tm.begin(); tm.getTransaction().enlistResource(new SampleOnePhaseResource(ErrorType.none, false)); tm.commit(); } catch (Exception e) { if (measurement.getNumberOfErrors() == 0) e.printStackTrace(); measurement.incrementErrorCount(); } } return context; }
@Test public void testTxManagerRollbackDissassociatesThread() throws Exception { // don't wait for ages, has to be set before TX is begun tm.setTransactionTimeout(TRANSACTION_TIMEOUT_SECONDS); tm.begin(); Transaction tx = tm.getTransaction(); assertNotNull("Transaction should have started.", tx); assertEquals("TX should have been active", Status.STATUS_ACTIVE, tx.getStatus()); tm.rollback(); assertNull("Committing via TX Manager should have disassociated TX from the current thread.", tm.getTransaction()); }
protected void endTransaction(TransactionManager tm, Transaction tx) throws Exception { if (tx != tm.getTransaction()) { throw new RuntimeException(jtaLogger.i18NLogger.get_wrong_tx_on_thread()); } if (tx.getStatus() == Status.STATUS_MARKED_ROLLBACK) { tm.rollback(); } else { tm.commit(); } }
/** * @see javax.transaction.UserTransaction#commit */ public void commit() throws HeuristicMixedException, HeuristicRollbackException, IllegalStateException, RollbackException, SecurityException, SystemException { int flag = XAResource.TMSUCCESS; tm.getTransaction().delistResource(XARes, flag); tm.commit(); }
@Test public void test() throws Exception { for (int i = 0; i < 1000; i++) { javax.transaction.TransactionManager tm = com.arjuna.ats.jta.TransactionManager.transactionManager(); tm.begin(); tm.getTransaction().rollback(); tm.suspend(); } } }
Transaction tx = com.arjuna.ats.jta.TransactionManager.transactionManager() .getTransaction(); if (tx != null) { int testTxState = tx.getStatus(); if (testTxState != Status.STATUS_NO_TRANSACTION && testTxState != Status.STATUS_ROLLEDBACK
@Test public void testTxManagerCommitDissassociatesThread() throws Exception { // don't wait for ages, has to be set before TX is begun tm.setTransactionTimeout(TRANSACTION_TIMEOUT_SECONDS); tm.begin(); Transaction tx = tm.getTransaction(); assertNotNull("Transaction should have started.", tx); assertEquals("TX should have been active", Status.STATUS_ACTIVE, tx.getStatus()); tm.commit(); assertNull("Committing via TX Manager should have disassociated TX from the current thread.", tm.getTransaction()); }
@Override public Void doWork(Void context, int batchSize, Measurement<Void> measurement) { for (int i = 0; i < batchSize; i++) { try { tm.begin(); tm.getTransaction().enlistResource(new SampleOnePhaseResource(ErrorType.none, false)); tm.commit(); } catch (Exception e) { if (measurement.getNumberOfErrors() == 0) e.printStackTrace(); measurement.incrementErrorCount(); } } return context; }
@Test public void testCreateThenDrop() throws Exception { URL persistenceXmlUrl = Thread.currentThread().getContextClassLoader().getResource( PERSISTENCE_XML_RESOURCE_NAME ); if ( persistenceXmlUrl == null ) { persistenceXmlUrl = Thread.currentThread().getContextClassLoader().getResource( '/' + PERSISTENCE_XML_RESOURCE_NAME ); } assertNotNull( persistenceXmlUrl ); ParsedPersistenceXmlDescriptor persistenceUnit = PersistenceXmlParser.locateIndividualPersistenceUnit( persistenceXmlUrl ); // creating the EMF causes SchemaCreator to be run... EntityManagerFactory emf = Bootstrap.getEntityManagerFactoryBuilder( persistenceUnit, Collections.emptyMap() ).build(); // closing the EMF causes the delayed SchemaDropper to be run... // wrap in a transaction just to see if we can get this to fail in the way the WF report says; // in my experience however this succeeds with or without the transaction final TransactionManager tm = emf.unwrap( SessionFactoryImplementor.class ).getServiceRegistry().getService( JtaPlatform.class ).retrieveTransactionManager(); tm.begin(); Transaction txn = tm.getTransaction(); emf.close(); txn.commit(); } }
if(transactionManager != null) { try { final Transaction transactionOnReset = transactionManager.getTransaction(); if(transactionOnReset != null && !transactionOnReset.equals(transactionOnSetup)) { switch (transactionOnReset.getStatus()) { case Status.STATUS_ACTIVE: case Status.STATUS_COMMITTING:
@Test public void testTxHandleCommitKeepsThreadAssociation() throws Exception { // don't wait for ages, has to be set before TX is begun tm.setTransactionTimeout(TRANSACTION_TIMEOUT_SECONDS); tm.begin(); Transaction tx = tm.getTransaction(); assertNotNull("Transaction should have started.", tx); assertEquals("TX should have been active", Status.STATUS_ACTIVE, tx.getStatus()); tx.commit(); tx = tm.getTransaction(); assertNotNull("Committing via TX handle should NOT disassociated TX from the current thread.", tx); assertEquals("TX status should have been COMMITTED.", Status.STATUS_COMMITTED, tx.getStatus()); // Remove the TX-thread association. The only public API to achieve it is suspend(), // technically we never resume the same transaction (TX forget). Transaction suspended = tm.suspend(); assertTrue("Wrong TX suspended?.", suspended.equals(tx)); assertNull("TX should've been disassociated from the thread.", tm.getTransaction()); // should be no-op and never fail tm.resume(null); // ensure we don't have any TX-Thread association lurking around a main thread assertNull(tm.getTransaction()); }
protected void endTransaction(TransactionManager tm, Transaction tx) throws Exception { if (tx != tm.getTransaction()) { throw new RuntimeException(jtaLogger.i18NLogger.get_wrong_tx_on_thread()); } if (tx.getStatus() == Status.STATUS_MARKED_ROLLBACK) { tm.rollback(); } else { tm.commit(); } }
@After public void tearDown() throws Exception { javax.transaction.TransactionManager txm = com.arjuna.ats.jta.TransactionManager.transactionManager(); assertTrue("There is still a transaction running!", txm.getTransaction() == null ); cleanUp(context); logService.dispose(); }
public void commit() throws RollbackException, HeuristicMixedException, HeuristicRollbackException, SecurityException, IllegalStateException, SystemException { Transaction tx = tm.getTransaction(); if (log.isDebugEnabled()) log.debug("UserTx commit: " + tx); tm.commit(); }
@Test public void test() throws Exception { TransactionManager tm = com.arjuna.ats.jta.TransactionManager.transactionManager(); tm.begin(); Transaction tx = tm.getTransaction(); tx.commit(); assertEquals(Status.STATUS_COMMITTED, tm.getStatus()); try { tm.begin(); fail("Begin call completed successfully - this shouldn't have happened"); } catch (NotSupportedException e) { System.out.println("NotSupportedException \""+e.getMessage()+"\" occurred this is expected and correct"); } } }
@Test public void test() throws Exception { javax.transaction.TransactionManager tm = com.arjuna.ats.jta.TransactionManager.transactionManager(); tm.begin(); javax.transaction.Transaction theTransaction = tm.getTransaction(); tm.commit(); tm.resume(theTransaction); } }