[jboss-cvs] JBossAS SVN: r80992 - in trunk/testsuite/src: main/org/jboss/test/cluster/invokerha and 2 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri Nov 14 03:57:47 EST 2008


Author: galder.zamarreno at jboss.com
Date: 2008-11-14 03:57:47 -0500 (Fri, 14 Nov 2008)
New Revision: 80992

Modified:
   trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/test/JRMPInvokerHaTransactionStickyUnitTestCase.java
   trunk/testsuite/src/main/org/jboss/test/cluster/invokerha/AbstractInvokerHa.java
   trunk/testsuite/src/main/org/jboss/test/cluster/invokerha/AbstractInvokerHaTransactionSticky.java
   trunk/testsuite/src/main/org/jboss/test/cluster/invokerha/InvokerHaFailureType.java
   trunk/testsuite/src/main/org/jboss/test/cluster/invokerha/InvokerHaInfrastructure.java
   trunk/testsuite/src/main/org/jboss/test/cluster/invokerha/InvokerHaTransactionalMockUtils.java
   trunk/testsuite/src/main/org/jboss/test/cluster/invokerha/JRMPInvokerHaMockUtils.java
   trunk/testsuite/src/main/org/jboss/test/cluster/invokerha/UnifiedInvokerHaMockUtils.java
   trunk/testsuite/src/resources/cluster/ejb2/ustxsticky/META-INF/jboss.xml
   trunk/testsuite/src/resources/test-configs/ustxsticky/deploy/transaction-service.xml
Log:
[JBAS-6194] Fixed standalone unit tests so that a client user transaction is now used that uses one of the sticky interceptors. Bean invocations now go past the EJB sticky interceptor too. Finally, modified descriptors for in-server unit test.

Modified: trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/test/JRMPInvokerHaTransactionStickyUnitTestCase.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/test/JRMPInvokerHaTransactionStickyUnitTestCase.java	2008-11-14 08:55:44 UTC (rev 80991)
+++ trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/test/JRMPInvokerHaTransactionStickyUnitTestCase.java	2008-11-14 08:57:47 UTC (rev 80992)
@@ -23,6 +23,9 @@
 
 import java.util.List;
 
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
 import org.jboss.invocation.InvokerHA;
 import org.jboss.test.cluster.defaultcfg.test.JRMPInvokerHaUnitTestCase.JRMPInvokerHaFactory;
 import org.jboss.test.cluster.invokerha.AbstractInvokerHaTransactionSticky;
@@ -62,4 +65,12 @@
          return "TX_STICKY_TARGET";
       }
    }
+   
+   public static Test suite() 
+   {
+      /* No transactions to be run for JRMP invoker version of transaction 
+       * sticky functionality because this old legacy invoker is no longer 
+       * supported for transaction sticky functionality. */
+      return new TestSuite();
+   }
 }

Modified: trunk/testsuite/src/main/org/jboss/test/cluster/invokerha/AbstractInvokerHa.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/cluster/invokerha/AbstractInvokerHa.java	2008-11-14 08:55:44 UTC (rev 80991)
+++ trunk/testsuite/src/main/org/jboss/test/cluster/invokerha/AbstractInvokerHa.java	2008-11-14 08:57:47 UTC (rev 80992)
@@ -65,6 +65,8 @@
    
    Invoker systemTimeProxy;
    
+   Invoker clientUserTransactionProxy;
+   
    Object prevChosenTargetDateTimeTeller;
    
    Object prevChosenTargetSystemTimeTeller;
@@ -87,9 +89,11 @@
       
       infrastructure.createDateTimeTeller();
       infrastructure.createSystemTimeTeller();
+      infrastructure.createClientUserTransactionService();
 
       infrastructure.deployDateTimeTeller();
       infrastructure.deploySystemTimeTeller();
+      infrastructure.deployClientUserTransactionService();
    }
 
    @Override
@@ -101,6 +105,7 @@
       
       infrastructure.undeployDateTimeTeller();
       infrastructure.undeploySystemTimeTeller();
+      infrastructure.undeployClientUserTransactionService();
       
       infrastructure.undeployServers();
    }
