[jboss-svn-commits] JBL Code SVN: r25351 - in labs/jbosstm/trunk/XTS/sar/tests/src/org/jboss/jbossts/xts/servicetests: service and 1 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Thu Feb 19 13:26:48 EST 2009


Author: adinn
Date: 2009-02-19 13:26:47 -0500 (Thu, 19 Feb 2009)
New Revision: 25351

Added:
   labs/jbosstm/trunk/XTS/sar/tests/src/org/jboss/jbossts/xts/servicetests/test/ATSubordinateMultiParticipantPrepareAndCommitTest.java
   labs/jbosstm/trunk/XTS/sar/tests/src/org/jboss/jbossts/xts/servicetests/test/XTSServiceTestBase.java
Modified:
   labs/jbosstm/trunk/XTS/sar/tests/src/org/jboss/jbossts/xts/servicetests/client/XTSServiceTestClient.java
   labs/jbosstm/trunk/XTS/sar/tests/src/org/jboss/jbossts/xts/servicetests/service/Constants.java
   labs/jbosstm/trunk/XTS/sar/tests/src/org/jboss/jbossts/xts/servicetests/service/XTSServiceTestPortTypeImpl.java
   labs/jbosstm/trunk/XTS/sar/tests/src/org/jboss/jbossts/xts/servicetests/test/ATMultiParticipantPrepareAndCommitTest.java
   labs/jbosstm/trunk/XTS/sar/tests/src/org/jboss/jbossts/xts/servicetests/test/ATMultiServicePrepareAndCommitTest.java
   labs/jbosstm/trunk/XTS/sar/tests/src/org/jboss/jbossts/xts/servicetests/test/ATSingleParticipantPrepareAndCommitTest.java
   labs/jbosstm/trunk/XTS/sar/tests/src/org/jboss/jbossts/xts/servicetests/test/BAMultiParticipantCoordinatorCompletionParticipantCloseAndExitTest.java
   labs/jbosstm/trunk/XTS/sar/tests/src/org/jboss/jbossts/xts/servicetests/test/BAMultiParticipantCoordinatorCompletionParticipantCloseTest.java
   labs/jbosstm/trunk/XTS/sar/tests/src/org/jboss/jbossts/xts/servicetests/test/BAMultiParticipantParticipantCompletionParticipantCloseAndExitTest.java
   labs/jbosstm/trunk/XTS/sar/tests/src/org/jboss/jbossts/xts/servicetests/test/BAMultiParticipantParticipantCompletionParticipantCloseTest.java
   labs/jbosstm/trunk/XTS/sar/tests/src/org/jboss/jbossts/xts/servicetests/test/BAMultiServiceCoordinatorCompletionParticipantCloseAndExitTest.java
   labs/jbosstm/trunk/XTS/sar/tests/src/org/jboss/jbossts/xts/servicetests/test/BAMultiServiceCoordinatorCompletionParticipantCloseTest.java
   labs/jbosstm/trunk/XTS/sar/tests/src/org/jboss/jbossts/xts/servicetests/test/BAMultiServiceParticipantCompletionParticipantCloseAndExitTest.java
   labs/jbosstm/trunk/XTS/sar/tests/src/org/jboss/jbossts/xts/servicetests/test/BAMultiServiceParticipantCompletionParticipantCloseTest.java
   labs/jbosstm/trunk/XTS/sar/tests/src/org/jboss/jbossts/xts/servicetests/test/BASingleCoordinatorCompletionParticipantCloseTest.java
   labs/jbosstm/trunk/XTS/sar/tests/src/org/jboss/jbossts/xts/servicetests/test/BASingleParticipantCompletionParticipantCloseTest.java
Log:
extended test service to enabel creation of subordinate AT transactions and added service test implementing a simple subordinate AT transaction create, prepare and commit scenario -- partially fixes JBTM-447

Modified: labs/jbosstm/trunk/XTS/sar/tests/src/org/jboss/jbossts/xts/servicetests/client/XTSServiceTestClient.java
===================================================================
--- labs/jbosstm/trunk/XTS/sar/tests/src/org/jboss/jbossts/xts/servicetests/client/XTSServiceTestClient.java	2009-02-19 18:10:48 UTC (rev 25350)
+++ labs/jbosstm/trunk/XTS/sar/tests/src/org/jboss/jbossts/xts/servicetests/client/XTSServiceTestClient.java	2009-02-19 18:26:47 UTC (rev 25351)
@@ -46,7 +46,7 @@
  * agreement participant such as completed, fail etc. The full list of available commands and associated
  * return values is
  *
- * enlistDureable (ATParticipantCommand)* ==> DurableId
+ * enlistDurable (ATParticipantCommand)* ==> DurableId
  * enlistVolatile  (ATParticipantCommand)* ==> VolatileId
  * enlistCoordinatorCompletion (BACoordinatorCompletionCommand)* ==> BACoordinatorCompletionId
  * enlistParticipantCompletion (BAParticipantCompletionCommand)* ==> BAParticipantCompletionId
@@ -55,6 +55,10 @@
  * exit (BAParticipantCompletionId | BACoordinatorCompletionId) ==> "ok"
  * cannotComplete BAParticipantCompletionId ==> "ok"
  * completed BAParticipantCompletionId ==> "ok"
+ * subtransaction ==> subtransactionId
+ * subactivity ==> subactivityId
+ * subtransactioncommands subtransactionId serviceURL (command)
+ * subactivitycommands subactivityId serviceURL (command)
  *
  * where
  *
@@ -93,7 +97,18 @@
  * BAParticipantCompletionId is a String of the form
  *   "org.jboss.jbossts.xts.servicetests.ParticipantCompletionTestParticipant.NNNNNNNN"
  *
