Search in sources :

Example 11 with BusinessActivityManager

use of com.arjuna.mw.wst11.BusinessActivityManager in project narayana by jbosstm.

the class MultiCancelTest method testMultiCancel.

@Test
public void testMultiCancel() throws Exception {
    UserBusinessActivity uba = UserBusinessActivity.getUserBusinessActivity();
    BusinessActivityManager bam = BusinessActivityManager.getBusinessActivityManager();
    DemoBusinessParticipant p = new DemoBusinessParticipant(DemoBusinessParticipant.CANCEL, "1239");
    FailureBusinessParticipant fp = new FailureBusinessParticipant(FailureBusinessParticipant.FAIL_IN_CANCEL, "5678");
    try {
        uba.begin();
        bam.enlistForBusinessAgreementWithParticipantCompletion(p, "1239");
        bam.enlistForBusinessAgreementWithParticipantCompletion(fp, "5678");
    } catch (Exception eouter) {
        try {
            uba.cancel();
        } catch (Exception einner) {
        }
        throw eouter;
    }
    try {
        uba.cancel();
    } catch (SystemException ex) {
        // failure will result in heuristic hazard warning message but wil not throw an exception
        throw ex;
    } catch (Exception eouter) {
        try {
            uba.cancel();
        } catch (Exception einner) {
        }
        throw eouter;
    }
    assertTrue(p.passed());
}
Also used : DemoBusinessParticipant(com.arjuna.wstx.tests.common.DemoBusinessParticipant) SystemException(com.arjuna.wst.SystemException) BusinessActivityManager(com.arjuna.mw.wst11.BusinessActivityManager) UserBusinessActivity(com.arjuna.mw.wst11.UserBusinessActivity) FailureBusinessParticipant(com.arjuna.wstx.tests.common.FailureBusinessParticipant) SystemException(com.arjuna.wst.SystemException) Test(org.junit.Test)

Example 12 with BusinessActivityManager

use of com.arjuna.mw.wst11.BusinessActivityManager in project narayana by jbosstm.

the class MultiCompensateTest method testMultiCompensate.

@Test
public void testMultiCompensate() throws Exception {
    ParticipantCompletionCoordinatorRules.setParticipantCount(2);
    UserBusinessActivity uba = UserBusinessActivity.getUserBusinessActivity();
    BusinessActivityManager bam = BusinessActivityManager.getBusinessActivityManager();
    com.arjuna.wst11.BAParticipantManager bpm1 = null;
    com.arjuna.wst11.BAParticipantManager bpm2 = null;
    DemoBusinessParticipant p = new DemoBusinessParticipant(DemoBusinessParticipant.COMPENSATE, "1241");
    FailureBusinessParticipant fp = new FailureBusinessParticipant(FailureBusinessParticipant.FAIL_IN_COMPENSATE, "5680");
    try {
        uba.begin();
        bpm1 = bam.enlistForBusinessAgreementWithParticipantCompletion(p, "1241");
        bpm2 = bam.enlistForBusinessAgreementWithParticipantCompletion(fp, "5680");
        bpm1.completed();
        bpm2.completed();
    } catch (Exception eouter) {
        try {
            uba.cancel();
        } catch (Exception einner) {
        }
        throw eouter;
    }
    // the cancel/compensate should succeed even though the participant fails to compensate
    uba.cancel();
    assertTrue(p.passed());
}
Also used : DemoBusinessParticipant(com.arjuna.wstx.tests.common.DemoBusinessParticipant) BusinessActivityManager(com.arjuna.mw.wst11.BusinessActivityManager) UserBusinessActivity(com.arjuna.mw.wst11.UserBusinessActivity) FailureBusinessParticipant(com.arjuna.wstx.tests.common.FailureBusinessParticipant) Test(org.junit.Test)

Example 13 with BusinessActivityManager

use of com.arjuna.mw.wst11.BusinessActivityManager in project narayana by jbosstm.

the class CancelTest method testCancel.

@Test
public void testCancel() throws Exception {
    UserBusinessActivity uba = UserBusinessActivity.getUserBusinessActivity();
    BusinessActivityManager bam = BusinessActivityManager.getBusinessActivityManager();
    String participantId = "1234";
    DemoBusinessParticipant p = new DemoBusinessParticipant(DemoBusinessParticipant.CANCEL, participantId);
    try {
        uba.begin();
        bam.enlistForBusinessAgreementWithParticipantCompletion(p, participantId);
    } catch (Exception eouter) {
        try {
            uba.cancel();
        } catch (Exception einner) {
        }
        throw eouter;
    }
    uba.cancel();
    assertTrue(p.passed());
}
Also used : DemoBusinessParticipant(com.arjuna.wstx.tests.common.DemoBusinessParticipant) BusinessActivityManager(com.arjuna.mw.wst11.BusinessActivityManager) UserBusinessActivity(com.arjuna.mw.wst11.UserBusinessActivity) Test(org.junit.Test)

Example 14 with BusinessActivityManager

use of com.arjuna.mw.wst11.BusinessActivityManager in project narayana by jbosstm.

the class TestServiceBAImple method increment.