@@ -181,14 +186,14 @@
       for (int i = 0; i < numberPairCalls; i++)
       {
          /* create invocation to date time teller */
-         inv = infrastructure.createDateTimeTellerInvocation(tx, null);
+         inv = infrastructure.createDateTimeTellerInvocation(tx, null, timeTellerProxy);
          /* invoke on proxy passing the invocation */
          log.debug(timeTellerProxy.invoke(inv));
          /* assert post conditions after invocation */
          prevChosenTargetDateTimeTeller = assertSuccessfulPostConditions(inv, prevChosenTargetDateTimeTeller, tx, policyClass);
          
          /* create invocation to system time teller */
-         inv = infrastructure.createSystemTimeTellerInvocation(tx, null);
+         inv = infrastructure.createSystemTimeTellerInvocation(tx, null, systemTimeProxy);
          /* invoke on proxy passing the invocation */
          log.debug(systemTimeProxy.invoke(inv));
          /* assert post conditions after invocation */
@@ -247,6 +252,7 @@
       /* Create a proxy instances retrieved from the first server */
       timeTellerProxy = infrastructure.createDateTimeTellerProxy(serverIndex, policyClass);
       systemTimeProxy = infrastructure.createSystemTimeTellerProxy(serverIndex, policyClass);
+      clientUserTransactionProxy = infrastructure.createClientUserTransactionProxy(serverIndex, policyClass);
       
       /* Initialise previous chosen targets. If not new proxies elected 
        * between transactions, this allows to carry on checking chosen 
@@ -360,14 +366,14 @@
          for (int i = 0; i < numberPairCalls; i++)
          {
             /* create invocation to date time teller */
-            inv = infrastructure.createDateTimeTellerInvocation(null, null);
+            inv = infrastructure.createDateTimeTellerInvocation(null, null, timeTellerProxy);
             /* invoke on proxy passing the invocation */
             log.debug(timeTellerProxy.invoke(inv));
             /* assert post conditions after invocation */
             assertThreadSafePostConditions(inv, timeTellerProxy);
             
             /* create invocation to system time teller */
-            inv = infrastructure.createSystemTimeTellerInvocation(null, null);
+            inv = infrastructure.createSystemTimeTellerInvocation(null, null, systemTimeProxy);
             /* invoke on proxy passing the invocation */
             log.debug(systemTimeProxy.invoke(inv));
             /* assert post conditions after invocation */

Modified: trunk/testsuite/src/main/org/jboss/test/cluster/invokerha/AbstractInvokerHaTransactionSticky.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/cluster/invokerha/AbstractInvokerHaTransactionSticky.java	2008-11-14 08:55:44 UTC (rev 80991)
+++ trunk/testsuite/src/main/org/jboss/test/cluster/invokerha/AbstractInvokerHaTransactionSticky.java	2008-11-14 08:57:47 UTC (rev 80992)
@@ -21,13 +21,13 @@
  */
 package org.jboss.test.cluster.invokerha;
 
-import java.rmi.server.UID;
 import java.util.ArrayList;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
 
 import javax.transaction.Transaction;
+import javax.transaction.UserTransaction;
 
 import org.jboss.ha.framework.interfaces.LoadBalancePolicy;
 import org.jboss.ha.framework.interfaces.TransactionStickyFirstAvailable;
@@ -35,10 +35,12 @@
 import org.jboss.ha.framework.interfaces.TransactionStickyRandomRobin;
 import org.jboss.ha.framework.interfaces.TransactionStickyRoundRobin;
 import org.jboss.invocation.Invocation;
+import org.jboss.invocation.Invoker;
 import org.jboss.invocation.InvokerProxyHA;
 import org.jboss.invocation.ServiceUnavailableException;
 import org.jboss.logging.Logger;
-import org.jboss.test.cluster.invokerha.InvokerHaTransactionalMockUtils.MockTransaction;
+import org.jboss.test.cluster.invokerha.InvokerHaTransactionalMockUtils.MockUserTransaction;
+import org.jboss.test.cluster.invokerha.InvokerHaTransactionalMockUtils.MockTransactionStickyInterceptor;
 
 /**
  * AbstractInvokerHaTransactionSticky.
@@ -161,28 +163,23 @@
       
       try
       {
-         UID uid;
-         
          createNewProxies(0, policyClass, true);
 
-         /* Simulate client user transaction */
-         uid = new UID();         
-         transactionalMockUtils.getTpcf().setUid(uid);
+         UserTransaction ut = new MockUserTransaction(clientUserTransactionProxy, infrastructure);
+         ut.begin();
          performTransactionalStickyCalls(3, null, policyClass, newProxiesInBetweenTransactions);
+         ut.commit();
          /* either set would do because they should be the same */
-         Set<Object> chosenTargetsTx1 = chosenTargets;
+         Set<Object> chosenTargetsTx1 = chosenTargets;;
          
          if (newProxiesInBetweenTransactions)
          {
             createNewProxies(0, policyClass, false);
          }
          
-         /* Simulate transaction interceptor */
-         uid = new UID();
-         Transaction tx = new MockTransaction();
-         transactionalMockUtils.getTpcf().setUid(uid);
-         transactionalMockUtils.getTpci().setTransaction(tx);
-         performTransactionalStickyCalls(3, tx, policyClass, newProxiesInBetweenTransactions);
+         ut.begin();
+         performTransactionalStickyCalls(3, null, policyClass, newProxiesInBetweenTransactions);
+         ut.commit();
          /* either set would do because they should be the same */
          Set<Object> chosenTargetsTx2 = chosenTargets;
          
@@ -204,10 +201,11 @@
       
       try
       {
-         UID uid = new UID();
          createNewProxies(0, policyClass, true);
-         transactionalMockUtils.getTpcf().setUid(uid);
+         UserTransaction ut = new MockUserTransaction(clientUserTransactionProxy, infrastructure);
+         ut.begin();
          performTransactionalCallsWithNodeShutdown(null, policyClass);
+         ut.commit();
       }
       catch(Exception e)
       {
@@ -247,16 +245,16 @@
       for (int i = 0; i < numberPairCalls; i++)
       {
          /* create invocation to date time teller */
-         inv = infrastructure.createDateTimeTellerInvocation(tx, null);
+         inv = infrastructure.createDateTimeTellerInvocation(tx, null, timeTellerProxy);
          /* invoke on proxy passing the invocation */
-         log.debug(timeTellerProxy.invoke(inv));
+         log.debug(invokeTimeTellerProxy(inv));
          /* assert post conditions after invocation */
          chosenTargetsDateTimeTeller = assertSuccessfulPostConditions(inv, chosenTargetsDateTimeTeller);
          
          /* create invocation to system time teller */
-         inv = infrastructure.createSystemTimeTellerInvocation(tx, null);
+         inv = infrastructure.createSystemTimeTellerInvocation(tx, null, systemTimeProxy);
          /* invoke on proxy passing the invocation */
-         log.debug(systemTimeProxy.invoke(inv));
+         log.debug(invokeSystemTimeProxy(inv));
          /* assert post conditions after invocation */
          chosenTargetsSystemTimeTeller = assertSuccessfulPostConditions(inv, chosenTargetsSystemTimeTeller);
       }
@@ -289,25 +287,25 @@
       Set<Object> chosenTargetsDateTimeTeller = new HashSet<Object>(1);
       
       /* create invocation to date time teller */
-      inv = infrastructure.createDateTimeTellerInvocation(tx, null);
+      inv = infrastructure.createDateTimeTellerInvocation(tx, null, timeTellerProxy);
       /* invoke on proxy passing the invocation */
-      log.debug(timeTellerProxy.invoke(inv));
+      log.debug(invokeTimeTellerProxy(inv));
       /* assert post conditions after invocation */
       chosenTargetsDateTimeTeller = assertSuccessfulPostConditions(inv, chosenTargetsDateTimeTeller);
       
       List<Object> newReplicants = undeployChosenTargetNode(chosenTargetsDateTimeTeller.toArray()[0]);      
       ((InvokerProxyHA)timeTellerProxy).updateClusterInfo((ArrayList<Object>)newReplicants, 3);
       
-      inv = infrastructure.createDateTimeTellerInvocation(tx, null);
+      inv = infrastructure.createDateTimeTellerInvocation(tx, null, timeTellerProxy);
       try
       {
-         log.debug(timeTellerProxy.invoke(inv));
+         log.debug(invokeTimeTellerProxy(inv));
          fail("Should have thrown an exception because sticky target is no longer available");
       }
       catch(Exception e)
       {
          log.debug("Expected exception", e);
-         assertTrue(e instanceof ServiceUnavailableException || e.getCause() instanceof ServiceUnavailableException);
+         assertTrue(e.getCause() instanceof ServiceUnavailableException);
       }
    }
    
@@ -356,7 +354,10 @@
       try 
       {
          /* fail in 1st call */
+         UserTransaction ut = new MockUserTransaction(clientUserTransactionProxy, infrastructure);
+         ut.begin();
          failureCall(failureType, true, policyClass, newProxiesInBetweenFailures);
+         ut.commit();
          
          if (newProxiesInBetweenFailures)
          {
@@ -364,7 +365,9 @@
          }
          
          /* fail in Nth call */
+         ut.begin();
          failureCall(failureType, false, policyClass, newProxiesInBetweenFailures);
+         ut.commit();
       }
       catch(Exception e)
       {
@@ -377,38 +380,31 @@
    
    protected void failureCall(InvokerHaFailureType failureType, boolean injectFailureIn1stCall, Class<? extends LoadBalancePolicy> policyClass, boolean newProxiesInBetweenFailures) throws Exception
    {
-      UID uid;
       Invocation inv;
       
       if (injectFailureIn1stCall)
       {
-         uid = new UID();         
-         transactionalMockUtils.getTpcf().setUid(uid);
          /* When failure must happen in the very 1st call, we create a 1st 
           * invocation with the failure injected */
-         inv = infrastructure.createDateTimeTellerInvocation(null, failureType);         
+         inv = infrastructure.createDateTimeTellerInvocation(null, failureType, timeTellerProxy);         
       }
       else
       {
-         uid = new UID();
-         Transaction tx = new MockTransaction();
-         transactionalMockUtils.getTpcf().setUid(uid);
-         transactionalMockUtils.getTpci().setTransaction(tx);
          /* When failure is not in first call, we do a call to each bean before 
           * injecting the faliure */
-         performTransactionalStickyCalls(1, tx, policyClass, newProxiesInBetweenFailures);
+         performTransactionalStickyCalls(1, null, policyClass, newProxiesInBetweenFailures);
          /* Now we create the invocation with the failure injected */
-         inv = infrastructure.createDateTimeTellerInvocation(null, failureType);
+         inv = infrastructure.createDateTimeTellerInvocation(null, failureType, timeTellerProxy);
       }
       
       try 
       {
-         log.debug(timeTellerProxy.invoke(inv));
+         log.debug(invokeTimeTellerProxy(inv));
          if (failureType.isRecoverable(injectFailureIn1stCall))
          {
             failureType.assertFailoverCounter(injectFailureIn1stCall, inv.getAsIsValue("FAILOVER_COUNTER"));
-            inv = infrastructure.createDateTimeTellerInvocation(null, null);
-            log.debug(timeTellerProxy.invoke(inv));
+            inv = infrastructure.createDateTimeTellerInvocation(null, null, timeTellerProxy);
+            log.debug(invokeTimeTellerProxy(inv));
          }
          else
          {
@@ -417,6 +413,7 @@
       }
       catch (Exception e)
       {
+         log.debug("Exception (could be expected) during failure call testing", e);
          if (failureType.isRecoverable(injectFailureIn1stCall))
          {
             fail("should have failed, failover is not allowed for " + failureType);
@@ -425,9 +422,31 @@
          {
             assertNull("transaction on the client side should be null", inv.getTransaction());
             failureType.assertFailoverCounter(injectFailureIn1stCall, inv.getAsIsValue("FAILOVER_COUNTER"));
-            failureType.assertException(e);                        
+            failureType.assertException(e.getCause());                        
          }
       }
    }
 
-}
+   protected Object invokeTimeTellerProxy(Invocation inv) throws Exception
+   {
+      return invokeProxy(timeTellerProxy, inv);      
+   }
+   
+   protected Object invokeSystemTimeProxy(Invocation inv) throws Exception
+   {
+      return invokeProxy(systemTimeProxy, inv);      
+   }
+   
+   protected Object invokeProxy(Invoker invoker, Invocation inv) throws Exception
+   {
+      try
+      {
+         return new MockTransactionStickyInterceptor(invoker).invoke(inv);
+      }
+      catch(Throwable t)
+      {
+         throw new Exception("Throwable", t);
+      }
+            
+   }
+}
\ No newline at end of file

Modified: trunk/testsuite/src/main/org/jboss/test/cluster/invokerha/InvokerHaFailureType.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/cluster/invokerha/InvokerHaFailureType.java	2008-11-14 08:55:44 UTC (rev 80991)
+++ trunk/testsuite/src/main/org/jboss/test/cluster/invokerha/InvokerHaFailureType.java	2008-11-14 08:57:47 UTC (rev 80992)
@@ -53,14 +53,8 @@
             return false;
             
          case AFTER_SERVER_NOT_COMPLETED_BUT_SUCCESS_AFTER:
-            /* - if failure happens after reaching the server but didn't complete, and 
-             * it happens in the 1st transactional invocation, it's recoverable as 
-             * long as the failover call succeeds, otherwise (Nth invocation) it's 
-             * not recoverable. */
-            if (injectFailureIn1stCall)
-            {
-               return true;
-            }
+            /* it is not recoverable because UserTransaction.begin() already 
+             * reached a server.*/
             return false;
             
          case AFTER_SERVER_NOT_COMPLETED_BOTH_SERVERS:
@@ -122,7 +116,7 @@
       switch(this)
       {
          case BEFORE_SERVER:
-            TestCase.assertEquals(Integer.valueOf(0), failoverCounter);
+            TestCase.assertNull(failoverCounter);
             break;
             
          case AFTER_SERVER_NOT_COMPLETED_BUT_SUCCESS_AFTER:
@@ -130,18 +124,10 @@
             break;
             
          case AFTER_SERVER_NOT_COMPLETED_BOTH_SERVERS:
-            if (injectFailureIn1stCall)
-            {
-               /* Two failovers were attempted before finally giving up */
-               TestCase.assertEquals(Integer.valueOf(2), failoverCounter);
-            }
-            else
-            {
-               /* It's 1 because after several calls, the transaction has 
-                * already reached the server, so that's good enough not to 
-                * succeed */
-               TestCase.assertEquals(Integer.valueOf(1), failoverCounter);
-            }
+            /* Only one attempted failover because it won't be available to 
+             * failover due to UserTransaction.begin() having already hit the 
+             * server and hence, txFailoverAuthorization maps contains that tpc. */ 
+            TestCase.assertEquals(1, failoverCounter);
             break;
             
          case AFTER_SERVER_COMPLETED:
@@ -155,23 +141,23 @@
       }
    }
    
-   public void assertException(Exception e)
+   public void assertException(Throwable t)
    {
       switch(this) 
       {
          case BEFORE_SERVER:
-            TestCase.assertTrue(e instanceof IllegalStateException);
+            TestCase.assertTrue(t instanceof IllegalStateException);
             break;
             
          case AFTER_SERVER_NOT_COMPLETED_BUT_SUCCESS_AFTER:
          case AFTER_SERVER_NOT_COMPLETED_BOTH_SERVERS:
-            TestCase.assertTrue(e instanceof ServiceUnavailableException);
-            TestCase.assertTrue(e.getCause() instanceof GenericClusteringException);
+            TestCase.assertTrue(t instanceof ServiceUnavailableException);
+            TestCase.assertTrue(t.getCause() instanceof GenericClusteringException);
             break;
             
          case AFTER_SERVER_COMPLETED:
-            TestCase.assertTrue(e instanceof ServerException);
-            TestCase.assertTrue(e.getCause() instanceof GenericClusteringException);
+            TestCase.assertTrue(t instanceof ServerException);
+            TestCase.assertTrue(t.getCause() instanceof GenericClusteringException);
             break;
       }
    }

Modified: trunk/testsuite/src/main/org/jboss/test/cluster/invokerha/InvokerHaInfrastructure.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/cluster/invokerha/InvokerHaInfrastructure.java	2008-11-14 08:55:44 UTC (rev 80991)
+++ trunk/testsuite/src/main/org/jboss/test/cluster/invokerha/InvokerHaInfrastructure.java	2008-11-14 08:57:47 UTC (rev 80992)
@@ -23,6 +23,7 @@
 
 import java.io.Serializable;
 import java.lang.management.ManagementFactory;
+import java.rmi.server.UID;
 import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
@@ -43,6 +44,7 @@
 import org.jboss.ha.framework.interfaces.RoundRobin;
 import org.jboss.ha.framework.server.HATarget;
 import org.jboss.invocation.Invocation;
+import org.jboss.invocation.InvocationContext;
 import org.jboss.invocation.Invoker;
 import org.jboss.invocation.InvokerHA;
 import org.jboss.logging.Logger;
@@ -70,10 +72,14 @@
    
    private final ObjectName systemTimeTellerON;
    
+   private final ObjectName clientUserTransactionServiceON;
+   
    private final Integer dateTimeTellerONHashCode;
    
    private final Integer systemTimeTellerONHashCode;
    
+   private final Integer clientUserTransactionServiceONHashCode;
+   
    private final int serverCount;
    
    private List<? extends InvokerHA> replicants;
@@ -96,8 +102,10 @@
          /* initialise ObjectNames and hashcodes */
          dateTimeTellerON = new ObjectName("com.acme.mbeans:type=DateTimeTeller");
          systemTimeTellerON = new ObjectName("com.acme.mbeans:type=SystemTimeTeller");
+         clientUserTransactionServiceON = new ObjectName("com.acme.mbeans:type=ClientUserTransactionService");
          dateTimeTellerONHashCode = new Integer(dateTimeTellerON.hashCode());
          systemTimeTellerONHashCode = new Integer(systemTimeTellerON.hashCode());
+         clientUserTransactionServiceONHashCode = new Integer(clientUserTransactionServiceON.hashCode());
    
          /* create a list of object names for the invoker endpoints */
          invokerONs = new ArrayList<ObjectName>(this.serverCount);
@@ -120,6 +128,7 @@
    {
       Registry.bind(dateTimeTellerONHashCode, dateTimeTellerON);
       Registry.bind(systemTimeTellerONHashCode, systemTimeTellerON);
+      Registry.bind(clientUserTransactionServiceONHashCode, clientUserTransactionServiceON);      
    }
 
    /** 
@@ -169,6 +178,13 @@
       return systemTimeTellerMBean;
    }
    
+   public ClientUserTransactionService createClientUserTransactionService() throws Exception
+   {
+      ClientUserTransactionService clientUserTransactionServiceMBean = new ClientUserTransactionService();
+      mbs.registerMBean(clientUserTransactionServiceMBean, clientUserTransactionServiceON);
+      return clientUserTransactionServiceMBean;
+   }   
+   
    /**
     * Deploy date time teller mbean in each server, or invoker endpoint, 
     * creating a mock HATarget with the list of replicants and associating the 
@@ -189,6 +205,11 @@
       deploy(replicants, systemTimeTellerON, "SystemTimeTellerReplicant");
    }
    
+   public void deployClientUserTransactionService() throws Exception
+   {
+      deploy(replicants, clientUserTransactionServiceON, "ClientUserTransactionServiceReplicant");
+   }   
+   
    /**
     * Create a proxy to date time teller bean.
     * 
@@ -217,6 +238,12 @@
       InvokerHA server = replicants.get(serverIndex);
       return server.createProxy(systemTimeTellerON, policyClass.newInstance(), "UnitTestPartition/SystemTimeTellerMBean");
    }
+
+   public Invoker createClientUserTransactionProxy(int serverIndex, Class<? extends LoadBalancePolicy> policyClass) throws Exception
+   {
+      InvokerHA server = replicants.get(serverIndex);
+      return server.createProxy(clientUserTransactionServiceON, policyClass.newInstance(), "UnitTestPartition/ClientUserTransactionServiceMBean");
+   }   
    
    /**
     * Create a new invocation for date time teller mbean 
@@ -228,9 +255,9 @@
     * injected.
     * @return
     */
-   public Invocation createDateTimeTellerInvocation(Transaction tx, InvokerHaFailureType failureType)
+   public Invocation createDateTimeTellerInvocation(Transaction tx, InvokerHaFailureType failureType, Invoker invoker)
    {
-      return createInvocation(tx, dateTimeTellerONHashCode, failureType);
+      return createInvocation(tx, dateTimeTellerONHashCode, failureType, invoker);
    }
    
    /**
@@ -241,11 +268,16 @@
     * in non managed environments.
     * @return
     */
-   public Invocation createSystemTimeTellerInvocation(Transaction tx, InvokerHaFailureType failureType)
+   public Invocation createSystemTimeTellerInvocation(Transaction tx, InvokerHaFailureType failureType, Invoker invoker)
    {
-      return createInvocation(tx, systemTimeTellerONHashCode, failureType);
+      return createInvocation(tx, systemTimeTellerONHashCode, failureType, invoker);
    }  
    
+   public Invocation createClientUserTransactionInvocation(Transaction tx, InvokerHaFailureType failureType, Invoker invoker)
+   {
+      return createInvocation(tx, clientUserTransactionServiceONHashCode, failureType, invoker);
+   } 
+   
    /**
     * Unbind mbean object name hashcodes from JMX registry.
     */
@@ -254,6 +286,7 @@
       /* Unregister from the JMX registry */
       Registry.unbind(dateTimeTellerONHashCode);
       Registry.unbind(systemTimeTellerONHashCode);      
+      Registry.unbind(clientUserTransactionServiceONHashCode);
    }
    
    /**
@@ -274,6 +307,12 @@
       undeploy(replicants, systemTimeTellerON);
    }
    
+
+   public void undeployClientUserTransactionService() throws Exception
+   {
+      undeploy(replicants, clientUserTransactionServiceON);
+   }
+   
    /**
     * Unregister invoker endpoints from mbean server.
     */