+ * subtransactionId is a String of the form
+ *   "transaction.at.NNNNNNNN"
+ *
+ * subactivityId is a String of the form
+ *   "transaction.ba.NNNNNNNN"
+ *
  * where NNNNNNNNN is a sequence of base 10 digits.
+ * 
+ * serviceURL is a URL identifying an instance of the test service to which commands are to be
+ * recursively dispatched within the relevant subtransaction or subactivity
+ *
+ * command is any sequence of command strings defined by the LHS of the preceding productions
  */
 
 public class XTSServiceTestClient

Modified: labs/jbosstm/trunk/XTS/sar/tests/src/org/jboss/jbossts/xts/servicetests/service/Constants.java
===================================================================
--- labs/jbosstm/trunk/XTS/sar/tests/src/org/jboss/jbossts/xts/servicetests/service/Constants.java	2009-02-19 18:10:48 UTC (rev 25350)
+++ labs/jbosstm/trunk/XTS/sar/tests/src/org/jboss/jbossts/xts/servicetests/service/Constants.java	2009-02-19 18:26:47 UTC (rev 25351)
@@ -6,4 +6,5 @@
 public class Constants
 {
     public static final String PARTICIPANT_ID_PREFIX = "org.jboss.jbossts.xts.servicetests.";
+    public static final String TRANSACTION_ID_PREFIX = "transaction.";
 }

Modified: labs/jbosstm/trunk/XTS/sar/tests/src/org/jboss/jbossts/xts/servicetests/service/XTSServiceTestPortTypeImpl.java
===================================================================
--- labs/jbosstm/trunk/XTS/sar/tests/src/org/jboss/jbossts/xts/servicetests/service/XTSServiceTestPortTypeImpl.java	2009-02-19 18:10:48 UTC (rev 25350)
+++ labs/jbosstm/trunk/XTS/sar/tests/src/org/jboss/jbossts/xts/servicetests/service/XTSServiceTestPortTypeImpl.java	2009-02-19 18:26:47 UTC (rev 25351)
@@ -27,23 +27,26 @@
 import org.jboss.jbossts.xts.servicetests.generated.XTSServiceTestPortType;
 import org.jboss.jbossts.xts.servicetests.service.participant.*;
 import org.jboss.jbossts.xts.servicetests.service.recovery.TestATRecoveryModule;
+import org.jboss.jbossts.xts.servicetests.client.XTSServiceTestClient;
 
 import javax.jws.*;
 import javax.jws.soap.SOAPBinding;
 import javax.xml.bind.annotation.XmlSeeAlso;
 import javax.xml.ws.WebServiceException;
 import javax.xml.ws.WebServiceContext;
+import javax.xml.ws.handler.MessageContext;
 import javax.xml.namespace.QName;
 import javax.annotation.PostConstruct;
 import javax.annotation.PreDestroy;
 import javax.annotation.Resource;
+import javax.servlet.ServletContext;
+import javax.servlet.ServletRequest;
+import javax.servlet.http.HttpServletRequest;
 import java.util.List;
 import java.util.HashMap;
 
-import com.arjuna.mw.wst11.TransactionManager;
-import com.arjuna.mw.wst11.TransactionManagerFactory;
-import com.arjuna.mw.wst11.BusinessActivityManager;
-import com.arjuna.mw.wst11.BusinessActivityManagerFactory;
+import com.arjuna.mw.wst11.*;
+import com.arjuna.mw.wst.TxContext;
 import com.arjuna.wst11.BAParticipantManager;
 import com.arjuna.wst.WrongStateException;
 import com.arjuna.wst.UnknownTransactionException;
@@ -83,6 +86,9 @@
     {
         System.out.println("XTSServiceTestPortTypeImpl preDestroy");
     }
