use of com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple in project narayana by jbosstm.
the class XAResourceRecordUnitTest method test.
@Test
public void test() throws Exception {
XAResourceRecord xares = new XAResourceRecord();
Object obj = new Object();
xares.setValue(obj);
assertTrue(xares.value() != obj);
DummyRecoverableXAConnection rc = new DummyRecoverableXAConnection();
Object[] params = new Object[1];
params[XAResourceRecord.XACONNECTION] = rc;
xares = new XAResourceRecord(new TransactionImple(0), new DummyXA(false), new XidImple(new Uid()), params);
assertTrue(xares.type() != null);
xares.merge(xares);
xares.replace(xares);
assertTrue(xares.toString() != null);
}
use of com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple in project narayana by jbosstm.
the class XAResourceRecordUnitTest method testReadonly.
@Test
public void testReadonly() throws Exception {
XAResourceRecord xares;
DummyRecoverableXAConnection rc = new DummyRecoverableXAConnection();
Object[] params = new Object[1];
params[XAResourceRecord.XACONNECTION] = rc;
xares = new XAResourceRecord(new TransactionImple(0), new TestResource(true), new XidImple(new Uid()), params);
assertEquals(xares.topLevelCommit(), TwoPhaseOutcome.NOT_PREPARED);
assertEquals(xares.topLevelPrepare(), TwoPhaseOutcome.PREPARE_READONLY);
}
use of com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple in project narayana by jbosstm.
the class TestCommitMarkableResourceReturnUnknownOutcomeFrom1PCCommit method testRMFAILAfterCommit.
@Test
public void testRMFAILAfterCommit() throws Exception {
jtaPropertyManager.getJTAEnvironmentBean().setNotifyCommitMarkableResourceRecoveryModuleOfCompleteBranches(false);
final JdbcDataSource dataSource = new JdbcDataSource();
dataSource.setURL("jdbc:h2:mem:JBTMDB;MVCC=TRUE;DB_CLOSE_DELAY=-1");
// Test code
Utils.createTables(dataSource.getConnection());
// We can't just instantiate one as we need to be using the
// same one as
// the transaction
// manager would have used to mark the transaction for GC
CommitMarkableResourceRecordRecoveryModule commitMarkableResourceRecoveryModule = null;
Vector recoveryModules = manager.getModules();
if (recoveryModules != null) {
Enumeration modules = recoveryModules.elements();
while (modules.hasMoreElements()) {
RecoveryModule m = (RecoveryModule) modules.nextElement();
if (m instanceof CommitMarkableResourceRecordRecoveryModule) {
commitMarkableResourceRecoveryModule = (CommitMarkableResourceRecordRecoveryModule) m;
} else if (m instanceof XARecoveryModule) {
XARecoveryModule xarm = (XARecoveryModule) m;
xarm.addXAResourceRecoveryHelper(new XAResourceRecoveryHelper() {
public boolean initialise(String p) throws Exception {
return true;
}
public XAResource[] getXAResources() throws Exception {
return new XAResource[] { xaResource };
}
});
}
}
}
javax.transaction.TransactionManager tm = com.arjuna.ats.jta.TransactionManager.transactionManager();
tm.begin();
Uid get_uid = ((TransactionImple) tm.getTransaction()).get_uid();
Connection localJDBCConnection = dataSource.getConnection();
localJDBCConnection.setAutoCommit(false);
nonXAResource = new JDBCConnectableResource(localJDBCConnection) {
@Override
public void commit(Xid arg0, boolean arg1) throws XAException {
super.commit(arg0, arg1);
throw new XAException(XAException.XAER_RMFAIL);
}
};
tm.getTransaction().enlistResource(nonXAResource);
xaResource = new SimpleXAResource();
tm.getTransaction().enlistResource(xaResource);
localJDBCConnection.createStatement().execute("INSERT INTO foo (bar) VALUES (1)");
tm.commit();
assertTrue(xaResource.wasCommitted());
Xid committed = ((JDBCConnectableResource) nonXAResource).getStartedXid();
assertNotNull(committed);
InputObjectState uids = new InputObjectState();
StoreManager.getRecoveryStore().allObjUids(new AtomicAction().type(), uids);
Uid uid = UidHelper.unpackFrom(uids);
assertTrue(uid.equals(get_uid));
// Belt and braces but we don't expect the CMR to be removed anyway as
// the RM is "offline"
manager.scan();
manager.scan();
// The recovery module has to perform lookups
new InitialContext().rebind("commitmarkableresource", dataSource);
assertTrue(commitMarkableResourceRecoveryModule.wasCommitted("commitmarkableresource", committed));
// This will complete the atomicaction
manager.scan();
StoreManager.getRecoveryStore().allObjUids(new AtomicAction().type(), uids);
uid = UidHelper.unpackFrom(uids);
assertTrue(uid.equals(Uid.nullUid()));
// This is when the CMR deletes are done due to ordering
manager.scan();
// of the recovery modules
assertFalse(commitMarkableResourceRecoveryModule.wasCommitted("commitmarkableresource", committed));
}
use of com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple in project narayana by jbosstm.
the class ExceptionDeferrerTest method testCheckDeferredHeuristicException.
@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);
}
}
use of com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple in project narayana by jbosstm.
the class ExceptionDeferrerTest method testCheckDeferredHeuristicRollbackSecondResourceFails.
@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);
}
}
Aggregations