@@ -335,7 +374,7 @@
     * @param hashCode hashcode of object name of the mbean
     * @return
     */
-   private Invocation createInvocation(Transaction tx, Integer hashCode, InvokerHaFailureType failureType)
+   private Invocation createInvocation(Transaction tx, Integer hashCode, InvokerHaFailureType failureType, Invoker invoker)
    {
       Invocation inv = new Invocation();
       inv.setObjectName(hashCode);
@@ -347,6 +386,11 @@
       {
          inv.setValue("FAILURE_TYPE", failureType);
       }
+
+      InvocationContext ctx = new InvocationContext();
+      ctx.setInvoker(invoker);
+      inv.setInvocationContext(ctx);
+      
       return inv;
    }
       
@@ -413,6 +457,11 @@
       Object invoke(Invocation invocation) throws Exception;
    }
    
+   public interface ClientUserTransactionServiceMBean
+   {
+      Object invoke(Invocation invocation) throws Exception;      
+   }
+   
    /** Classes **/
    
    public class DateTimeTeller implements DateTimeTellerMBean
@@ -433,6 +482,15 @@
       }      
    }
    
+   public class ClientUserTransactionService implements ClientUserTransactionServiceMBean
+   {
+      public Object invoke(Invocation invocation) throws Exception
+      {
+         // Return new tpc -> only begin() calls really tested as they set the sticky target
+         return new UID();
+      }
+   }
+   
    /**
     * MockHATarget class that avoids using DistributedReplicantManager in any 
     * way. The unit test will force changes in the composition of replicants, 

Modified: trunk/testsuite/src/main/org/jboss/test/cluster/invokerha/InvokerHaTransactionalMockUtils.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/cluster/invokerha/InvokerHaTransactionalMockUtils.java	2008-11-14 08:55:44 UTC (rev 80991)
+++ trunk/testsuite/src/main/org/jboss/test/cluster/invokerha/InvokerHaTransactionalMockUtils.java	2008-11-14 08:57:47 UTC (rev 80992)
@@ -25,12 +25,20 @@
 
 import javax.transaction.HeuristicMixedException;
 import javax.transaction.HeuristicRollbackException;
+import javax.transaction.NotSupportedException;
 import javax.transaction.RollbackException;
 import javax.transaction.Synchronization;
 import javax.transaction.SystemException;
 import javax.transaction.Transaction;
+import javax.transaction.UserTransaction;
 import javax.transaction.xa.XAResource;
 
+import org.jboss.invocation.Invocation;
+import org.jboss.invocation.Invoker;
+import org.jboss.invocation.InvokerInterceptor;
+import org.jboss.proxy.ClientUserTransactionStickyInterceptor;
+import org.jboss.proxy.Interceptor;
+import org.jboss.proxy.TransactionStickyInterceptor;
 import org.jboss.tm.TransactionPropagationContextFactory;
 import org.jboss.tm.TransactionPropagationContextImporter;
 import org.jboss.tm.TransactionPropagationContextUtil;
@@ -42,7 +50,7 @@
  */
 public class InvokerHaTransactionalMockUtils
 {
-   private MockTransactionPropagationContextFactory tpcf;
+   private static MockTransactionPropagationContextFactory tpcf;
    
    private MockTransactionPropagationContextImporter tpci;   
    
@@ -155,4 +163,104 @@
       }
    }
 