+
+    @Resource WebServiceContext context;
+
     /**
      *
      * @param commands
@@ -99,15 +105,21 @@
         List<String> resultsList = results.getResultList();
         List<String> commandList = commands.getCommandList();
 
+        MessageContext messageContext = context.getMessageContext();
+        HttpServletRequest servletRequest = ((HttpServletRequest)messageContext.get(MessageContext.SERVLET_REQUEST));
+        String path = servletRequest.getServletPath();
+
+        System.out.println("service " + path);
         for (String s : commandList)
         {
-            System.out.println("service  " + this + " :  command " + s);
+            System.out.println("  command " + s);
         }
 
         int size = commandList.size();
         int idx = 0;
 
-        String command = commandList.get(idx);
+        String command = commandList.remove(idx);
+        size--;
 
         // check against each of the possible commands
 
@@ -122,7 +134,7 @@
             } catch (Exception e) {
                 throw new WebServiceException("enlistDurable failed ", e);
             }
-            for (idx = 1; idx < size; idx++) {
+            for (idx = 0; idx < size; idx++) {
                 participant.addCommand(commandList.get(idx));
             }
             participantMap.put(id, participant);
@@ -136,7 +148,7 @@
             } catch (Exception e) {
                 throw new WebServiceException("enlistVolatile failed ", e);
             }
-            for (idx = 1;idx < size; idx++) {
+            for (idx = 0; idx < size; idx++) {
                 participant.addCommand(commandList.get(idx));
             }
             participantMap.put(id, participant);
@@ -152,7 +164,7 @@
             } catch (Exception e) {
                 throw new WebServiceException("enlistCoordinatorCompletion failed ", e);
             }
-            for (idx = 1;idx < size; idx++) {
+            for (idx = 0; idx < size; idx++) {
                 participant.addCommand(commandList.get(idx));
             }
             participantMap.put(id, participant);
@@ -168,17 +180,18 @@
             } catch (Exception e) {
                 throw new WebServiceException("enlistParticipantCompletion failed ", e);
             }
-            for (idx = 1;idx < size; idx++) {
+            for (idx = 0; idx < size; idx++) {
                 participant.addCommand(commandList.get(idx));
             }
             participantMap.put(id, participant);
             resultsList.add(id);
         } else if (command.equals("commands")) {
-// add extra commands
-            String id = commandList.get(1);
+// add extra commands to a participant script
+            String id = commandList.remove(idx);
+            size--;
             ScriptedTestParticipant participant = participantMap.get(id);
             if (participant != null) {
-                for (idx = 2; idx < size; idx++)
+                for (idx = 0; idx < size; idx++)
                 {
                     participant.addCommand(commandList.get(idx));
                 }
@@ -188,7 +201,8 @@
             }
         } else if (command.equals("exit")) {
 // initiate BA manager activities
-            String id = commandList.get(1);
+            String id = commandList.remove(idx);
+            size--;
             ScriptedTestParticipant participant = participantMap.get(id);
             if (participant != null ) {
                 if (participant instanceof ParticipantCompletionTestParticipant) {
@@ -207,7 +221,8 @@
                 throw new WebServiceException("exit unknown participant " + id);
             }
         } else if (command.equals("completed")) {
-            String id = commandList.get(1);
+            String id = commandList.remove(idx);
+            size--;
             ScriptedTestParticipant participant = participantMap.get(id);
             if (participant != null ) {
                 if (participant instanceof ParticipantCompletionTestParticipant) {
@@ -226,7 +241,8 @@
                 throw new WebServiceException("completed unknown participant " + id);
             }
         } else if (command.equals("fail")) {
-            String id = commandList.get(1);
+            String id = commandList.remove(idx);
+            size--;
             ScriptedTestParticipant participant = participantMap.get(id);
             if (participant != null ) {
                 if (participant instanceof ParticipantCompletionTestParticipant) {
@@ -246,7 +262,8 @@
                 throw new WebServiceException("fail unknown participant " + id);
             }
         } else if (command.equals("cannotComplete")) {
-            String id = commandList.get(1);
+            String id = commandList.remove(idx);
+            size--;
             ScriptedTestParticipant participant = participantMap.get(id);
             if (participant != null ) {
                 if (participant instanceof ParticipantCompletionTestParticipant) {
@@ -264,12 +281,141 @@
             } else {
                 throw new WebServiceException("cannotComplete unknown participant " + id);
             }
+        } else if (command.equals("subtransaction")) {
+// create subordinate AT transaction
+            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.userTransaction();
+                userTransaction.beginSubordinate();
+                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
+            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("subtransactioncommands")) {
+// 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
+            String txId = commandList.remove(idx);
+            size--;
+            String url = commandList.remove(idx);
+            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
+
+            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("subactivitycommands")) {
+// 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
+            String txId = commandList.remove(idx);
+            size--;
+            String url = commandList.remove(idx);
+            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
+
+            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));
+            }
         }
 
         return results;
     }
 
     /**
+     * utiilty method provided to simplify recursive dispatch of commands to another web service. this is
+     * intended to be used to create and drive partiicpants in subordinate transactions
+     * @param url
+     * @param commands
+     * @return
+     */
+    private ResultsType serveSubordinate(String url, CommandsType commands)
+    {
+        return getClient().serve(url, commands);
+    }
+
+    private synchronized XTSServiceTestClient getClient()
+    {
+        if (client == null) {
+            client = new XTSServiceTestClient();
+        }
+
+        return client;
+    }
+    /**
      *  counter used to conjure up participant names
      */
 
@@ -288,6 +434,18 @@
     }
 
     /**
+     * obtain a new transaction name starting with a transaction prefix and terminated
+     * with the supplied suffix and a unique trailing number
+     * @param suffix a component to be added to the name before the counter identifying the type of
+     * transaction
+     * @return
+     */
+    private synchronized String transactionId(String suffix)
+    {
+        return Constants.TRANSACTION_ID_PREFIX + suffix + "." + nextId++;
+    }
+
+    /**
      * a table used to retain a handle on enlisted participants so that they can be driven by the client to
      * perform actions not contained in the original command script.
      */
@@ -297,4 +455,20 @@
      * a table used to retain a handle on managers for enlisted BA  participants.
      */
     private static HashMap<String, BAParticipantManager> managerMap = new HashMap<String, BAParticipantManager>();
+
+    /**
+     * a table used to retain a handle on AT subordinate transactions
+     */
+    private static HashMap<String, TxContext> subordinateTransactionMap = new HashMap<String, TxContext>();
+
+    /**
+     * a table used to retain a handle on BA subactivities
+     */
+    private static HashMap<String, TxContext> subordinateActivityMap = new HashMap<String, TxContext>();
+
+    /**
+     * a client used to propagate requests recursively from within subtransactions or subactivities
+     */
+
+    private static XTSServiceTestClient client = null;
 }
\ No newline at end of file

Modified: labs/jbosstm/trunk/XTS/sar/tests/src/org/jboss/jbossts/xts/servicetests/test/ATMultiParticipantPrepareAndCommitTest.java
===================================================================
--- labs/jbosstm/trunk/XTS/sar/tests/src/org/jboss/jbossts/xts/servicetests/test/ATMultiParticipantPrepareAndCommitTest.java	2009-02-19 18:10:48 UTC (rev 25350)
+++ labs/jbosstm/trunk/XTS/sar/tests/src/org/jboss/jbossts/xts/servicetests/test/ATMultiParticipantPrepareAndCommitTest.java	2009-02-19 18:26:47 UTC (rev 25351)
@@ -36,11 +36,8 @@
  * Starts a transaction and enlist several participants for the same web service with instructions to
  * prepare and commit without error
  */
