use of com.arjuna.wst.TransactionRolledBackException in project narayana by jbosstm.
the class SubtransactionCommitRollbackInPrepareTest method testSubTransactionCommitRollbackInPrepare.
@Test
public void testSubTransactionCommitRollbackInPrepare() throws Exception {
final UserTransaction ut = UserTransactionFactory.userTransaction();
final UserTransaction ust = UserTransactionFactory.userSubordinateTransaction();
final TransactionManager tm = TransactionManager.getTransactionManager();
final DemoDurableParticipant p1 = new DemoDurableParticipant();
final DemoVolatileParticipant p2 = new DemoVolatileParticipant();
final FailureParticipant p3 = new FailureParticipant(FailureParticipant.FAIL_IN_PREPARE, FailureParticipant.NONE);
final DemoVolatileParticipant p4 = new DemoVolatileParticipant();
ut.begin();
final TxContext tx = tm.suspend();
tm.resume(tx);
tm.enlistForDurableTwoPhase(p1, p1.identifier());
tm.enlistForVolatileTwoPhase(p2, p2.identifier());
ust.begin();
final TxContext stx = tm.suspend();
tm.resume(stx);
tm.enlistForDurableTwoPhase(p3, "failure in prepare");
tm.enlistForVolatileTwoPhase(p4, p4.identifier());
tm.resume(tx);
try {
ut.commit();
fail("expecting TransactionRolledBackException");
} catch (TransactionRolledBackException trbe) {
// expect this
}
assertTrue(p1.prepared() && p1.resolved() && !p1.passed());
assertTrue(p2.prepared() && p2.resolved() && !p2.passed());
assertTrue(!p3.passed());
assertTrue(p4.prepared() && p4.resolved() && !p4.passed());
}
use of com.arjuna.wst.TransactionRolledBackException in project narayana by jbosstm.
the class SubtransactionCommitFailInPrepareTest method testSubTransactionCommitFailInPrepare.
@Test
public void testSubTransactionCommitFailInPrepare() throws Exception {
final UserTransaction ut = UserTransactionFactory.userTransaction();
final UserTransaction ust = UserTransactionFactory.userSubordinateTransaction();
final TransactionManager tm = TransactionManager.getTransactionManager();
final DemoDurableParticipant p1 = new DemoDurableParticipant();
final DemoVolatileParticipant p2 = new DemoVolatileParticipant();
final FailureParticipant p3 = new FailureParticipant(FailureParticipant.FAIL_IN_PREPARE, FailureParticipant.WRONG_STATE);
final DemoVolatileParticipant p4 = new DemoVolatileParticipant();
ut.begin();
final TxContext tx = tm.suspend();
tm.resume(tx);
tm.enlistForDurableTwoPhase(p1, p1.identifier());
tm.enlistForVolatileTwoPhase(p2, p2.identifier());
ust.begin();
final TxContext stx = tm.suspend();
tm.resume(stx);
tm.enlistForDurableTwoPhase(p3, "failure in prepare");
tm.enlistForVolatileTwoPhase(p4, p4.identifier());
tm.resume(tx);
try {
ut.commit();
fail("expecting TransactionRolledBackException");
} catch (TransactionRolledBackException wse) {
// expect this
}
assertTrue(p1.prepared() && p1.resolved() && !p1.passed());
assertTrue(p2.prepared() && p2.resolved() && !p2.passed());
assertTrue(!p3.passed());
assertTrue(p4.prepared() && p4.resolved() && !p4.passed());
}
use of com.arjuna.wst.TransactionRolledBackException in project narayana by jbosstm.
the class CompletionCoordinatorProcessorImpl method commit.
/**
* Commit.
* @param commit The commit notification.
* @param map The addressing context.
* @param arjunaContext The arjuna context.
*/
public void commit(final Notification commit, final MAP map, final ArjunaContext arjunaContext) {
final InstanceIdentifier instanceIdentifier = arjunaContext.getInstanceIdentifier();
final CompletionCoordinatorParticipant participant = getParticipant(instanceIdentifier);
try {
if (participant != null) {
final String messageId = MessageId.getMessageId();
try {
participant.commit();
} catch (final TransactionRolledBackException trbe) {
final MAP responseAddressingContext = AddressingHelper.createResponseContext(map, messageId);
CompletionInitiatorClient.getClient().sendAborted(participant.getParticipant(), responseAddressingContext, instanceIdentifier);
return;
} catch (final UnknownTransactionException ute) {
final MAP faultAddressingContext = AddressingHelper.createFaultContext(map, messageId);
final SoapFault soapFault = new SoapFault11(SoapFaultType.FAULT_SENDER, ArjunaTXConstants.UNKNOWNTRANSACTION_ERROR_CODE_QNAME, WSTLogger.i18NLogger.get_wst11_messaging_CompletionCoordinatorProcessorImpl_1());
CompletionInitiatorClient.getClient().sendSoapFault(participant.getParticipant(), faultAddressingContext, soapFault, instanceIdentifier);
return;
} catch (final SystemException se) {
final MAP faultAddressingContext = AddressingHelper.createFaultContext(map, messageId);
final String pattern = WSTLogger.i18NLogger.get_wst11_messaging_CompletionCoordinatorProcessorImpl_2();
final String message = MessageFormat.format(pattern, new Object[] { se });
final SoapFault soapFault = new SoapFault11(SoapFaultType.FAULT_SENDER, ArjunaTXConstants.UNKNOWNERROR_ERROR_CODE_QNAME, message);
CompletionInitiatorClient.getClient().sendSoapFault(participant.getParticipant(), faultAddressingContext, soapFault, instanceIdentifier);
return;
} catch (final Throwable th) {
if (WSTLogger.logger.isTraceEnabled()) {
WSTLogger.logger.tracev("Unexpected exception thrown from commit:", th);
}
final MAP faultAddressingContext = AddressingHelper.createFaultContext(map, MessageId.getMessageId());
final SoapFault soapFault = new SoapFault11(th);
CompletionInitiatorClient.getClient().sendSoapFault(participant.getParticipant(), faultAddressingContext, soapFault, instanceIdentifier);
return;
}
final MAP responseAddressingContext = AddressingHelper.createResponseContext(map, messageId);
CompletionInitiatorClient.getClient().sendCommitted(participant.getParticipant(), responseAddressingContext, instanceIdentifier);
} else {
if (WSTLogger.logger.isTraceEnabled()) {
WSTLogger.logger.tracev("Commit called on unknown participant: {0}", new Object[] { instanceIdentifier });
}
final MAP faultAddressingContext = AddressingHelper.createFaultContext(map, MessageId.getMessageId());
final SoapFault soapFault = new SoapFault11(SoapFaultType.FAULT_SENDER, ArjunaTXConstants.UNKNOWNTRANSACTION_ERROR_CODE_QNAME, WSTLogger.i18NLogger.get_wst11_messaging_CompletionCoordinatorProcessorImpl_5());
CompletionInitiatorClient.getClient().sendSoapFault(faultAddressingContext, soapFault, instanceIdentifier);
}
} catch (Throwable throwable) {
throwable.printStackTrace(System.err);
}
}
use of com.arjuna.wst.TransactionRolledBackException in project narayana by jbosstm.
the class BusinessActivityTerminatorStub method close.
public void close() throws TransactionRolledBackException, UnknownTransactionException, SystemException {
final MAP map = AddressingHelper.createNotificationContext(MessageId.getMessageId());
final RequestCallback callback = new RequestCallback();
final TerminationParticipantProcessor terminationParticipantProcessor = TerminationParticipantProcessor.getProcessor();
terminationParticipantProcessor.registerCallback(_id, callback);
try {
TerminationCoordinatorClient.getClient().sendClose(_terminationCoordinator, map, new InstanceIdentifier(_id));
callback.waitUntilTriggered();
} catch (final Throwable th) {
throw new SystemException();
} finally {
terminationParticipantProcessor.removeCallback(_id);
}
if (callback.hasTriggered()) {
if (callback.receivedClosed()) {
return;
}
final SoapFault soapFault = callback.getSoapFault();
if (soapFault != null) {
final QName subcode = soapFault.getSubcode();
if (ArjunaTXConstants.TRANSACTIONROLLEDBACK_ERROR_CODE_QNAME.equals(subcode)) {
throw new TransactionRolledBackException();
} else if (ArjunaTXConstants.UNKNOWNTRANSACTION_ERROR_CODE_QNAME.equals(subcode)) {
throw new UnknownTransactionException();
}
}
}
throw new SystemException();
}
use of com.arjuna.wst.TransactionRolledBackException in project narayana by jbosstm.
the class CompletionStub method commit.
public void commit() throws TransactionRolledBackException, UnknownTransactionException, SystemException {
final MAP map = AddressingHelper.createNotificationContext(MessageId.getMessageId());
final CompletionStub.RequestCallback callback = new CompletionStub.RequestCallback();
final CompletionInitiatorProcessor completionInitiator = CompletionInitiatorProcessor.getProcessor();
completionInitiator.registerCallback(_id, callback);
try {
CompletionCoordinatorClient.getClient().sendCommit(_completionCoordinator, map, new InstanceIdentifier(_id));
callback.waitUntilTriggered();
} catch (final Throwable th) {
th.printStackTrace();
throw new SystemException();
} finally {
completionInitiator.removeCallback(_id);
}
if (callback.hasTriggered()) {
if (callback.receivedCommitted()) {
return;
} else if (callback.receivedAborted()) {
throw new TransactionRolledBackException();
}
final SoapFault soapFault = callback.getSoapFault();
if ((soapFault != null) && ArjunaTXConstants.UNKNOWNTRANSACTION_ERROR_CODE_QNAME.equals(soapFault.getSubcode())) {
throw new UnknownTransactionException();
}
}
throw new SystemException();
}
Aggregations