+   public static class MockUserTransaction implements UserTransaction
+   {
+      private Invoker invoker;
+      
+      private InvokerHaInfrastructure infrastructure; 
+      
+      public MockUserTransaction(Invoker invoker, InvokerHaInfrastructure infrastructure)
+      {
+         this.invoker = invoker;
+         this.infrastructure = infrastructure;
+      }
+
+      public void begin() throws NotSupportedException, SystemException
+      {
+         try
+         {
+            Invocation inv = infrastructure.createClientUserTransactionInvocation(null, null, invoker);
+            UID uid = (UID) new MockClientUserTransactionStickyInterceptor(invoker).invoke(inv);
+            tpcf.setUid(uid);
+         }
+         catch (Throwable e)
+         {
+            throw new RuntimeException("Exception during mock UT.begin", e);
+         }
+      }
+
+      public void commit() throws RollbackException, HeuristicMixedException, HeuristicRollbackException,
+            SecurityException, IllegalStateException, SystemException
+      {
+         tpcf.setUid(null);
+      }
+
+      public int getStatus() throws SystemException
+      {
+         return 0;
+      }
+
+      public void rollback() throws IllegalStateException, SecurityException, SystemException
+      {
+      }
+
+      public void setRollbackOnly() throws IllegalStateException, SystemException
+      {
+      }
+
+      public void setTransactionTimeout(int seconds) throws SystemException
+      {
+      }
+   }
+   
+   public static class MockClientUserTransactionStickyInterceptor extends ClientUserTransactionStickyInterceptor
+   {
+      private Invoker invoker;
+      
+      public MockClientUserTransactionStickyInterceptor(Invoker invoker)
+      {
+         this.invoker = invoker;
+      }
+
+      @Override
+      public Interceptor getNext()
+      {
+         InvokerInterceptor.setLocal(invoker);
+         
+         return new InvokerInterceptor()
+         {
+            @Override
+            public boolean isLocal(Invocation invocation)
+            {
+               return true;
+            }
+         };
+      }
+   }
+   
+   public static class MockTransactionStickyInterceptor extends TransactionStickyInterceptor
+   {
+      private Invoker invoker;
+            
+      public MockTransactionStickyInterceptor(Invoker invoker)
+      {
+         this.invoker = invoker;
+      }
+
+      @Override
+      public Interceptor getNext()
+      {
+         InvokerInterceptor.setLocal(invoker);
+         
+         return new InvokerInterceptor()
+         {
+            @Override
+            public boolean isLocal(Invocation invocation)
+            {
+               return true;
+            }
+         };
+      }
+   }
+   
 }