-public class ATMultiParticipantPrepareAndCommitTest implements XTSServiceTest
+public class ATMultiParticipantPrepareAndCommitTest extends XTSServiceTestBase implements XTSServiceTest
 {
-    private boolean isSuccessful = false;
-    private Exception exception;
-
     public void run() {
 
         try {
@@ -158,12 +155,4 @@
 
         isSuccessful = (exception == null);
     }
-
-    public boolean isSuccessful() {
-        return false;  //To change body of implemented methods use File | Settings | File Templates.
-    }
-
-    public Exception getException() {
-        return null;  //To change body of implemented methods use File | Settings | File Templates.
-    }
 }
\ No newline at end of file

Modified: labs/jbosstm/trunk/XTS/sar/tests/src/org/jboss/jbossts/xts/servicetests/test/ATMultiServicePrepareAndCommitTest.java
===================================================================
--- labs/jbosstm/trunk/XTS/sar/tests/src/org/jboss/jbossts/xts/servicetests/test/ATMultiServicePrepareAndCommitTest.java	2009-02-19 18:10:48 UTC (rev 25350)
+++ labs/jbosstm/trunk/XTS/sar/tests/src/org/jboss/jbossts/xts/servicetests/test/ATMultiServicePrepareAndCommitTest.java	2009-02-19 18:26:47 UTC (rev 25351)
@@ -36,11 +36,8 @@
  * Starts a transaction and enlist a single participants for each of several web services with instructions to
  * prepare and commit without error
  */
-public class ATMultiServicePrepareAndCommitTest implements XTSServiceTest
+public class ATMultiServicePrepareAndCommitTest extends XTSServiceTestBase implements XTSServiceTest
 {
-    private boolean isSuccessful = false;
-    private Exception exception;
-
     public void run() {
 
         // wait a while so the service has time to start
@@ -170,12 +167,4 @@
 
         isSuccessful = (exception == null);
     }
-
-    public boolean isSuccessful() {
-        return false;  //To change body of implemented methods use File | Settings | File Templates.
-    }
-
-    public Exception getException() {
-        return exception;  //To change body of implemented methods use File | Settings | File Templates.
-    }
 }
\ No newline at end of file

Modified: labs/jbosstm/trunk/XTS/sar/tests/src/org/jboss/jbossts/xts/servicetests/test/ATSingleParticipantPrepareAndCommitTest.java
===================================================================
--- labs/jbosstm/trunk/XTS/sar/tests/src/org/jboss/jbossts/xts/servicetests/test/ATSingleParticipantPrepareAndCommitTest.java	2009-02-19 18:10:48 UTC (rev 25350)
+++ labs/jbosstm/trunk/XTS/sar/tests/src/org/jboss/jbossts/xts/servicetests/test/ATSingleParticipantPrepareAndCommitTest.java	2009-02-19 18:26:47 UTC (rev 25351)
@@ -36,11 +36,8 @@
  * Starts a transaction and enlists a single participant with instructions to prepare and commit
  * without error
  */
-public class ATSingleParticipantPrepareAndCommitTest implements XTSServiceTest
+public class ATSingleParticipantPrepareAndCommitTest extends XTSServiceTestBase implements XTSServiceTest
 {
-    private boolean isSuccessful = false;
-    private Exception exception;
-
     public void run() {
 
         // wait a while so the service has time to start
@@ -126,12 +123,4 @@
 
         isSuccessful = (exception == null);
     }
-
-    public boolean isSuccessful() {
-        return false;  //To change body of implemented methods use File | Settings | File Templates.
-    }
-
-    public Exception getException() {
-        return null;  //To change body of implemented methods use File | Settings | File Templates.
-    }
 }

Copied: labs/jbosstm/trunk/XTS/sar/tests/src/org/jboss/jbossts/xts/servicetests/test/ATSubordinateMultiParticipantPrepareAndCommitTest.java (from rev 25304, labs/jbosstm/trunk/XTS/sar/tests/src/org/jboss/jbossts/xts/servicetests/test/ATMultiParticipantPrepareAndCommitTest.java)
===================================================================
--- labs/jbosstm/trunk/XTS/sar/tests/src/org/jboss/jbossts/xts/servicetests/test/ATSubordinateMultiParticipantPrepareAndCommitTest.java	                        (rev 0)
+++ labs/jbosstm/trunk/XTS/sar/tests/src/org/jboss/jbossts/xts/servicetests/test/ATSubordinateMultiParticipantPrepareAndCommitTest.java	2009-02-19 18:26:47 UTC (rev 25351)
@@ -0,0 +1,225 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA  02110-1301, USA.
+ *
+ * (C) 2009,
+ * @author JBoss Inc.
+ */
+
+package org.jboss.jbossts.xts.servicetests.test;
+
+import org.jboss.jbossts.xts.servicetests.service.XTSServiceTestServiceManager;
+import org.jboss.jbossts.xts.servicetests.client.XTSServiceTestClient;
+import org.jboss.jbossts.xts.servicetests.generated.CommandsType;
+import org.jboss.jbossts.xts.servicetests.generated.ResultsType;
+import com.arjuna.mw.wst11.UserTransactionFactory;
+import com.arjuna.mw.wst11.UserTransaction;
+import com.arjuna.wst.WrongStateException;
+import com.arjuna.wst.SystemException;
+import com.arjuna.wst.TransactionRolledBackException;
+import com.arjuna.wst.UnknownTransactionException;
+
+import java.util.List;
+
+/**
+ * Starts a transaction, enlists a participant with a web service with instructions to prepare and commit
+ * without errot then gets the web service to start a subordinate transaction and enlist several participants
+ * for a second web service in the subtransaction also with instructions to prepare and commit without error
+ */
+public class ATSubordinateMultiParticipantPrepareAndCommitTest extends XTSServiceTestBase implements XTSServiceTest
+{
+    public void run() {
+
+        try {
+            Thread.sleep(5000);
+        } catch (InterruptedException e) {
+            // ignore
+        }
+
+        String serviceURL1;
+        String serviceURL2;
+
+        serviceURL1 = System.getProperty(XTSServiceTest.SERVICE_URL1_KEY);
+
+        if (serviceURL1 == null) {
+            serviceURL1 = "http://localhost:8080/xtstest/xtsservicetest1";
+        }
+
+        serviceURL2 = System.getProperty(XTSServiceTest.SERVICE_URL2_KEY);
+
+        if (serviceURL2 == null) {
+            serviceURL2 = "http://localhost:8080/xtstest/xtsservicetest2";
+        }
+
+        UserTransaction tx = UserTransactionFactory.userTransaction();
+
+        // invoke the service via the client
+
+        XTSServiceTestClient client = new XTSServiceTestClient();
+        CommandsType commands = new CommandsType();
+        ResultsType results = null;
+
+        // wait a while so the service has time to start
+
+        // start the transaction
+
+        try {
+            tx.begin();
+        } catch (WrongStateException e) {
+            exception = e;
+        } catch (SystemException e) {
+            exception = e;
+        }
+
+        if (exception != null) {
+            System.out.println("ATSubordinateMultiParticipantPrepareAndCommitTest : txbegin failure " + exception);
+            return;
+        }
+
+        // invoke the service and tell it to create a subtransaction
+
+        commands = new CommandsType();
+        commands.getCommandList().add("subtransaction");
+
+        try {
+            results = client.serve(serviceURL1, commands);
+        } catch (Exception e) {
+            exception = e;
+        }
+
+        if (exception != null) {
+            System.out.println("ATSubordinateMultiParticipantPrepareAndCommitTest : subtransaction failure " + exception);
+            return;
+        }
+
+        for (String s : results.getResultList()) {
+            System.out.println("ATSubordinateMultiParticipantPrepareAndCommitTest : subtransaction " + s);
+        }
+
+        List<String> resultList = results.getResultList();
+
+        String subTxId = resultList.get(0);
+
+        // enlist a durable participant in the original transaction and tell it to prepare and  commit
+
+        commands = new CommandsType();
+        commands.getCommandList().add("enlistDurable");
+        commands.getCommandList().add("prepare");
+        commands.getCommandList().add("commit");
+
+        // call the web service multiple times
+
+        try {
+            results = client.serve(serviceURL1, commands);
+        } catch (Exception e) {
+            exception = e;
+        }
+
+        if (exception != null) {
+            System.out.println("ATSubordinateMultiParticipantPrepareAndCommitTest : server failure " + exception);
+            return;
+        }
+
+        for (String s : results.getResultList()) {
+            System.out.println("ATSubordinateMultiParticipantPrepareAndCommitTest : enlistDurable " + s);
+        }
+
+        try {
+            results = client.serve(serviceURL1, commands);
+        } catch (Exception e) {
+            exception = e;
+        }
+
+        // enlist a durable participant in the subtransaction and tell it to prepare and  commit
+
+        commands = new CommandsType();
+        commands.getCommandList().add("subtransactioncommands");
+        commands.getCommandList().add(subTxId);
+        commands.getCommandList().add(serviceURL2);
+        commands.getCommandList().add("enlistDurable");
+        commands.getCommandList().add("prepare");
+        commands.getCommandList().add("commit");
+
+        // call the same web service multiple times -- it's ok to use the same commands list
+
+        try {
+            results = client.serve(serviceURL1, commands);
+        } catch (Exception e) {
+            exception = e;
+        }
+
+        if (exception != null) {
+            System.out.println("ATSubordinateMultiParticipantPrepareAndCommitTest : subtransactioncommands failure " + exception);
+            return;
+        }
+
+        for (String s : results.getResultList()) {
+            System.out.println("ATSubordinateMultiParticipantPrepareAndCommitTest : subtransactioncommands " + s);
+        }
+
+        try {
+            results = client.serve(serviceURL1, commands);
+        } catch (Exception e) {
+            exception = e;
+        }
+
+        if (exception != null) {
+            System.out.println("ATSubordinateMultiParticipantPrepareAndCommitTest : subtransactioncommands failure " + exception);
+            return;
+        }
+
+        for (String s : results.getResultList()) {
+            System.out.println("ATSubordinateMultiParticipantPrepareAndCommitTest : subtransactioncommands " + s);
+        }
+
+        try {
+            results = client.serve(serviceURL1, commands);
+        } catch (Exception e) {
+            exception = e;
+        }
+
+        if (exception != null) {
+            System.out.println("ATSubordinateMultiParticipantPrepareAndCommitTest : subtransactioncommands failure " + exception);
+            return;
+        }
+
+        for (String s : results.getResultList()) {
+            System.out.println("ATSubordinateMultiParticipantPrepareAndCommitTest : subtransactioncommands " + s);
+        }
+
+        // now commit the transaction which should also commit the subtransaction
+
+        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) {
+            System.out.println("ATSubordinateMultiParticipantPrepareAndCommitTest : commit failure " + exception);
+        }
+
+        System.out.println("ATSubordinateMultiParticipantPrepareAndCommitTest : completed");
+
+        isSuccessful = (exception == null);
+    }
+}
\ No newline at end of file


