/** * This is the JTA compliant version of the method. However, you had better * know that your XAResource and family are truly compliant implementations. * If they aren't then we may fail gracefully (e.g., some versions of Oracle * don't work with arbitrary Xid implementations!) * * If the family isn't compliant, then you should use the other method and * pass through a relevant XAModifier, which should address the issues we * have already come across. */ public boolean enlistResource(XAResource xaRes) throws RollbackException, IllegalStateException, javax.transaction.SystemException { return enlistResource(xaRes, null); }
@Test public void testThreadIsActive () throws Exception { ThreadActionData.purgeActions(); Class[] parameterTypes = new Class[1]; TransactionImple tx = new TransactionImple(0); tx.enlistResource(new RecoveryXAResource()); parameterTypes[0] = XAResource.class; Method m = tx.getClass().getDeclaredMethod("threadIsActive", parameterTypes); m.setAccessible(true); Object[] parameters = new Object[1]; parameters[0] = new RecoveryXAResource(); Boolean res = (Boolean) m.invoke(tx, parameters); assertFalse(res.booleanValue()); tx.rollback(); ThreadActionData.purgeActions(); }
@Test public void test() throws Exception { UserTransactionImple ut = new UserTransactionImple(); ut.begin(); TransactionImple current = TransactionImple.getTransaction(); TestResource res1, res2; current.enlistResource( res1 = new TestResource() ); current.enlistResource( res2 = new TestResource() ); current.delistResource( res2, XAResource.TMSUCCESS ); current.delistResource( res1, XAResource.TMSUCCESS ); Future<Void> commitAsync = ut.commitAsync(); commitAsync.get(); } }
private TransactionImple generateHeuristic(TransactionImple tx, FailureXAResource failureXAResource) throws Exception { ThreadActionData.purgeActions(); XAResource[] resources = { new DummyXA(false), failureXAResource }; // enlist the XA resources into the transaction for (XAResource resource : resources) tx.enlistResource(resource); try { tx.commit(); fail("Expected a mixed heuristic"); } catch (final HeuristicMixedException expected) { } return tx; }
@Test public void testCheckDeferredHeuristicRollbackSecondOfThreeFails() throws Exception { ThreadActionData.purgeActions(); TxControl.setXANodeName("test"); TransactionImple tx = new TransactionImple(500); try { tx.enlistResource(new TestResource()); tx.enlistResource(new FailureXAResource(FailLocation.commit, FailType.nota)); tx.enlistResource(new TestResource()); } catch (final RollbackException ex) { fail(); } try { tx.commit(); fail(); } catch (final HeuristicMixedException ex) { assertEquals(XAException.XAER_NOTA, ((XAException) ex.getSuppressed()[0]).errorCode); } }
@Test public void testCheckDeferredPrepareHeuristic() throws Exception { ThreadActionData.purgeActions(); TransactionImple tx = new TransactionImple(0); tx.enlistResource(new FailureXAResource()); try { tx.enlistResource(new FailureXAResource(FailLocation.prepare, FailType.XA_HEURHAZ)); } catch (final RollbackException ex) { fail(); } try { tx.commit(); fail(); } catch (final HeuristicMixedException ex) { assertEquals(XAException.XA_HEURHAZ, ((XAException) ex.getSuppressed()[0]).errorCode); } }
tx.enlistResource(null); tx.enlistResource(new DummyXA(false)); tx.enlistResource(new DummyXA(false));
@Test public void testCheckDeferredPrepareRollbackException () throws Exception { ThreadActionData.purgeActions(); TransactionImple tx = new TransactionImple(0); tx.enlistResource(new FailureXAResource()); try { tx.enlistResource(new FailureXAResource(FailLocation.prepare, FailType.rollback)); } catch (final RollbackException ex) { fail(); } try { tx.commit(); fail(); } catch (final RollbackException ex) { assertEquals(XAException.XAER_INVAL, ((XAException) ex.getSuppressed()[0]).errorCode); } }
@Test public void testRecoveryMonitorWithFailure() throws Exception { XATestResourceXARecovery.setUseFaultyResources(true); UserTransaction ut = com.arjuna.ats.jta.UserTransaction.userTransaction(); ut.begin(); TransactionImple tx = TransactionImple.getTransaction(); // enlist a resource that behaves correctly assertTrue(tx.enlistResource(new XATestResource(XATestResource.OK_JNDI_NAME, false))); // enlist a resource that throws an exception from recover assertTrue(tx.enlistResource(new XATestResource(XATestResource.FAULTY_JNDI_NAME, true))); ut.commit(); manager.scan(); assertTrue(jtaLogger.isRecoveryProblems()); }
@Test public void testCheckDeferredHeuristicRollbackFirstResourceFails() throws Exception { ThreadActionData.purgeActions(); TxControl.setXANodeName("test"); TransactionImple tx = new TransactionImple(500); try { tx.enlistResource(new FailureXAResource(FailLocation.commit, FailType.nota)); tx.enlistResource(new TestResource()); } catch (final RollbackException ex) { fail(); } try { tx.commit(); fail(); } catch (final HeuristicMixedException ex) { assertEquals(XAException.XAER_NOTA, ((XAException) ex.getSuppressed()[0]).errorCode); } }
@Test public void testCheckDeferredHeuristicRollbackSecondResourceFails() throws Exception { ThreadActionData.purgeActions(); TxControl.setXANodeName("test"); TransactionImple tx = new TransactionImple(500); try { tx.enlistResource(new TestResource()); tx.enlistResource(new FailureXAResource(FailLocation.commit, FailType.nota)); } catch (final RollbackException ex) { fail(); } try { tx.commit(); fail(); } catch (final HeuristicMixedException ex) { assertEquals(XAException.XAER_NOTA, ((XAException) ex.getSuppressed()[0]).errorCode); } }
@Test public void testCheckDeferredPrepareInitCause () throws Exception { ThreadActionData.purgeActions(); TransactionImple tx = new TransactionImple(0); tx.enlistResource(new FailureXAResource()); try { tx.enlistResource(new FailureXAResource(FailLocation.prepare, FailType.message)); } catch (final RollbackException ex) { fail(); } try { tx.commit(); fail(); } catch (final RollbackException ex) { assertEquals(XAException.XA_RBROLLBACK, ((XAException) ex.getSuppressed()[0]).errorCode); assertEquals("test message", ((XAException) ex.getSuppressed()[0]).getCause().getMessage()); } }
assertTrue(tx.enlistResource(dummy)); assertTrue(tx.enlistResource(dummy));
assertTrue(tx.enlistResource(new XATestResource(XATestResource.OK_JNDI_NAME, false))); assertTrue(tx.enlistResource(new XATestResource(XATestResource.FAULTY_JNDI_NAME, true)));
@Test public void testCheckDeferredHeuristicException () throws Exception { ThreadActionData.purgeActions(); TransactionImple tx = new TransactionImple(0); try { tx.enlistResource(new FailureXAResource(FailLocation.commit, FailType.normal)); } catch (final RollbackException ex) { fail(); } try { tx.commit(); fail(); } catch (final HeuristicMixedException ex) { assertEquals(XAException.XA_HEURMIX, ((XAException) ex.getSuppressed()[0]).errorCode); } }
@Test public void testCheckDeferredRollbackException () throws Exception { ThreadActionData.purgeActions(); TransactionImple tx = new TransactionImple(0); try { tx.enlistResource(new FailureXAResource(FailLocation.commit, FailType.rollback)); } catch (final RollbackException ex) { fail(); } try { tx.commit(); fail(); } catch (final RollbackException ex) { assertEquals(XAException.XA_HEURRB, ((XAException) ex.getSuppressed()[0]).errorCode); } }
tx.enlistResource(xares);
assertTrue(tx.equals(tx)); tx.enlistResource(new FailureXAResource(FailLocation.commit));