Modified: trunk/testsuite/src/main/org/jboss/test/cluster/invokerha/JRMPInvokerHaMockUtils.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/cluster/invokerha/JRMPInvokerHaMockUtils.java	2008-11-14 08:55:44 UTC (rev 80991)
+++ trunk/testsuite/src/main/org/jboss/test/cluster/invokerha/JRMPInvokerHaMockUtils.java	2008-11-14 08:57:47 UTC (rev 80992)
@@ -123,18 +123,6 @@
       {
          return super.invoke(invocation);
       }
-      
-      @Override
-      protected void putIfExistsTransactionTarget(Invocation invocation, Object tpc) throws Exception
-      {
-         InvokerHaFailureType failureType = (InvokerHaFailureType)invocation.getValue("FAILURE_TYPE");
-         if (failureType != null)
-         {
-            failureType.injectFailureIfExistsBeforeServer();
-         }
-         
-         super.putIfExistsTransactionTarget(invocation, tpc);
-      }
    }
 
 }

Modified: trunk/testsuite/src/main/org/jboss/test/cluster/invokerha/UnifiedInvokerHaMockUtils.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/cluster/invokerha/UnifiedInvokerHaMockUtils.java	2008-11-14 08:55:44 UTC (rev 80991)
+++ trunk/testsuite/src/main/org/jboss/test/cluster/invokerha/UnifiedInvokerHaMockUtils.java	2008-11-14 08:57:47 UTC (rev 80992)
@@ -130,7 +130,7 @@
       }
 
       @Override