Property changes on: labs/jbosstm/trunk/XTS/sar/tests/src/org/jboss/jbossts/xts/servicetests/test/ATSubordinateMultiParticipantPrepareAndCommitTest.java
___________________________________________________________________
Name: svn:mergeinfo
   + 

Modified: labs/jbosstm/trunk/XTS/sar/tests/src/org/jboss/jbossts/xts/servicetests/test/BAMultiParticipantCoordinatorCompletionParticipantCloseAndExitTest.java
===================================================================
--- labs/jbosstm/trunk/XTS/sar/tests/src/org/jboss/jbossts/xts/servicetests/test/BAMultiParticipantCoordinatorCompletionParticipantCloseAndExitTest.java	2009-02-19 18:10:48 UTC (rev 25350)
+++ labs/jbosstm/trunk/XTS/sar/tests/src/org/jboss/jbossts/xts/servicetests/test/BAMultiParticipantCoordinatorCompletionParticipantCloseAndExitTest.java	2009-02-19 18:26:47 UTC (rev 25351)
@@ -40,11 +40,8 @@
  * Starts a transaction and enlists  multipleparticipants with instructions to prepare and commit
  * without error then gets one of them to exit before closing
  */
-public class BAMultiParticipantCoordinatorCompletionParticipantCloseAndExitTest implements XTSServiceTest
+public class BAMultiParticipantCoordinatorCompletionParticipantCloseAndExitTest extends XTSServiceTestBase implements XTSServiceTest
 {
-    private boolean isSuccessful = false;
-    private Exception exception;
-
     public void run() {
 
         // wait a while so the service has time to start
@@ -199,12 +196,4 @@
 
         isSuccessful = (exception == null);
     }
-
-    public boolean isSuccessful() {
-        return isSuccessful;
-    }
-
-    public Exception getException() {
-        return exception;
-    }
 }
