use of com.arjuna.ats.internal.jta.transaction.arjunacore.jca.XATerminatorImple in project narayana by jbosstm.
the class XATerminatorUnitTest method testInvalid.
@Test
public void testInvalid() throws Exception {
XATerminatorImple term = new XATerminatorImple();
XidImple xid = new XidImple(new Uid());
try {
SubordinationManager.getTransactionImporter().importTransaction(null);
fail();
} catch (final IllegalArgumentException ex) {
}
try {
SubordinationManager.getTransactionImporter().recoverTransaction(null);
fail();
} catch (final IllegalArgumentException ex) {
}
try {
SubordinationManager.getTransactionImporter().getImportedTransaction(null);
fail();
} catch (final IllegalArgumentException ex) {
}
try {
SubordinationManager.getTransactionImporter().removeImportedTransaction(null);
fail();
} catch (final IllegalArgumentException ex) {
}
Uid uid = new Uid();
try {
Object obj = SubordinationManager.getTransactionImporter().recoverTransaction(uid);
fail();
} catch (IllegalArgumentException ex) {
}
}
use of com.arjuna.ats.internal.jta.transaction.arjunacore.jca.XATerminatorImple in project narayana by jbosstm.
the class XATerminatorUnitTest method testCommitMid.
@Test
public void testCommitMid() throws Exception {
TransactionManagerImple tm = new TransactionManagerImple();
RecordTypeManager.manager().add(new RecordTypeMap() {
@SuppressWarnings("unchecked")
public Class getRecordClass() {
return XAResourceRecord.class;
}
public int getType() {
return RecordType.JTA_RECORD;
}
});
XATerminatorImple xaTerminator = new XATerminatorImple();
XidImple xid = new XidImple(new Uid());
XAResourceImple toCommit = new XAResourceImple(XAResource.XA_OK, XAResource.XA_OK);
{
SubordinateTransaction subordinateTransaction = SubordinationManager.getTransactionImporter().importTransaction(xid);
tm.resume(subordinateTransaction);
subordinateTransaction.enlistResource(new XAResourceImple(XAResource.XA_RDONLY, XAResource.XA_OK));
subordinateTransaction.enlistResource(toCommit);
Transaction suspend = tm.suspend();
}
{
SubordinateTransaction subordinateTransaction = SubordinationManager.getTransactionImporter().getImportedTransaction(xid);
tm.resume(subordinateTransaction);
subordinateTransaction.doPrepare();
Transaction suspend = tm.suspend();
}
XARecoveryModule xaRecoveryModule = new XARecoveryModule();
xaRecoveryModule.addXAResourceRecoveryHelper(new XAResourceRecoveryHelper() {
@Override
public boolean initialise(String p) throws Exception {
return false;
}
@Override
public XAResource[] getXAResources() throws Exception {
return new XAResource[] { toCommit };
}
});
RecoveryManager.manager().addModule(xaRecoveryModule);
xaTerminator.doRecover(null, null);
{
SubordinateTransaction subordinateTransaction = SubordinationManager.getTransactionImporter().getImportedTransaction(xid);
tm.resume(subordinateTransaction);
subordinateTransaction.doCommit();
tm.suspend();
}
RecoveryManager.manager().removeModule(xaRecoveryModule, false);
assertTrue(toCommit.wasCommitted());
SubordinationManager.getTransactionImporter().removeImportedTransaction(xid);
}
Aggregations