-      protected void putIfExistsTransactionTarget(Invocation invocation, Object tpc) throws Exception
+      public Object invoke(Invocation invocation) throws Exception
       {
          InvokerHaFailureType failureType = (InvokerHaFailureType)invocation.getValue("FAILURE_TYPE");
          if (failureType != null)
@@ -138,7 +138,7 @@
             failureType.injectFailureIfExistsBeforeServer();
          }
          
-         super.putIfExistsTransactionTarget(invocation, tpc);
+         return super.invoke(invocation);
       }
       
       public InvokerLocator getLocator()

Modified: trunk/testsuite/src/resources/cluster/ejb2/ustxsticky/META-INF/jboss.xml
===================================================================
--- trunk/testsuite/src/resources/cluster/ejb2/ustxsticky/META-INF/jboss.xml	2008-11-14 08:55:44 UTC (rev 80991)
+++ trunk/testsuite/src/resources/cluster/ejb2/ustxsticky/META-INF/jboss.xml	2008-11-14 08:57:47 UTC (rev 80992)
@@ -6,7 +6,7 @@
        <session>
           <ejb-name>UserTransactionStickyEjb</ejb-name>
           <jndi-name>ejb/UserTransactionStickyEjb</jndi-name>
-          <configuration-name>User Transaction Stickiness Verifier Clustered Stateless SessionBean</configuration-name>
+          <configuration-name>User Transaction Sticky Clustered Stateless SessionBean</configuration-name>
           <clustered>true</clustered>
           <cluster-config>
              <partition-name>${jboss.partition.name:DefaultPartition}</partition-name>          