\ No newline at end of file

Modified: labs/jbosstm/trunk/XTS/sar/tests/src/org/jboss/jbossts/xts/servicetests/test/BAMultiParticipantCoordinatorCompletionParticipantCloseTest.java
===================================================================
--- labs/jbosstm/trunk/XTS/sar/tests/src/org/jboss/jbossts/xts/servicetests/test/BAMultiParticipantCoordinatorCompletionParticipantCloseTest.java	2009-02-19 18:10:48 UTC (rev 25350)
+++ labs/jbosstm/trunk/XTS/sar/tests/src/org/jboss/jbossts/xts/servicetests/test/BAMultiParticipantCoordinatorCompletionParticipantCloseTest.java	2009-02-19 18:26:47 UTC (rev 25351)
@@ -38,11 +38,8 @@
  * Starts a transaction and enlists mulitple participants swith instructions to prepare and commit
  * without error
  */
-public class BAMultiParticipantCoordinatorCompletionParticipantCloseTest implements XTSServiceTest
+public class BAMultiParticipantCoordinatorCompletionParticipantCloseTest extends XTSServiceTestBase implements XTSServiceTest
 {
-    private boolean isSuccessful = false;
-    private Exception exception;
-
     public void run() {
 
         // wait a while so the service has time to start
@@ -173,12 +170,4 @@
 
         isSuccessful = (exception == null);
     }
-
-    public boolean isSuccessful() {
-        return isSuccessful;
-    }
-
-    public Exception getException() {
-        return exception;
-    }
 }
\ No newline at end of file

Modified: labs/jbosstm/trunk/XTS/sar/tests/src/org/jboss/jbossts/xts/servicetests/test/BAMultiParticipantParticipantCompletionParticipantCloseAndExitTest.java
===================================================================
--- labs/jbosstm/trunk/XTS/sar/tests/src/org/jboss/jbossts/xts/servicetests/test/BAMultiParticipantParticipantCompletionParticipantCloseAndExitTest.java	2009-02-19 18:10:48 UTC (rev 25350)
+++ labs/jbosstm/trunk/XTS/sar/tests/src/org/jboss/jbossts/xts/servicetests/test/BAMultiParticipantParticipantCompletionParticipantCloseAndExitTest.java	2009-02-19 18:26:47 UTC (rev 25351)
@@ -40,11 +40,8 @@
  * Starts a transaction and enlists  multipleparticipants with instructions to prepare and commit
  * without error then gets one of them to exit before closing
  */
-public class BAMultiParticipantParticipantCompletionParticipantCloseAndExitTest implements XTSServiceTest
+public class BAMultiParticipantParticipantCompletionParticipantCloseAndExitTest extends XTSServiceTestBase implements XTSServiceTest
 {
-    private boolean isSuccessful = false;
-    private Exception exception;
-
     public void run() {
 
         // wait a while so the service has time to start
@@ -245,12 +242,4 @@
 
         isSuccessful = (exception == null);
     }
-
-    public boolean isSuccessful() {
-        return isSuccessful;
-    }
-
-    public Exception getException() {
-        return exception;
-    }
 }
\ No newline at end of file

Modified: labs/jbosstm/trunk/XTS/sar/tests/src/org/jboss/jbossts/xts/servicetests/test/BAMultiParticipantParticipantCompletionParticipantCloseTest.java
===================================================================
--- labs/jbosstm/trunk/XTS/sar/tests/src/org/jboss/jbossts/xts/servicetests/test/BAMultiParticipantParticipantCompletionParticipantCloseTest.java	2009-02-19 18:10:48 UTC (rev 25350)
+++ labs/jbosstm/trunk/XTS/sar/tests/src/org/jboss/jbossts/xts/servicetests/test/BAMultiParticipantParticipantCompletionParticipantCloseTest.java	2009-02-19 18:26:47 UTC (rev 25351)
@@ -40,11 +40,8 @@
  * Starts a transaction and enlists mulitple participants swith instructions to prepare and commit
  * without error
  */