@Override
public void increment() {
    try {
        BusinessActivityManager activityManager = BusinessActivityManagerFactory.businessActivityManager();
        activityManager.enlistForBusinessAgreementWithCoordinatorCompletion(this, "TestService:" + UUID.randomUUID());
    } catch (NullPointerException e) {
    // Ignore if no activity
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    counter.incrementAndGet();
}
Also used : BusinessActivityManager(com.arjuna.mw.wst11.BusinessActivityManager) FaultedException(com.arjuna.wst.FaultedException) WrongStateException(com.arjuna.wst.WrongStateException) SystemException(com.arjuna.wst.SystemException)

Example 15 with BusinessActivityManager

use of com.arjuna.mw.wst11.BusinessActivityManager in project wildfly by wildfly.

the class BACoordinatorCompletionSuperService method saveData.

/**
 * Add an item to a set and enroll a Participant if necessary then pass the call through to the business logic.
 *
 * @param value the value to add to the set.
 * @throws AlreadyInSetException if value is already in the set
 * @throws SetServiceException   if an error occurred when attempting to add the item to the set.
 */
public void saveData(String value, ServiceCommand... serviceCommands) throws TestApplicationException {
    log.trace("[BA COORDINATOR COMPL SERVICE] web method saveData('" + value + "')");
    eventLog.foundEventLogName(value);
    BusinessActivityManager activityManager = BusinessActivityManagerFactory.businessActivityManager();
    // transaction context associated with this thread
    String transactionId;
    try {
        transactionId = activityManager.currentTransaction().toString();
    } catch (SystemException e) {
        throw new RuntimeException("Unable to lookup existing business activity", e);
    }
    // Lookup existing participant or register new participant (
    BACoordinationCompletionParticipant participantBA = BACoordinationCompletionParticipant.getSomeParticipant(transactionId);
    if (participantBA != null && ServiceCommand.isPresent(REUSE_BA_PARTICIPANT, serviceCommands)) {
        log.trace("[BA COORDINATOR COMPL SERVICE] Re-using the existing participant, already registered for this BA - command set to: " + REUSE_BA_PARTICIPANT);
    } else {
        try {
            // enlist the Participant for this service:
            participantBA = new BACoordinationCompletionParticipant(serviceCommands, eventLog, transactionId, value);
            BACoordinationCompletionParticipant.recordParticipant(transactionId, participantBA);
            log.trace("[BA COORDINATOR COMPL SERVICE] Enlisting a participant into the BA");
            BAParticipantManager baParticipantManager = activityManager.enlistForBusinessAgreementWithCoordinatorCompletion(participantBA, "BACoordinatorCompletition:" + new Uid().toString());
            if (ServiceCommand.isPresent(CANNOT_COMPLETE, serviceCommands)) {
                baParticipantManager.cannotComplete();
                return;
            }
            if (ServiceCommand.isPresent(DO_COMPLETE, serviceCommands)) {
                throw new RuntimeException("Only ParticipantCompletion participants are supposed to call complete. " + "CoordinatorCompletion participants need to wait to be notified by the coordinator.");
            }
        } catch (Exception e) {
            log.error("[BA COORDINATOR COMPL SERVICE] Participant enlistment failed", e);
            throw new RuntimeException("Error enlisting participant", e);
        }
    }
    if (ServiceCommand.isPresent(APPLICATION_EXCEPTION, serviceCommands)) {
        throw new TestApplicationException("Intentionally thrown Application Exception - service command set to: " + APPLICATION_EXCEPTION);
    }
    // invoke the back-end business logic
    log.trace("[BA COORDINATOR COMPL SERVICE] Invoking the back-end business logic - saving value: " + value);
}
Also used : Uid(com.arjuna.ats.arjuna.common.Uid) TestApplicationException(org.jboss.as.test.xts.base.TestApplicationException) SystemException(com.arjuna.wst.SystemException) BusinessActivityManager(com.arjuna.mw.wst11.BusinessActivityManager) BAParticipantManager(com.arjuna.wst11.BAParticipantManager) TestApplicationException(org.jboss.as.test.xts.base.TestApplicationException) SystemException(com.arjuna.wst.SystemException)

Aggregations

BusinessActivityManager (com.arjuna.mw.wst11.BusinessActivityManager)15 UserBusinessActivity (com.arjuna.mw.wst11.UserBusinessActivity)9 Test (org.junit.Test)9 DemoBusinessParticipant (com.arjuna.wstx.tests.common.DemoBusinessParticipant)8 SystemException (com.arjuna.wst.SystemException)6 BAParticipantManager (com.arjuna.wst11.BAParticipantManager)3 FailureBusinessParticipant (com.arjuna.wstx.tests.common.FailureBusinessParticipant)3 Uid (com.arjuna.ats.arjuna.common.Uid)2 WebMethod (javax.jws.WebMethod)2 TestApplicationException (org.jboss.as.test.xts.base.TestApplicationException)2 Context (com.arjuna.mw.wsc11.context.Context)1 TxContext (com.arjuna.mw.wst.TxContext)1 TransactionManager (com.arjuna.mw.wst11.TransactionManager)1 TxContextImple (com.arjuna.mwlabs.wst11.at.context.TxContextImple)1 FaultedException (com.arjuna.wst.FaultedException)1 TransactionRolledBackException (com.arjuna.wst.TransactionRolledBackException)1 WrongStateException (com.arjuna.wst.WrongStateException)1 DemoBusinessParticipantWithComplete (com.arjuna.wstx.tests.common.DemoBusinessParticipantWithComplete)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 Name (javax.xml.soap.Name)1