@@ -16,9 +16,40 @@
        </session>
     </enterprise-beans>
     
+    <invoker-proxy-bindings>
+       <invoker-proxy-binding>
+         <name>ustxsticky-clustered-stateless-unified-invoker</name>
+         <invoker-mbean>jboss:service=invoker,type=unifiedha</invoker-mbean>
+         <proxy-factory>org.jboss.proxy.ejb.ProxyFactoryHA</proxy-factory>
+         <proxy-factory-config>
+           <client-interceptors>
+             <home>
+               <interceptor>org.jboss.proxy.ejb.HomeInterceptor</interceptor>
+               <interceptor>org.jboss.proxy.SecurityInterceptor</interceptor>
+               <interceptor>org.jboss.proxy.TransactionInterceptor</interceptor>
+               <interceptor>org.jboss.proxy.ejb.SingleRetryInterceptor</interceptor>
+               <interceptor>org.jboss.proxy.TransactionStickyInterceptor</interceptor>
+               <interceptor call-by-value="false">org.jboss.invocation.InvokerInterceptor</interceptor>
+               <interceptor call-by-value="true">org.jboss.invocation.MarshallingInvokerInterceptor</interceptor>
+             </home>
+             <bean>
+               <interceptor>org.jboss.proxy.ejb.StatelessSessionInterceptor</interceptor>
+               <interceptor>org.jboss.proxy.SecurityInterceptor</interceptor>
+               <interceptor>org.jboss.proxy.TransactionInterceptor</interceptor>
+               <interceptor>org.jboss.proxy.ejb.SingleRetryInterceptor</interceptor>
+               <interceptor>org.jboss.proxy.TransactionStickyInterceptor</interceptor>               
+               <interceptor call-by-value="false">org.jboss.invocation.InvokerInterceptor</interceptor>
+               <interceptor call-by-value="true">org.jboss.invocation.MarshallingInvokerInterceptor</interceptor>
+             </bean>
+           </client-interceptors>
+         </proxy-factory-config>
+       </invoker-proxy-binding>    
+    </invoker-proxy-bindings>
+    
     <container-configurations>
       <container-configuration extends="Clustered Stateless SessionBean">