-public class BAMultiParticipantParticipantCompletionParticipantCloseTest implements XTSServiceTest
+public class BAMultiParticipantParticipantCompletionParticipantCloseTest extends XTSServiceTestBase implements XTSServiceTest
 {
-    private boolean isSuccessful = false;
-    private Exception exception;
-
     public void run() {
 
         // wait a while so the service has time to start
@@ -244,12 +241,4 @@
 
         isSuccessful = (exception == null);
     }
-
-    public boolean isSuccessful() {
-        return isSuccessful;
-    }
-
-    public Exception getException() {
-        return exception;
-    }
 }
\ No newline at end of file

Modified: labs/jbosstm/trunk/XTS/sar/tests/src/org/jboss/jbossts/xts/servicetests/test/BAMultiServiceCoordinatorCompletionParticipantCloseAndExitTest.java
===================================================================
--- labs/jbosstm/trunk/XTS/sar/tests/src/org/jboss/jbossts/xts/servicetests/test/BAMultiServiceCoordinatorCompletionParticipantCloseAndExitTest.java	2009-02-19 18:10:48 UTC (rev 25350)
+++ labs/jbosstm/trunk/XTS/sar/tests/src/org/jboss/jbossts/xts/servicetests/test/BAMultiServiceCoordinatorCompletionParticipantCloseAndExitTest.java	2009-02-19 18:26:47 UTC (rev 25351)
@@ -40,11 +40,8 @@
  * Starts a transaction and enlists a single participant in each of multiple services with instructions to
  * prepare and commit without error
  */
-public class BAMultiServiceCoordinatorCompletionParticipantCloseAndExitTest implements XTSServiceTest
+public class BAMultiServiceCoordinatorCompletionParticipantCloseAndExitTest extends XTSServiceTestBase implements XTSServiceTest
 {
-    private boolean isSuccessful = false;
-    private Exception exception;
-
     public void run() {
 
         // wait a while so the service has time to start
@@ -211,12 +208,4 @@
 
         isSuccessful = (exception == null);
     }
-
-    public boolean isSuccessful() {
-        return isSuccessful;
-    }
-
-    public Exception getException() {
-        return exception;
-    }
 }
\ No newline at end of file

Modified: labs/jbosstm/trunk/XTS/sar/tests/src/org/jboss/jbossts/xts/servicetests/test/BAMultiServiceCoordinatorCompletionParticipantCloseTest.java
===================================================================
--- labs/jbosstm/trunk/XTS/sar/tests/src/org/jboss/jbossts/xts/servicetests/test/BAMultiServiceCoordinatorCompletionParticipantCloseTest.java	2009-02-19 18:10:48 UTC (rev 25350)
+++ labs/jbosstm/trunk/XTS/sar/tests/src/org/jboss/jbossts/xts/servicetests/test/BAMultiServiceCoordinatorCompletionParticipantCloseTest.java	2009-02-19 18:26:47 UTC (rev 25351)
@@ -38,11 +38,8 @@
  * Starts a transaction and enlists a single participant in each of multiple services with instructions to
  * prepare and commit without error
  */
-public class BAMultiServiceCoordinatorCompletionParticipantCloseTest implements XTSServiceTest
+public class BAMultiServiceCoordinatorCompletionParticipantCloseTest extends XTSServiceTestBase implements XTSServiceTest
 {
-    private boolean isSuccessful = false;
-    private Exception exception;
-
     public void run() {
 
         // wait a while so the service has time to start
@@ -185,12 +182,4 @@
 
         isSuccessful = (exception == null);
     }
-
-    public boolean isSuccessful() {
-        return isSuccessful;
-    }
-
-    public Exception getException() {
-        return exception;
-    }
 }
\ No newline at end of file

Modified: labs/jbosstm/trunk/XTS/sar/tests/src/org/jboss/jbossts/xts/servicetests/test/BAMultiServiceParticipantCompletionParticipantCloseAndExitTest.java
===================================================================
--- labs/jbosstm/trunk/XTS/sar/tests/src/org/jboss/jbossts/xts/servicetests/test/BAMultiServiceParticipantCompletionParticipantCloseAndExitTest.java	2009-02-19 18:10:48 UTC (rev 25350)
+++ labs/jbosstm/trunk/XTS/sar/tests/src/org/jboss/jbossts/xts/servicetests/test/BAMultiServiceParticipantCompletionParticipantCloseAndExitTest.java	2009-02-19 18:26:47 UTC (rev 25351)
@@ -40,11 +40,8 @@
  * Starts a transaction and enlists a single participant in each of multiple services with instructions to
  * prepare and commit without error
  */
-public class BAMultiServiceParticipantCompletionParticipantCloseAndExitTest implements XTSServiceTest
+public class BAMultiServiceParticipantCompletionParticipantCloseAndExitTest extends XTSServiceTestBase implements XTSServiceTest
 {
-    private boolean isSuccessful = false;
-    private Exception exception;
-
     public void run() {
 
         // wait a while so the service has time to start
@@ -256,12 +253,4 @@
 
         isSuccessful = (exception == null);
     }
-
-    public boolean isSuccessful() {
-        return isSuccessful;
-    }
-
-    public Exception getException() {
-        return exception;
-    }
 }
\ No newline at end of file

