use of com.arjuna.wst.SystemException 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());
}
use of com.arjuna.wst.SystemException in project narayana by jbosstm.
the class XTSServiceTestInterpreter method processCommands.
// / implementation of the interpreter functionality
/**
* simple command interpreter which executes the commands in the command list, inserting the
* corresponding results in the results list and using the supplied bindings list
* to provide values for any parameters supplied in the commands and to bind any results
* obtained by executing the commands
*
* @param commandList a list of command strings
* @param resultsList a list into which results strings are to be inserted
* @param bindings a list of bound variables to be substituted into commands
* or updated with new bindings
*/
private void processCommands(List<String> commandList, List<String> resultsList, HashMap<String, String> bindings) throws WebServiceException {
int size = commandList.size();
if (size == 0) {
throw new WebServiceException("empty command list");
}
String command = commandList.remove(0);
size--;
if (command.equals("block")) {
// we don't bind the command block immediately since bindings may be produced
// by intermediate bind commands
processCommandBlock(commandList, resultsList, bindings);
} else {
int idx = 0;
if (command.equals("enlistDurable")) {
// enlistment commands
bindCommands(commandList, bindings);
String id = participantId("DurableTestParticipant");
DurableTestParticipant participant = new DurableTestParticipant(id);
TransactionManager txman = TransactionManagerFactory.transactionManager();
try {
txman.enlistForDurableTwoPhase(participant, id);
} catch (Exception e) {
throw new WebServiceException("enlistDurable failed ", e);
}
for (idx = 0; idx < size; idx++) {
participant.addCommand(commandList.get(idx));
}
participantMap.put(id, participant);
resultsList.add(id);
} else if (command.equals("enlistVolatile")) {
bindCommands(commandList, bindings);
String id = participantId("VolatileTestParticipant");
VolatileTestParticipant participant = new VolatileTestParticipant(id);
TransactionManager txman = TransactionManagerFactory.transactionManager();
try {
txman.enlistForVolatileTwoPhase(participant, id);
} catch (Exception e) {
throw new WebServiceException("enlistVolatile failed ", e);
}
for (idx = 0; idx < size; idx++) {
participant.addCommand(commandList.get(idx));
}
participantMap.put(id, participant);
resultsList.add(id);
} else if (command.equals("enlistCoordinatorCompletion")) {
bindCommands(commandList, bindings);
String id = participantId("CoordinatorCompletionParticipant");
CoordinatorCompletionTestParticipant participant = new CoordinatorCompletionTestParticipant(id);
BusinessActivityManager baman = BusinessActivityManagerFactory.businessActivityManager();
try {
BAParticipantManager partMan;
partMan = baman.enlistForBusinessAgreementWithCoordinatorCompletion(participant, id);
managerMap.put(id, partMan);
} catch (Exception e) {
throw new WebServiceException("enlistCoordinatorCompletion failed ", e);
}
for (idx = 0; idx < size; idx++) {
participant.addCommand(commandList.get(idx));
}
participantMap.put(id, participant);
resultsList.add(id);
} else if (command.equals("enlistParticipantCompletion")) {
bindCommands(commandList, bindings);
String id = participantId("ParticipantCompletionParticipant");
ParticipantCompletionTestParticipant participant = new ParticipantCompletionTestParticipant(id);
BusinessActivityManager baman = BusinessActivityManagerFactory.businessActivityManager();
try {
BAParticipantManager partMan;
partMan = baman.enlistForBusinessAgreementWithParticipantCompletion(participant, id);
managerMap.put(id, partMan);
} catch (Exception e) {
throw new WebServiceException("enlistParticipantCompletion failed ", e);
}
for (idx = 0; idx < size; idx++) {
participant.addCommand(commandList.get(idx));
}
participantMap.put(id, participant);
resultsList.add(id);
} else if (command.equals("addCommands")) {
// add extra commands to a participant script
bindCommands(commandList, bindings);
String id = commandList.remove(idx);
size--;
ScriptedTestParticipant participant = participantMap.get(id);
if (participant != null) {
for (idx = 0; idx < size; idx++) {
participant.addCommand(commandList.get(idx));
}
resultsList.add("ok");
} else {
throw new WebServiceException("addCommands failed to find participant " + id);
}
} else if (command.equals("exit")) {
// initiate BA manager activities
bindCommands(commandList, bindings);
String id = commandList.remove(idx);
size--;
ScriptedTestParticipant participant = participantMap.get(id);
if (participant != null) {
if (participant instanceof ParticipantCompletionTestParticipant) {
ParticipantCompletionTestParticipant baparticipant = (ParticipantCompletionTestParticipant) participant;
BAParticipantManager manager = managerMap.get(id);
try {
manager.exit();
} catch (Exception e) {
throw new WebServiceException("exit " + id + " failed with exception " + e);
}
resultsList.add("ok");
} else {
throw new WebServiceException("exit invalid participant type " + id);
}
} else {
throw new WebServiceException("exit unknown participant " + id);
}
} else if (command.equals("completed")) {
bindCommands(commandList, bindings);
String id = commandList.remove(idx);
size--;
ScriptedTestParticipant participant = participantMap.get(id);
if (participant != null) {
if (participant instanceof ParticipantCompletionTestParticipant) {
ParticipantCompletionTestParticipant baparticipant = (ParticipantCompletionTestParticipant) participant;
BAParticipantManager manager = managerMap.get(id);
try {
manager.completed();
resultsList.add("ok");
} catch (Exception e) {
throw new WebServiceException("completed " + id + " failed with exception " + e);
}
} else {
throw new WebServiceException("completed invalid participant type " + id);
}
} else {
throw new WebServiceException("completed unknown participant " + id);
}
} else if (command.equals("fail")) {
bindCommands(commandList, bindings);
String id = commandList.remove(idx);
size--;
ScriptedTestParticipant participant = participantMap.get(id);
if (participant != null) {
if (participant instanceof ParticipantCompletionTestParticipant) {
ParticipantCompletionTestParticipant baparticipant = (ParticipantCompletionTestParticipant) participant;
BAParticipantManager manager = managerMap.get(id);
QName qname = new QName("http://jbossts.jboss.org/xts/servicetests/", "fail");
try {
manager.fail(qname);
resultsList.add("ok");
} catch (Exception e) {
throw new WebServiceException("fail " + id + " failed with exception " + e);
}
} else {
throw new WebServiceException("fail invalid participant type " + id);
}
} else {
throw new WebServiceException("fail unknown participant " + id);
}
} else if (command.equals("cannotComplete")) {
bindCommands(commandList, bindings);
String id = commandList.remove(idx);
size--;
ScriptedTestParticipant participant = participantMap.get(id);
if (participant != null) {
if (participant instanceof ParticipantCompletionTestParticipant) {
ParticipantCompletionTestParticipant baparticipant = (ParticipantCompletionTestParticipant) participant;
BAParticipantManager manager = managerMap.get(id);
try {
manager.cannotComplete();
resultsList.add("ok");
} catch (Exception e) {
throw new WebServiceException("cannotComplete " + id + " failed with exception " + e);
}
} else {
throw new WebServiceException("cannotComplete invalid participant type " + id);
}
} else {
throw new WebServiceException("cannotComplete unknown participant " + id);
}
} else if (command.equals("serve")) {
// dispatch commands to a server for execution
// we should find a web service URL and a list of commands to dispatch to that service
String url = commandList.remove(idx);
size--;
// we throw an error if the server url is unbound but we allow
// unbound variables in the command list passed on to the server
// since they may be bound by bind commands in the command list
// being served.
url = bindCommand(url, bindings, true);
bindCommands(commandList, bindings, false);
CommandsType newCommands = new CommandsType();
List<String> newCommandList = newCommands.getCommandList();
for (int i = 0; i < size; i++) {
newCommandList.add(commandList.get(i));
}
ResultsType subResults = serveSubordinate(url, newCommands);
List<String> subResultsList = subResults.getResultList();
size = subResultsList.size();
for (idx = 0; idx < size; idx++) {
resultsList.add(subResultsList.get(idx));
}
} else if (command.equals("subtransaction")) {
// create subordinate AT transaction
// this is surplus to requirements since we should really be running against a service which uses
// the subordinate interposition JaxWS handler to install a subordinate transaction before
// entering the service method. we ought to test that handler rather than hand crank the
// interposition in the service
TxContext currentTx;
TxContext newTx;
try {
currentTx = TransactionManager.getTransactionManager().currentTransaction();
} catch (SystemException e) {
throw new WebServiceException("subtransaction currentTransaction() failed with exception " + e);
}
try {
UserTransaction userTransaction = UserTransactionFactory.userSubordinateTransaction();
userTransaction.begin();
newTx = TransactionManager.getTransactionManager().currentTransaction();
} catch (Exception e) {
throw new WebServiceException("subtransaction begin() failed with exception " + e);
}
String id = transactionId("at");
subordinateTransactionMap.put(id, newTx);
resultsList.add(id);
} else if (command.equals("subactivity")) {
// create subordinate BA transaction
// this is surplus ot requirements since we should really be running against a service which uses
// the subordinate interposition JaxWS handler to install a subordinate activity before
// entering the service method. we ought to test that handler rather than hand crank the
// interposition in the service
TxContext currentTx;
TxContext newTx;
try {
currentTx = BusinessActivityManagerFactory.businessActivityManager().currentTransaction();
} catch (SystemException e) {
throw new WebServiceException("subtransaction currentTransaction() failed with exception " + e);
}
try {
UserBusinessActivity userBusinessActivity = UserBusinessActivityFactory.userBusinessActivity();
// this is nto implemented yet!!!
// userBusinessActivity.beginSubordinate();
// and this will fail with a WrongStateException
userBusinessActivity.begin();
newTx = BusinessActivityManager.getBusinessActivityManager().currentTransaction();
} catch (Exception e) {
throw new WebServiceException("subtransaction begin() failed with exception " + e);
}
String id = transactionId("ba");
subordinateActivityMap.put(id, newTx);
resultsList.add(id);
} else if (command.equals("subtransactionserve")) {
// dispatch commands in a subordinate transaction or activity
// we should find the id of a subordinate transaction, a web service URL
// and a list of commands to dispatch to that transaction
// the txid and url must be resolved if supplied as bindings
String txId = bindCommand(commandList.remove(idx), bindings, true);
size--;
String url = bindCommand(commandList.remove(idx), bindings, true);
size--;
TxContext newTx = subordinateTransactionMap.get(txId);
if (newTx != null) {
try {
TransactionManager.getTransactionManager().resume(newTx);
} catch (Exception e) {
throw new WebServiceException("subtransactioncommands resume() failed with exception " + e);
}
} else {
throw new WebServiceException("subtransactioncommands unknown subordinate transaction id " + txId);
}
// ok, now we install the relevant transaction and then just pass the commands on to
// the web service
// we allow unresolved variable references in the rest of the command list as
// they may be satisfied by embedded bind commands
bindCommands(commandList, bindings, false);
CommandsType newCommands = new CommandsType();
List<String> newCommandList = newCommands.getCommandList();
for (int i = 0; i < size; i++) {
newCommandList.add(commandList.get(i));
}
ResultsType subResults = serveSubordinate(url, newCommands);
List<String> subResultsList = subResults.getResultList();
size = subResultsList.size();
for (idx = 0; idx < size; idx++) {
resultsList.add(subResultsList.get(idx));
}
} else if (command.equals("subactivityserve")) {
// dispatch commands in a subordinate transaction or activity
// we should find the id of a subordinate transaction, a web service URL
// and a list of commands to dispatch to that transaction
// the txid and url must be resolved if supplied as bindings
String txId = bindCommand(commandList.remove(idx), bindings, true);
size--;
String url = bindCommand(commandList.remove(idx), bindings, true);
size--;
TxContext newTx = subordinateActivityMap.get(txId);
if (newTx != null) {
try {
TransactionManager.getTransactionManager().resume(newTx);
} catch (Exception e) {
throw new WebServiceException("subactivitycommands resume() failed with exception " + e);
}
} else {
throw new WebServiceException("subactivitycommands unknown subordinate transaction id " + txId);
}
// ok, now we install the relevant transaction and then just pass the commands on to
// the web service
// we allow unresolved variable references in the rest of the command list as
// they may be satisfied by embedded bind commands
bindCommands(commandList, bindings, false);
CommandsType newCommands = new CommandsType();
List<String> newCommandList = newCommands.getCommandList();
for (int i = 0; i < size; i++) {
newCommandList.add(commandList.get(i));
}
ResultsType subResults = serveSubordinate(url, newCommands);
List<String> subResultsList = subResults.getResultList();
size = subResultsList.size();
for (idx = 0; idx < size; idx++) {
resultsList.add(subResultsList.get(idx));
}
}
}
}
use of com.arjuna.wst.SystemException in project narayana by jbosstm.
the class MultiServicePrepareAndCommitTest method run.
public void run() {
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
// ignore
}
String serviceURL1;
String serviceURL2;
String serviceURL3;
serviceURL1 = System.getProperty(XTSServiceTest.SERVICE_URL1_KEY);
serviceURL2 = System.getProperty(XTSServiceTest.SERVICE_URL2_KEY);
serviceURL3 = System.getProperty(XTSServiceTest.SERVICE_URL3_KEY);
if (serviceURL1 == null) {
serviceURL1 = "http://localhost:8080/xtstest/xtsservicetest1";
}
if (serviceURL2 == null) {
serviceURL2 = "http://localhost:8080/xtstest/xtsservicetest2";
}
if (serviceURL3 == null) {
serviceURL3 = "http://localhost:8080/xtstest/xtsservicetest3";
}
addDefaultBinding("service1", serviceURL1);
addDefaultBinding("service2", serviceURL2);
addDefaultBinding("service3", serviceURL3);
UserTransaction tx = UserTransactionFactory.userTransaction();
try {
tx.begin();
} catch (WrongStateException e) {
exception = e;
} catch (SystemException e) {
exception = e;
}
if (exception != null) {
error("txbegin failure " + exception);
return;
}
// invoke the service and tell it to prepare and commit
List<String> commands = new ArrayList<String>();
List<String> results = new ArrayList<String>();
commands.add("block");
commands.add("serve");
commands.add("{service1}");
commands.add("enlistDurable");
commands.add("prepare");
commands.add("commit");
commands.add("next");
commands.add("serve");
commands.add("{service2}");
commands.add("enlistDurable");
commands.add("prepare");
commands.add("commit");
commands.add("next");
commands.add("serve");
commands.add("{service3}");
commands.add("enlistDurable");
commands.add("prepare");
commands.add("commit");
commands.add("endblock");
try {
processCommands(commands, results);
} catch (Exception e) {
exception = e;
}
if (exception != null) {
error("test failure " + exception);
return;
}
try {
tx.commit();
} catch (TransactionRolledBackException e) {
exception = e;
} catch (UnknownTransactionException e) {
exception = e;
} catch (SystemException e) {
exception = e;
} catch (WrongStateException e) {
exception = e;
}
if (exception != null) {
error("commit failure " + exception);
}
message("completed");
isSuccessful = (exception == null);
}
use of com.arjuna.wst.SystemException in project narayana by jbosstm.
the class MultiParticipantCoordinatorCompletionParticipantCloseTest method run.
public void run() {
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
// ignore
}
String serviceURL1;
serviceURL1 = System.getProperty(XTSServiceTest.SERVICE_URL1_KEY);
if (serviceURL1 == null) {
serviceURL1 = "http://localhost:8080/xtstest/xtsservicetest1";
}
addDefaultBinding("service1", serviceURL1);
UserBusinessActivity ba = UserBusinessActivityFactory.userBusinessActivity();
try {
ba.begin();
} catch (WrongStateException e) {
exception = e;
} catch (SystemException e) {
exception = e;
}
if (exception != null) {
error("txbegin failure " + exception);
return;
}
List<String> resultsList;
String participantId;
List<String> commands = new ArrayList<String>();
List<String> results = new ArrayList<String>();
commands.add("block");
commands.add("serve");
commands.add("{service1}");
commands.add("enlistCoordinatorCompletion");
commands.add("complete");
commands.add("close");
commands.add("next");
commands.add("serve");
commands.add("{service1}");
commands.add("enlistCoordinatorCompletion");
commands.add("complete");
commands.add("close");
commands.add("next");
commands.add("serve");
commands.add("{service1}");
commands.add("enlistCoordinatorCompletion");
commands.add("complete");
commands.add("close");
commands.add("endblock");
try {
processCommands(commands, results);
} catch (Exception e) {
exception = e;
}
if (exception != null) {
error("test failure " + exception);
return;
}
try {
ba.close();
} catch (TransactionRolledBackException e) {
exception = e;
} catch (UnknownTransactionException e) {
exception = e;
} catch (SystemException e) {
exception = e;
} catch (WrongStateException e) {
exception = e;
}
if (exception != null) {
error("commit failure " + exception);
}
message("completed");
isSuccessful = (exception == null);
}
use of com.arjuna.wst.SystemException in project narayana by jbosstm.
the class MultiParticipantCoordinatorCompletionParticipantCloseAndExitTest method run.
public void run() {
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
// ignore
}
String serviceURL1;
String subserviceURL1;
serviceURL1 = System.getProperty(XTSServiceTest.SERVICE_URL1_KEY);
if (serviceURL1 == null) {
serviceURL1 = "http://localhost:8080/xtstest/xtsservicetest1";
}
subserviceURL1 = System.getProperty(XTSServiceTest.SUBORDINATE_SERVICE_URL1_KEY);
if (subserviceURL1 == null) {
subserviceURL1 = "http://localhost:8080/xtstest/xtssubordinateservicetest1";
}
addDefaultBinding("service1", serviceURL1);
addDefaultBinding("subservice1", subserviceURL1);
UserBusinessActivity ba = UserBusinessActivityFactory.userBusinessActivity();
try {
ba.begin();
} catch (WrongStateException e) {
exception = e;
} catch (SystemException e) {
exception = e;
}
if (exception != null) {
error("txbegin failure " + exception);
return;
}
List<String> resultsList;
String participantId;
List<String> commands = new ArrayList<String>();
List<String> results = new ArrayList<String>();
commands.add("block");
commands.add("serve");
commands.add("{service1}");
commands.add("enlistCoordinatorCompletion");
commands.add("complete");
commands.add("close");
commands.add("bindings");
commands.add("bind");
commands.add("P1");
commands.add("0");
commands.add("next");
commands.add("serve");
commands.add("{subservice1}");
commands.add("enlistCoordinatorCompletion");
commands.add("bindings");
commands.add("bind");
commands.add("P2");
commands.add("0");
commands.add("next");
commands.add("serve");
commands.add("{subservice1}");
commands.add("enlistCoordinatorCompletion");
commands.add("bindings");
commands.add("bind");
commands.add("P3");
commands.add("0");
commands.add("next");
commands.add("serve");
commands.add("{subservice1}");
commands.add("exit");
commands.add("{P2}");
commands.add("next");
commands.add("serve");
commands.add("{subservice1}");
commands.add("exit");
commands.add("{P3}");
commands.add("endblock");
try {
processCommands(commands, results);
} catch (Exception e) {
exception = e;
}
if (exception != null) {
error("test failure " + exception);
return;
}
try {
ba.close();
} catch (TransactionRolledBackException e) {
exception = e;
} catch (UnknownTransactionException e) {
exception = e;
} catch (SystemException e) {
exception = e;
} catch (WrongStateException e) {
exception = e;
}
if (exception != null) {
error("commit failure " + exception);
}
message("completed");
isSuccessful = (exception == null);
}
Aggregations