-         <container-name>User Transaction Stickiness Verifier Clustered Stateless SessionBean</container-name>
+         <container-name>User Transaction Sticky Clustered Stateless SessionBean</container-name>
+         <invoker-proxy-binding-name>ustxsticky-clustered-stateless-unified-invoker</invoker-proxy-binding-name>         
          <container-interceptors>
            <interceptor>org.jboss.test.cluster.invokerha.ejb.UserTransactionStickinessVerifierInterceptor</interceptor>
            <interceptor>org.jboss.ejb.plugins.ProxyFactoryFinderInterceptor</interceptor>

Modified: trunk/testsuite/src/resources/test-configs/ustxsticky/deploy/transaction-service.xml
===================================================================
--- trunk/testsuite/src/resources/test-configs/ustxsticky/deploy/transaction-service.xml	2008-11-14 08:55:44 UTC (rev 80991)
+++ trunk/testsuite/src/resources/test-configs/ustxsticky/deploy/transaction-service.xml	2008-11-14 08:57:47 UTC (rev 80992)
@@ -46,10 +46,10 @@
             <attribute name="ClientInterceptors">
                <interceptors>
                   <interceptor>org.jboss.proxy.ClientMethodInterceptor</interceptor>
+                  <interceptor>org.jboss.proxy.ClientUserTransactionStickyInterceptor</interceptor>                  
                   <interceptor>org.jboss.invocation.InvokerInterceptor</interceptor>
                </interceptors>
             </attribute>
-            <!-- depends optional-attribute-name="PartitionObjectName">jboss:service=${jboss.partition.name:DefaultPartition}</depends -->
             <depends optional-attribute-name="InvokerName">jboss:service=invoker,type=unifiedha</depends>
          </mbean>
       </depends>




More information about the jboss-cvs-commits mailing list