Modified: labs/jbosstm/trunk/XTS/sar/tests/src/org/jboss/jbossts/xts/servicetests/test/BAMultiServiceParticipantCompletionParticipantCloseTest.java
===================================================================
--- labs/jbosstm/trunk/XTS/sar/tests/src/org/jboss/jbossts/xts/servicetests/test/BAMultiServiceParticipantCompletionParticipantCloseTest.java	2009-02-19 18:10:48 UTC (rev 25350)
+++ labs/jbosstm/trunk/XTS/sar/tests/src/org/jboss/jbossts/xts/servicetests/test/BAMultiServiceParticipantCompletionParticipantCloseTest.java	2009-02-19 18:26:47 UTC (rev 25351)
@@ -40,11 +40,8 @@
  * Starts a transaction and enlists a single participant in each of multiple services with instructions to
  * prepare and commit without error
  */
-public class BAMultiServiceParticipantCompletionParticipantCloseTest implements XTSServiceTest
+public class BAMultiServiceParticipantCompletionParticipantCloseTest extends XTSServiceTestBase implements XTSServiceTest
 {
-    private boolean isSuccessful = false;
-    private Exception exception;
-
     public void run() {
 
         // wait a while so the service has time to start
@@ -257,12 +254,4 @@
 
         isSuccessful = (exception == null);
     }
-
-    public boolean isSuccessful() {
-        return isSuccessful;
-    }
-
-    public Exception getException() {
-        return exception;
-    }
 }
\ No newline at end of file

Modified: labs/jbosstm/trunk/XTS/sar/tests/src/org/jboss/jbossts/xts/servicetests/test/BASingleCoordinatorCompletionParticipantCloseTest.java
===================================================================
--- labs/jbosstm/trunk/XTS/sar/tests/src/org/jboss/jbossts/xts/servicetests/test/BASingleCoordinatorCompletionParticipantCloseTest.java	2009-02-19 18:10:48 UTC (rev 25350)
+++ labs/jbosstm/trunk/XTS/sar/tests/src/org/jboss/jbossts/xts/servicetests/test/BASingleCoordinatorCompletionParticipantCloseTest.java	2009-02-19 18:26:47 UTC (rev 25351)
@@ -38,11 +38,8 @@
  * Starts a transaction and enlists a single participant with instructions to prepare and commit
  * without error
  */
-public class BASingleCoordinatorCompletionParticipantCloseTest implements XTSServiceTest
+public class BASingleCoordinatorCompletionParticipantCloseTest extends XTSServiceTestBase implements XTSServiceTest
 {
-    private boolean isSuccessful = false;
-    private Exception exception;
-
     public void run() {
 
         // wait a while so the service has time to start
@@ -128,12 +125,4 @@
 
         isSuccessful = (exception == null);
     }
-
-    public boolean isSuccessful() {
-        return isSuccessful;
-    }
-
-    public Exception getException() {
-        return exception;
-    }
 }
\ No newline at end of file

Modified: labs/jbosstm/trunk/XTS/sar/tests/src/org/jboss/jbossts/xts/servicetests/test/BASingleParticipantCompletionParticipantCloseTest.java
===================================================================
--- labs/jbosstm/trunk/XTS/sar/tests/src/org/jboss/jbossts/xts/servicetests/test/BASingleParticipantCompletionParticipantCloseTest.java	2009-02-19 18:10:48 UTC (rev 25350)
+++ labs/jbosstm/trunk/XTS/sar/tests/src/org/jboss/jbossts/xts/servicetests/test/BASingleParticipantCompletionParticipantCloseTest.java	2009-02-19 18:26:47 UTC (rev 25351)
@@ -40,11 +40,8 @@
  * Starts a transaction and enlists a single participant with instructions to prepare and commit
  * without error
  */
-public class BASingleParticipantCompletionParticipantCloseTest implements XTSServiceTest
+public class BASingleParticipantCompletionParticipantCloseTest extends XTSServiceTestBase implements XTSServiceTest
 {
-    private boolean isSuccessful = false;
-    private Exception exception;
-
     public void run() {
 
         // wait a while so the service has time to start
@@ -157,12 +154,4 @@
 
         isSuccessful = (exception == null);
     }
-
-    public boolean isSuccessful() {
-        return isSuccessful;
-    }
-
-    public Exception getException() {
-        return exception;
-    }
 }
\ No newline at end of file

Added: labs/jbosstm/trunk/XTS/sar/tests/src/org/jboss/jbossts/xts/servicetests/test/XTSServiceTestBase.java
===================================================================
--- labs/jbosstm/trunk/XTS/sar/tests/src/org/jboss/jbossts/xts/servicetests/test/XTSServiceTestBase.java	                        (rev 0)
+++ labs/jbosstm/trunk/XTS/sar/tests/src/org/jboss/jbossts/xts/servicetests/test/XTSServiceTestBase.java	2009-02-19 18:26:47 UTC (rev 25351)
@@ -0,0 +1,24 @@
+package org.jboss.jbossts.xts.servicetests.test;
+
+/**
+ * Class providing default behaviour for specific XTSServiceTest implementations
+ */
+public class XTSServiceTestBase
+{
+    protected boolean isSuccessful;
+    protected Exception exception;
+
+    protected XTSServiceTestBase()
+    {
+        isSuccessful = false;
+        exception = null;
+    }
+
+    public boolean isSuccessful() {
+        return isSuccessful;  //To change body of implemented methods use File | Settings | File Templates.
+    }
+
+    public Exception getException() {
+        return exception;  //To change body of implemented methods use File | Settings | File Templates.
+    }
+}




More information about the jboss-svn-commits mailing list