[jboss-cvs] JBossAS SVN: r69835 - branches/JBPAPP_4_2_0_GA_CP/testsuite/src/main/org/jboss/test/cluster/invokerha.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Feb 13 14:55:24 EST 2008


Author: galder.zamarreno at jboss.com
Date: 2008-02-13 14:55:24 -0500 (Wed, 13 Feb 2008)
New Revision: 69835

Added:
   branches/JBPAPP_4_2_0_GA_CP/testsuite/src/main/org/jboss/test/cluster/invokerha/AbstractInvokerHaTransactionSticky.java
   branches/JBPAPP_4_2_0_GA_CP/testsuite/src/main/org/jboss/test/cluster/invokerha/InvokerHaFailureType.java
   branches/JBPAPP_4_2_0_GA_CP/testsuite/src/main/org/jboss/test/cluster/invokerha/JRMPInvokerHaMockUtils.java
   branches/JBPAPP_4_2_0_GA_CP/testsuite/src/main/org/jboss/test/cluster/invokerha/JRMPInvokerHaTransactionStickyUnitTestCase.java
   branches/JBPAPP_4_2_0_GA_CP/testsuite/src/main/org/jboss/test/cluster/invokerha/JRMPInvokerHaUnitTestCase.java
   branches/JBPAPP_4_2_0_GA_CP/testsuite/src/main/org/jboss/test/cluster/invokerha/UnifiedInvokerHaTransactionStickyUnitTestCase.java
Modified:
   branches/JBPAPP_4_2_0_GA_CP/testsuite/src/main/org/jboss/test/cluster/invokerha/AbstractInvokerHa.java
   branches/JBPAPP_4_2_0_GA_CP/testsuite/src/main/org/jboss/test/cluster/invokerha/InvokerHaInfrastructure.java
   branches/JBPAPP_4_2_0_GA_CP/testsuite/src/main/org/jboss/test/cluster/invokerha/UnifiedInvokerHaMockUtils.java
   branches/JBPAPP_4_2_0_GA_CP/testsuite/src/main/org/jboss/test/cluster/invokerha/UnifiedInvokerHaUnitTestCase.java
Log:
[JBPAPP-546] New test classes added to test the new transaction sticky lbps and the behaivour of the invoker ha proxies. These tests include both successfull and failure scenarios.

Modified: branches/JBPAPP_4_2_0_GA_CP/testsuite/src/main/org/jboss/test/cluster/invokerha/AbstractInvokerHa.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/testsuite/src/main/org/jboss/test/cluster/invokerha/AbstractInvokerHa.java	2008-02-13 19:53:44 UTC (rev 69834)
+++ branches/JBPAPP_4_2_0_GA_CP/testsuite/src/main/org/jboss/test/cluster/invokerha/AbstractInvokerHa.java	2008-02-13 19:55:24 UTC (rev 69835)
@@ -22,7 +22,6 @@
 package org.jboss.test.cluster.invokerha;
 
 import java.rmi.server.UID;
-import java.util.WeakHashMap;
 
 import javax.transaction.Transaction;
 
@@ -31,6 +30,9 @@
 import org.jboss.invocation.Invoker;
 import org.jboss.logging.Logger;
 import org.jboss.test.cluster.invokerha.InvokerHaInfrastructure.InvokerHaFactory;
+import org.jboss.test.cluster.invokerha.InvokerHaInfrastructure.TraceFirstAvailable;
+import org.jboss.test.cluster.invokerha.InvokerHaInfrastructure.TraceFirstAvailableIdenticalAllProxies;
+import org.jboss.test.cluster.invokerha.InvokerHaInfrastructure.TraceRandomRobin;
 import org.jboss.test.cluster.invokerha.InvokerHaInfrastructure.TraceRoundRobin;
 import org.jboss.test.cluster.invokerha.InvokerHaTransactionalMockUtils.MockTransaction;
 
@@ -45,14 +47,26 @@
 {
    private static final Logger log = Logger.getLogger(AbstractInvokerHa.class);
    
-   protected InvokerHaInfrastructure infrastructure;
+   InvokerHaInfrastructure infrastructure;
    
-   protected InvokerHaTransactionalMockUtils transactionalMockUtils;
+   InvokerHaTransactionalMockUtils transactionalMockUtils;
+   
+   InvokerHaFactory invokerHaFactory;
+   
+   Invoker timeTellerProxy;
+   
+   Invoker systemTimeProxy;
+   
+   Object prevChosenTargetDateTimeTeller;
+   
+   Object prevChosenTargetSystemTimeTeller;
 
-   protected void setUp(int serverCount, InvokerHaFactory invokerHaFactory) throws Exception
+   protected void setUp(int serverCount, InvokerHaFactory factory) throws Exception
    {
       super.setUp();
       
+      invokerHaFactory = factory; 
+      
       transactionalMockUtils = new InvokerHaTransactionalMockUtils();
       
       infrastructure = invokerHaFactory.getInvokerHaInfrastructure(2);
@@ -80,43 +94,65 @@
       
       infrastructure.undeployServers();
    }
+
+   public void testTransactionalSuccessfulCallsRoundRobin() throws Exception
+   {
+      /* same proxies used in simulated transactions */
+      transactionalSuccessfulCalls(TraceRoundRobin.class, false);
+      /* different proxies in simulated transactions */
+      transactionalSuccessfulCalls(TraceRoundRobin.class, true);
+   }
    
-   protected InvokerHaInfrastructure createInvokerHaInfrastructure(int serverCount, InvokerHaFactory invokerHaFactory)
+   public void testTransactionalSuccessfulCallsFirstAvailable() throws Exception
    {
-      return new InvokerHaInfrastructure(serverCount, invokerHaFactory);
+      /* same proxies used in simulated transactions */
+      transactionalSuccessfulCalls(TraceFirstAvailable.class, false);
+      /* same proxies used in simulated transactions */
+      transactionalSuccessfulCalls(TraceFirstAvailable.class, true);            
    }
    
-   protected void successfulCalls(Class<? extends LoadBalancePolicy> policyClass, WeakHashMap txFailoverAuthorizations)
+   public void testTransactionalSuccessfulCallsFirstAvailableIndenticalAllProxies() throws Exception
    {
+      /* same proxies used in simulated transactions */
+      transactionalSuccessfulCalls(TraceFirstAvailableIdenticalAllProxies.class, false);
+      /* same proxies used in simulated transactions */
+      transactionalSuccessfulCalls(TraceFirstAvailableIdenticalAllProxies.class, true);                  
+   }
+   
+   public void testTransactionalSuccessfulCallsRandomRobin() throws Exception
+   {
+      /* same proxies used in simulated transactions */
+      transactionalSuccessfulCalls(TraceRandomRobin.class, false);
+      /* same proxies used in simulated transactions */
+      transactionalSuccessfulCalls(TraceRandomRobin.class, true);                  
+   }
+   
+   protected void transactionalSuccessfulCalls(Class<? extends LoadBalancePolicy> policyClass, boolean newProxiesInBetweenTransactions)
+   {
+      log.debug("transactional successfull calls [policy=" + policyClass + ",newProxiesInBetweenTransactions=" + newProxiesInBetweenTransactions + "]");
+      
       try
       {
          UID uid;
          
-         /* Create a proxy instances retrieved from the first server */
-         Invoker timeTellerProxy = infrastructure.createDateTimeTellerProxy(0, policyClass);
-         Invoker systemTimeProxy = infrastructure.createSystemTimeTellerProxy(0, policyClass);
+         createNewProxies(0, policyClass, true);
 
-//       Commented because tx failover maps are still mapped on tx rather than
-//       transaction propagation context. Once it's keyed on tpc, these tests 
-//       will be enabled.
-//         
-//         /* Simulate client user transaction */
-//         uid = new UID();         
-//         transactionalMockUtils.getTpcf().setUid(uid);
-//         callsWithinTransaction(3, timeTellerProxy, systemTimeProxy, null, policyClass, txFailoverAuthorizations);
-//         
-//         if (newProxiesInBetweenTransactions)
-//         {
-//            timeTellerProxy = infrastructure.createDateTimeTellerProxy(0, policyClass);
-//            systemTimeProxy = infrastructure.createDateTimeTellerProxy(0, policyClass);            
-//         }
+         /* Simulate client user transaction */
+         uid = new UID();         
+         transactionalMockUtils.getTpcf().setUid(uid);
+         performCalls(3, null, policyClass);
          
+         if (newProxiesInBetweenTransactions)
+         {
+            createNewProxies(0, policyClass, false);
+         }
+         
          /* Simulate transaction interceptor */
          uid = new UID();
          Transaction tx = new MockTransaction();
          transactionalMockUtils.getTpcf().setUid(uid);
          transactionalMockUtils.getTpci().setTransaction(tx);
-         callsWithinTransaction(3, timeTellerProxy, systemTimeProxy, tx, policyClass, txFailoverAuthorizations);                  
+         performCalls(3, tx, policyClass);                  
       }
       catch(Exception e)
       {
@@ -127,66 +163,113 @@
       }
    }
 
-   protected void callsWithinTransaction(int numberPairCalls, 
-         Invoker timeTellerProxy, 
-         Invoker systemTimeProxy, 
-         Transaction tx,
-         Class<? extends LoadBalancePolicy> policyClass,
-         WeakHashMap txFailoverAuthorizations) throws Exception
+   protected void performCalls(int numberPairCalls, 
+         Transaction tx, Class<? extends LoadBalancePolicy> policyClass) throws Exception
    {
       Invocation inv;
-      Object chosenTarget;
-      Object prevChosenTargetDateTimeTeller = null;
-      Object prevChosenTargetSystemTimeTeller = null;
-
+      
       for (int i = 0; i < numberPairCalls; i++)
       {
          /* create invocation to date time teller */
-         inv = infrastructure.createDateTimeTellerInvocation(tx);
+         inv = infrastructure.createDateTimeTellerInvocation(tx, null);
          /* invoke on proxy passing the invocation */
          log.debug(timeTellerProxy.invoke(inv));
-
-         assertEquals(0, inv.getAsIsValue("FAILOVER_COUNTER"));
-         chosenTarget = inv.getTransientValue("TEST_CHOSEN_TARGET");
-         assertNotNull(chosenTarget);
-         /* if tx was null, invocation's tx should be null after invocation. */
-         assertEquals(tx, inv.getTransaction());
-         /* check chosen target with previously chosen target, if there's any */
-         if (policyClass.equals(TraceRoundRobin.class))
-         {
-            prevChosenTargetDateTimeTeller = checkRoundRobin(i, chosenTarget, prevChosenTargetDateTimeTeller);
-         }
+         /* assert post conditions after invocation */
+         prevChosenTargetDateTimeTeller = assertSuccessfulPostConditions(inv, prevChosenTargetDateTimeTeller, tx, policyClass);
          
-         assertTrue("transaction should have reached the server", txFailoverAuthorizations.containsKey(tx));
-         
          /* create invocation to system time teller */
-         inv = infrastructure.createSystemTimeTellerInvocation(tx);
+         inv = infrastructure.createSystemTimeTellerInvocation(tx, null);
+         /* invoke on proxy passing the invocation */
          log.debug(systemTimeProxy.invoke(inv));
-         
-         assertEquals(0, inv.getAsIsValue("FAILOVER_COUNTER"));
-         chosenTarget = inv.getTransientValue("TEST_CHOSEN_TARGET");
-         assertNotNull(chosenTarget);
-         assertEquals(tx, inv.getTransaction());
-         if (policyClass.equals(TraceRoundRobin.class))
-         {
-            prevChosenTargetSystemTimeTeller = checkRoundRobin(i, chosenTarget, prevChosenTargetSystemTimeTeller);
-         }
-         assertTrue("transaction should have reached the server", txFailoverAuthorizations.containsKey(tx));
-                 
+         /* assert post conditions after invocation */
+         prevChosenTargetSystemTimeTeller = assertSuccessfulPostConditions(inv, prevChosenTargetSystemTimeTeller, tx, policyClass);
       }
    }
    
-   protected Object checkRoundRobin(int callIndex, Object chosenTarget, Object prevChosenTarget)
+   protected Object assertSuccessfulPostConditions(Invocation inv, Object prevChosenTarget, Transaction tx, Class<? extends LoadBalancePolicy> policyClass)
    {
-      if (callIndex != 0)
+      assertEquals(0, inv.getAsIsValue("FAILOVER_COUNTER"));
+      Object chosenTarget = inv.getTransientValue(invokerHaFactory.getChosenTargetKey());
+      assertNotNull(chosenTarget);
+      /* if tx was null, invocation's tx should be null after invocation. */
+      assertEquals(tx, inv.getTransaction());
+      if (transactionalMockUtils.getTpcf().getUid() != null)
       {
-         /* in round robin, previous chosen target must be different to the 
+         /* check tx failover authorisations */
+         assertTrue("transaction should have reached the server", invokerHaFactory.getTxFailoverAuthorizationsMap().containsKey(transactionalMockUtils.getTpcf().getUid()));         
+      }
+      /* check chosen target with previously chosen target, if there's any */
+      return assertChosenTarget(policyClass, chosenTarget, prevChosenTarget);
+   }
+   
+   protected void createNewProxies(int serverIndex, Class<? extends LoadBalancePolicy> policyClass, boolean isVery1st) throws Exception
+   {
+      /* Create a proxy instances retrieved from the first server */
+      timeTellerProxy = infrastructure.createDateTimeTellerProxy(serverIndex, policyClass);
+      systemTimeProxy = infrastructure.createSystemTimeTellerProxy(serverIndex, policyClass);
+      
+      /* Initialise previous chosen targets. If not new proxies elected 
+       * between transactions, this allows to carry on checking chosen 
+       * targets in between transactions. */ 
+      if (!isVery1st && policyClass.equals(TraceFirstAvailableIdenticalAllProxies.class))
+      {
+         /* In the particular case of first availble indentical proxies, if we're 
+         * not creating the proxies for the first time, do not initialise the 
+         * proxies because we need them to check them with next chosen ones. */
+      }
+      else
+      {
+         prevChosenTargetDateTimeTeller = null;
+         prevChosenTargetSystemTimeTeller = null;                  
+      }
+   }
+   
+   protected Object assertChosenTarget(Class<? extends LoadBalancePolicy> policyClass, Object chosenTarget, Object prevChosenTarget)
+   {
+      if (policyClass.equals(TraceRoundRobin.class))
+      {
+         prevChosenTarget = checkRoundRobin(chosenTarget, prevChosenTarget);
+      }
+      else if (policyClass.equals(TraceFirstAvailable.class))
+      {
+         prevChosenTarget = checkFirstAvailable(chosenTarget, prevChosenTarget);
+      }
+      else if (policyClass.equals(TraceFirstAvailableIdenticalAllProxies.class))
+      {
+         prevChosenTarget = checkFirstAvailableIndenticalAllProxies(chosenTarget, prevChosenTarget);
+      }
+      
+      return prevChosenTarget;
+   }
+   
+   protected Object checkRoundRobin(Object chosenTarget, Object prevChosenTarget)
+   {
+      if (prevChosenTarget != null)
+      {
+         /* In round robin, previous chosen target must be different to the 
           * current one, unless there's only one node in the cluster, but we're 
           * not testing that here. */
          assertNotSame(prevChosenTarget, chosenTarget);
-      }
+      }      
       
       return chosenTarget;
    }
    
+   protected Object checkFirstAvailable(Object chosenTarget, Object prevChosenTarget)
+   {
+      if (prevChosenTarget != null)
+      {
+         /* In first available robin, previous chosen target must be the same to the 
+          * current one, unless there's only one node in the cluster, but we're 
+          * not testing that here. */
+         assertEquals(prevChosenTarget, chosenTarget);
+      }
+      
+      return chosenTarget;      
+   }
+   
+   protected Object checkFirstAvailableIndenticalAllProxies(Object chosenTarget, Object prevChosenTarget)
+   {
+      return checkFirstAvailable(chosenTarget, prevChosenTarget);
+   }   
 }

Added: branches/JBPAPP_4_2_0_GA_CP/testsuite/src/main/org/jboss/test/cluster/invokerha/AbstractInvokerHaTransactionSticky.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/testsuite/src/main/org/jboss/test/cluster/invokerha/AbstractInvokerHaTransactionSticky.java	                        (rev 0)
+++ branches/JBPAPP_4_2_0_GA_CP/testsuite/src/main/org/jboss/test/cluster/invokerha/AbstractInvokerHaTransactionSticky.java	2008-02-13 19:55:24 UTC (rev 69835)
@@ -0,0 +1,368 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2007, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY 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 along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.test.cluster.invokerha;
+
+import java.rmi.server.UID;
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.transaction.Transaction;
+
+import org.jboss.ha.framework.interfaces.LoadBalancePolicy;
+import org.jboss.ha.framework.interfaces.TransactionStickyFirstAvailable;
+import org.jboss.ha.framework.interfaces.TransactionStickyFirstAvailableIdenticalAllProxies;
+import org.jboss.ha.framework.interfaces.TransactionStickyRandomRobin;
+import org.jboss.ha.framework.interfaces.TransactionStickyRoundRobin;
+import org.jboss.invocation.Invocation;
+import org.jboss.logging.Logger;
+import org.jboss.test.cluster.invokerha.InvokerHaTransactionalMockUtils.MockTransaction;
+
+/**
+ * AbstractInvokerHaTransactionSticky.
+ * 
+ * @author <a href="mailto:galder.zamarreno at jboss.com">Galder Zamarreno</a>
+ */
+public class AbstractInvokerHaTransactionSticky extends AbstractInvokerHa
+{
+   private static final Logger log = Logger.getLogger(AbstractInvokerHaTransactionSticky.class);
+   
+   private Set<Object> chosenTargets;
+   
+   @Override
+   public void testTransactionalSuccessfulCallsRoundRobin() throws Exception
+   {
+      /* same proxies used in simulated transactions */
+      transactionalSuccessfulCalls(TransactionStickyRoundRobin.class, false);
+      /* different proxies in simulated transactions */
+      transactionalSuccessfulCalls(TransactionStickyRoundRobin.class, true);
+   }
+   
+   @Override
+   public void testTransactionalSuccessfulCallsFirstAvailable() throws Exception
+   {
+      /* same proxies used in simulated transactions */
+      transactionalSuccessfulCalls(TransactionStickyFirstAvailable.class, false);
+      /* different proxies in simulated transactions */
+      transactionalSuccessfulCalls(TransactionStickyFirstAvailable.class, true);
+   }
+   
+   @Override
+   public void testTransactionalSuccessfulCallsFirstAvailableIndenticalAllProxies() throws Exception
+   {
+      /* same proxies used in simulated transactions */
+      transactionalSuccessfulCalls(TransactionStickyFirstAvailableIdenticalAllProxies.class, false);
+      /* different proxies in simulated transactions */
+      transactionalSuccessfulCalls(TransactionStickyFirstAvailableIdenticalAllProxies.class, true);
+   }
+
+   @Override
+   public void testTransactionalSuccessfulCallsRandomRobin() throws Exception
+   {
+      /* same proxies used in simulated transactions */
+      transactionalSuccessfulCalls(TransactionStickyRandomRobin.class, false);
+      /* different proxies in simulated transactions */
+      transactionalSuccessfulCalls(TransactionStickyRandomRobin.class, true);
+   }
+   
+   public void testSuccessfulCallsRoundRobin() throws Exception
+   {
+      /* test transaction sticky round robin lbp without transactions, should 
+       * behave like standard round robin */
+      successfulCalls(TransactionStickyRoundRobin.class);
+   }
+   
+   public void testSuccessfulCallsFirstAvailable() throws Exception
+   {
+      /* test transaction sticky first available lbp without transactions, should 
+       * behave like standard first available */
+      successfulCalls(TransactionStickyFirstAvailable.class);
+   }
+   
+   public void testSuccessfulCallsFirstAvailableIndenticalAllProxies() throws Exception
+   {
+      /* test transaction sticky first available identical all proxies lbp 
+       * without transactions, should behave like standard identical all 
+       * proxies */
+      successfulCalls(TransactionStickyFirstAvailableIdenticalAllProxies.class);
+   }
+   
+   public void testSuccessfulCallsRandomRobin() throws Exception
+   {
+      /* test transaction sticky random robin lbp without transactions, should 
+       * behave like standard random robin */
+      successfulCalls(TransactionStickyRandomRobin.class);
+   }
+   
+   public void testFailBeforeServer() throws Exception
+   {
+      /* if failure happens before reaching the server, regardless of whether
+       * the failure happened in the 1st or the Nth invocation, it's not 
+       * recoverable */
+      transactionalFailureCalls(InvokerHaFailureType.BEFORE_SERVER, TransactionStickyRandomRobin.class, false);
+   }
+   
+   public void testFailAfterServerNotCompletedButSuccessAfter() throws Exception
+   {
+      /* we use new proxies in between tests for 1st and Nth 
+       * call so that results from Nth call don't get polluted with what 
+       * happened in the 1st call test. */
+      transactionalFailureCalls(InvokerHaFailureType.AFTER_SERVER_NOT_COMPLETED_BUT_SUCCESS_AFTER, TransactionStickyRandomRobin.class, true);
+   }
+   
+   public void testFailAfterServerNotCompletedBothServers() throws Exception
+   {
+      /* we use new proxies in between tests for 1st and Nth call 
+       * so that results from Nth call don't get polluted with what happened in 
+       * the 1st call test. */
+      transactionalFailureCalls(InvokerHaFailureType.AFTER_SERVER_NOT_COMPLETED_BOTH_SERVERS, TransactionStickyRandomRobin.class, true);
+   }
+   
+   public void testFailAfterServerCompleted() throws Exception
+   {
+      /* We use new proxies in between tests for 1st and Nth call 
+       * so that results from Nth call don't get polluted with what happened in 
+       * the 1st call test. */
+      transactionalFailureCalls(InvokerHaFailureType.AFTER_SERVER_COMPLETED, TransactionStickyRandomRobin.class, true);
+   }
+
+   @Override
+   protected void transactionalSuccessfulCalls(Class<? extends LoadBalancePolicy> policyClass,
+         boolean newProxiesInBetweenTransactions)
+   {
+      log.debug("transactional successfull calls [policy=" + policyClass + ",newProxiesInBetweenTransactions=" + newProxiesInBetweenTransactions + "]");
+      
+      try
+      {
+         UID uid;
+         
+         createNewProxies(0, policyClass, true);
+
+         /* Simulate client user transaction */
+         uid = new UID();         
+         transactionalMockUtils.getTpcf().setUid(uid);
+         performTransactionalStickyCalls(3, null, policyClass, newProxiesInBetweenTransactions);
+         /* either set would do because they should be the same */
+         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);
+         /* either set would do because they should be the same */
+         Set<Object> chosenTargetsTx2 = chosenTargets;
+         
+         assertChosenTargetsInBetweenTx(policyClass, chosenTargetsTx1, chosenTargetsTx2, newProxiesInBetweenTransactions);
+      }
+      catch(Exception e)
+      {
+         /* catching to log the error properly (JUnit in eclipse does not show 
+          * correctly exceptions from invokers) and fail */
+         log.error("error", e);
+         fail();
+      }
+      
+   }
+   
+   protected void successfulCalls(Class<? extends LoadBalancePolicy> policyClass)
+   {
+      log.debug("successfull calls [policy=" + policyClass);
+      
+      try
+      {
+         createNewProxies(0, policyClass, true);
+         performCalls(3, null, policyClass);
+      }
+      catch(Exception e)
+      {
+         /* catching to log the error properly (JUnit in eclipse does not show 
+          * correctly exceptions from invokers) and fail */
+         log.error("error", e);
+         fail();
+      }
+   }
+
+   protected void performTransactionalStickyCalls(int numberPairCalls, Transaction tx,
+         Class<? extends LoadBalancePolicy> policyClass, boolean newProxiesInBetweenTransactions) throws Exception
+   {
+      Invocation inv;
+      
+      Set<Object> chosenTargetsDateTimeTeller = new HashSet<Object>(1);
+      Set<Object> chosenTargetsSystemTimeTeller = new HashSet<Object>(1);
+      
+      for (int i = 0; i < numberPairCalls; i++)
+      {
+         /* create invocation to date time teller */
+         inv = infrastructure.createDateTimeTellerInvocation(tx, null);
+         /* invoke on proxy passing the invocation */
+         log.debug(timeTellerProxy.invoke(inv));
+         /* assert post conditions after invocation */
+         chosenTargetsDateTimeTeller = assertSuccessfulPostConditions(inv, chosenTargetsDateTimeTeller);
+         
+         /* create invocation to system time teller */
+         inv = infrastructure.createSystemTimeTellerInvocation(tx, null);
+         /* invoke on proxy passing the invocation */
+         log.debug(systemTimeProxy.invoke(inv));
+         /* assert post conditions after invocation */
+         chosenTargetsSystemTimeTeller = assertSuccessfulPostConditions(inv, chosenTargetsSystemTimeTeller);
+      }
+      
+      /* for the duration of a transaction, all chosen targets should be the same */
+      assertEquals(chosenTargetsDateTimeTeller, chosenTargetsSystemTimeTeller);
+      
+      chosenTargets = chosenTargetsDateTimeTeller;
+   }
+      
+   protected Set<Object> assertSuccessfulPostConditions(Invocation inv, Set<Object> chosenTargets)
+   {
+      assertEquals(0, inv.getAsIsValue("FAILOVER_COUNTER"));
+      Object chosenTarget = inv.getTransientValue(invokerHaFactory.getChosenTargetKey());
+      assertNotNull(chosenTarget);
+      /* check tx failover authorisations */
+      assertTrue("transaction should have reached the server", invokerHaFactory.getTxFailoverAuthorizationsMap().containsKey(transactionalMockUtils.getTpcf().getUid()));
+      /* add target to singleton set, there must only be one different target within a transaction */
+      chosenTargets.add(chosenTarget);
+      assertEquals(1, chosenTargets.size());
+      
+      return chosenTargets;
+   }
+   
+   protected void assertChosenTargetsInBetweenTx(Class<? extends LoadBalancePolicy> policyClass, Set<?> chosenTargetsTx1, Set<?> chosenTargetsTx2, boolean newProxiesInBetweenTransactions)
+   {
+      if (policyClass.equals(TransactionStickyRoundRobin.class))
+      {
+         if (!newProxiesInBetweenTransactions)
+         {
+            /* If we're using sticky round robin and we didn't change proxies 
+             * in between transactions, we can guarantee that the chosen targets
+             * were different between transactions.*/
+            assertNotSame(chosenTargetsTx1, chosenTargetsTx2);
+         }
+      }
+      else if (policyClass.equals(TransactionStickyFirstAvailable.class))
+      {
+         if (!newProxiesInBetweenTransactions)
+         {
+            /* If we're using sticky first available and we didn't change proxies 
+             * in between transactions, we can guarantee that the chosen targets
+             * are equals between transactions.*/
+            assertEquals(chosenTargetsTx1, chosenTargetsTx2);
+         }
+      }
+      else if (policyClass.equals(TransactionStickyFirstAvailableIdenticalAllProxies.class))
+      {
+         /* If we're using sticky first available identical all proxies, 
+          * regardless of whether we're using same proxies or not, we can 
+          * guarantee that the chosen targets are the same between 
+          * transactions.*/         
+         assertEquals(chosenTargetsTx1, chosenTargetsTx2);
+      }
+   }
+   
+   protected void transactionalFailureCalls(InvokerHaFailureType failureType, Class<? extends LoadBalancePolicy> policyClass, boolean newProxiesInBetweenFailures) throws Exception
+   {
+      createNewProxies(0, policyClass, true);
+      
+      try 
+      {
+         /* fail in 1st call */
+         failureCall(failureType, true, policyClass, newProxiesInBetweenFailures);
+         
+         if (newProxiesInBetweenFailures)
+         {
+            createNewProxies(0, policyClass, false);            
+         }
+         
+         /* fail in Nth call */
+         failureCall(failureType, false, policyClass, newProxiesInBetweenFailures);
+      }
+      catch(Exception e)
+      {
+         /* catching to log the error properly (JUnit in eclipse does not show 
+          * correctly exceptions from invokers) and fail */
+         log.error("error", e);
+         fail();
+      }      
+   }
+   
+   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);         
+      }
+      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);
+         /* Now we create the invocation with the failure injected */
+         inv = infrastructure.createDateTimeTellerInvocation(null, failureType);
+      }
+      
+      try 
+      {
+         log.debug(timeTellerProxy.invoke(inv));
+         if (failureType.isRecoverable(injectFailureIn1stCall))
+         {
+            failureType.assertFailoverCounter(injectFailureIn1stCall, inv.getAsIsValue("FAILOVER_COUNTER"));
+            inv = infrastructure.createDateTimeTellerInvocation(null, null);
+            log.debug(timeTellerProxy.invoke(inv));
+         }
+         else
+         {
+            fail("should have failed, failover is not allowed for " + failureType);            
+         }
+      }
+      catch (Exception e)
+      {
+         if (failureType.isRecoverable(injectFailureIn1stCall))
+         {
+            fail("should have failed, failover is not allowed for " + failureType);
+         }
+         else
+         {
+            assertNull("transaction on the client side should be null", inv.getTransaction());
+            failureType.assertFailoverCounter(injectFailureIn1stCall, inv.getAsIsValue("FAILOVER_COUNTER"));
+            failureType.assertException(e);                        
+         }
+      }
+   }
+
+}

Added: branches/JBPAPP_4_2_0_GA_CP/testsuite/src/main/org/jboss/test/cluster/invokerha/InvokerHaFailureType.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/testsuite/src/main/org/jboss/test/cluster/invokerha/InvokerHaFailureType.java	                        (rev 0)
+++ branches/JBPAPP_4_2_0_GA_CP/testsuite/src/main/org/jboss/test/cluster/invokerha/InvokerHaFailureType.java	2008-02-13 19:55:24 UTC (rev 69835)
@@ -0,0 +1,169 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2007, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY 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 along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.test.cluster.invokerha;
+
+import java.rmi.ServerException;
+
+import org.jboss.ha.framework.interfaces.GenericClusteringException;
+import org.jboss.invocation.ServiceUnavailableException;
+import org.jboss.logging.Logger;
+
+import junit.framework.TestCase;
+
+/**
+ * InvokerHaFailureType.
+ * 
+ * @author <a href="mailto:galder.zamarreno at jboss.com">Galder Zamarreno</a>
+ */
+public enum InvokerHaFailureType 
+{
+   BEFORE_SERVER,
+   AFTER_SERVER_NOT_COMPLETED_BUT_SUCCESS_AFTER,
+   AFTER_SERVER_NOT_COMPLETED_BOTH_SERVERS,
+   AFTER_SERVER_COMPLETED;      
+
+   private static final Logger log = Logger.getLogger(InvokerHaFailureType.class);
+   
+   public boolean isRecoverable(boolean injectFailureIn1stCall)
+   {
+      switch(this) 
+      {
+         case BEFORE_SERVER:
+            /* a failure before even getting to the invocation call itself is 
+             * never recoverable */
+            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;
+            }
+            return false;
+            
+         case AFTER_SERVER_NOT_COMPLETED_BOTH_SERVERS:
+            /* if failure happens after reaching the server but didn't complete when 
+             * trying to call either server, neither in the 1st or Nth call is 
+             * recoverable.*/
+            return false;
+            
+         case AFTER_SERVER_COMPLETED:
+            /* if failure happens after reaching the server and completed, neither 
+             * 1st or Nth call are recoverable. */
+            return false;
+            
+         default:
+            return false;
+      }
+   }
+   
+   public void injectFailureIfExistsBeforeServer() throws IllegalStateException
+   {
+      switch(this) 
+      {
+         case BEFORE_SERVER:
+            log.debug("failing because of " + this);
+            throw new IllegalStateException("see how you handle this!!");
+      }
+   }
+   
+   public void injectFailureIfExistsAfterServer(Integer failoverCounter) throws GenericClusteringException
+   {
+      switch(this)
+      {
+         case AFTER_SERVER_NOT_COMPLETED_BUT_SUCCESS_AFTER:
+            if (failoverCounter.equals(new Integer(0)))
+            {
+               log.debug("failing because of " + this);
+               throw new GenericClusteringException(GenericClusteringException.COMPLETED_NO, this.toString());               
+            }
+            break;
+
+         case AFTER_SERVER_NOT_COMPLETED_BOTH_SERVERS:
+            log.debug("failing because of " + this);
+            throw new GenericClusteringException(GenericClusteringException.COMPLETED_NO, this.toString());
+            
+         case AFTER_SERVER_COMPLETED:
+            log.debug("failing because of " + this);
+            throw new GenericClusteringException(GenericClusteringException.COMPLETED_YES, this.toString());
+      }
+   }
+
+   public void assertFailoverCounter(boolean injectFailureIn1stCall, Object failoverCounter)
+   {
+      switch(this)
+      {
+         case BEFORE_SERVER:
+            TestCase.assertEquals(0, failoverCounter);
+            break;
+            
+         case AFTER_SERVER_NOT_COMPLETED_BUT_SUCCESS_AFTER:
+            TestCase.assertEquals(1, failoverCounter);
+            break;
+            
+         case AFTER_SERVER_NOT_COMPLETED_BOTH_SERVERS:
+            if (injectFailureIn1stCall)
+            {
+               /* Two failovers were attempted before finally giving up */
+               TestCase.assertEquals(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(1, failoverCounter);
+            }
+            break;
+            
+         case AFTER_SERVER_COMPLETED:
+            /* failover counters are always 0 because there's no chance of 
+             * calculating failover at all */
+            TestCase.assertEquals(0, failoverCounter);
+            break;
+      }
+   }
+   
+   public void assertException(Exception e)
+   {
+      switch(this) 
+      {
+         case BEFORE_SERVER:
+            TestCase.assertTrue(e 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);
+            break;
+            
+         case AFTER_SERVER_COMPLETED:
+            TestCase.assertTrue(e instanceof ServerException);
+            TestCase.assertTrue(e.getCause() instanceof GenericClusteringException);
+            break;
+      }
+   }
+}

Modified: branches/JBPAPP_4_2_0_GA_CP/testsuite/src/main/org/jboss/test/cluster/invokerha/InvokerHaInfrastructure.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/testsuite/src/main/org/jboss/test/cluster/invokerha/InvokerHaInfrastructure.java	2008-02-13 19:53:44 UTC (rev 69834)
+++ branches/JBPAPP_4_2_0_GA_CP/testsuite/src/main/org/jboss/test/cluster/invokerha/InvokerHaInfrastructure.java	2008-02-13 19:55:24 UTC (rev 69835)
@@ -26,6 +26,7 @@
 import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
+import java.util.WeakHashMap;
 
 import javax.management.MBeanServer;
 import javax.management.MalformedObjectNameException;
@@ -33,9 +34,12 @@
 import javax.transaction.Transaction;
 
 import org.jboss.ha.framework.interfaces.FamilyClusterInfo;
+import org.jboss.ha.framework.interfaces.FirstAvailable;
+import org.jboss.ha.framework.interfaces.FirstAvailableIdenticalAllProxies;
 import org.jboss.ha.framework.interfaces.HAPartition;
 import org.jboss.ha.framework.interfaces.HARMIClient;
 import org.jboss.ha.framework.interfaces.LoadBalancePolicy;
+import org.jboss.ha.framework.interfaces.RandomRobin;
 import org.jboss.ha.framework.interfaces.RoundRobin;
 import org.jboss.ha.framework.server.HATarget;
 import org.jboss.invocation.Invocation;
@@ -129,12 +133,10 @@
       /* create n invoker instances that emulate n AS servers */
       for (int i =0; i < serverCount; i++)
       {
-         InvokerHA server = invokerHaFactory.createInvokerHAServer("Server", i + 1);
+         InvokerHA server = invokerHaFactory.createInvokerHaServer("Server", i + 1);
          /* add invoker as replicant */
          replicantServers.add(server);
          
-         System.out.println(i);
-         
          mbs.registerMBean(server, invokerONs.get(i));
       }
 
@@ -221,11 +223,13 @@
     * @param tx instance of Transaction. If tx is null, transaction is not 
     * added to invocation, which is useful to replicate transactions starting 
     * in non managed environments.
+    * @param failureType type of failure to inject. If null, no failure is 
+    * injected. 
     * @return
     */
-   public Invocation createDateTimeTellerInvocation(Transaction tx)
+   public Invocation createDateTimeTellerInvocation(Transaction tx, InvokerHaFailureType failureType)
    {
-      return createInvocation(tx, dateTimeTellerONHashCode);
+      return createInvocation(tx, dateTimeTellerONHashCode, failureType);
    }
    
    /**
@@ -234,11 +238,13 @@
     * @param tx instance of Transaction. If tx is null, transaction is not 
     * added to invocation, which is useful to replicate transactions starting 
     * in non managed environments.
+    * @param failureType type of failure to inject. If null, no failure is 
+    * injected. 
     * @return
     */
-   public Invocation createSystemTimeTellerInvocation(Transaction tx)
+   public Invocation createSystemTimeTellerInvocation(Transaction tx, InvokerHaFailureType failureType)
    {
-      return createInvocation(tx, systemTimeTellerONHashCode);
+      return createInvocation(tx, systemTimeTellerONHashCode, failureType);
    }   
    
    /**
@@ -325,7 +331,7 @@
     * @param hashCode hashcode of object name of the mbean
     * @return
     */
-   private Invocation createInvocation(Transaction tx, Integer hashCode)
+   private Invocation createInvocation(Transaction tx, Integer hashCode, InvokerHaFailureType failureType)
    {
       Invocation inv = new Invocation();
       inv.setObjectName(hashCode);
@@ -333,6 +339,10 @@
       {
          inv.setTransaction(tx);
       }
+      if (failureType != null)
+      {
+         inv.setValue("FAILURE_TYPE", failureType);
+      }
       return inv;
    }
       
@@ -360,13 +370,27 @@
       InvokerHaInfrastructure getInvokerHaInfrastructure(int serverCount);
       
       /**
+       * Returns the invoker ha tx failover authorisations map.
+       * 
+       * @return WeakHashMap containing the tx failover authorisations.
+       */
+      WeakHashMap getTxFailoverAuthorizationsMap();
+      
+      /**
        * Creates an instance of invoker endpoint.
        * 
        * @param serverName name of invoker endpoint
        * @param serverNumber invoker endpoint number
        * @return
        */
-      InvokerHA createInvokerHAServer(String serverName, int serverNumber);
+      InvokerHA createInvokerHaServer(String serverName, int serverNumber);
+      
+      /**
+       * Returns transient payload key to retrieve chosen target.
+       * 
+       * @return String representation of the key
+       */
+      String getChosenTargetKey();
    }
    
    /**
@@ -487,4 +511,61 @@
          super(new RoundRobin());
       }
    }
+   
+   /**
+    * Trace load balance policy specific for first available. This allows for non 
+    * argument construction of such load balance policy, which makes it testing 
+    * cleaner. We just pass the load balance policy class and we use reflection 
+    * to create a new instance.  
+    * 
+    * @author <a href="mailto:galder.zamarreno at jboss.com">Galder Zamarreno</a>
+    */
+   public static class TraceFirstAvailable extends TraceLoadBalancePolicy
+   {
+      /** The serialVersionUID */
+      private static final long serialVersionUID = -1626190092127048933L;
+    
+      public TraceFirstAvailable()
+      {
+         super(new FirstAvailable());
+      }      
+   }
+
+   /**
+    * Trace load balance policy specific for first available indentical all 
+    * proxies. This allows for non argument construction of such load balance 
+    * policy, which makes it testing cleaner. We just pass the load balance 
+    * policy class and we use reflection to create a new instance.  
+    * 
+    * @author <a href="mailto:galder.zamarreno at jboss.com">Galder Zamarreno</a>
+    */
+   public static class TraceFirstAvailableIdenticalAllProxies extends TraceLoadBalancePolicy
+   {
+      /** The serialVersionUID */
+      private static final long serialVersionUID = -8656749681577922508L;
+
+      public TraceFirstAvailableIdenticalAllProxies()
+      {
+         super(new FirstAvailableIdenticalAllProxies());
+      }      
+   }
+   
+   /**
+    * Trace load balance policy specific for random robin. This allows for non 
+    * argument construction of such load balance policy, which makes it testing 
+    * cleaner. We just pass the load balance policy class and we use reflection 
+    * to create a new instance.  
+    * 
+    * @author <a href="mailto:galder.zamarreno at jboss.com">Galder Zamarreno</a>
+    */
+   public static class TraceRandomRobin extends TraceLoadBalancePolicy
+   {
+      /** The serialVersionUID */
+      private static final long serialVersionUID = -1626190092127048933L;
+    
+      public TraceRandomRobin()
+      {
+         super(new RandomRobin());
+      }      
+   }
 }

Added: branches/JBPAPP_4_2_0_GA_CP/testsuite/src/main/org/jboss/test/cluster/invokerha/JRMPInvokerHaMockUtils.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/testsuite/src/main/org/jboss/test/cluster/invokerha/JRMPInvokerHaMockUtils.java	                        (rev 0)
+++ branches/JBPAPP_4_2_0_GA_CP/testsuite/src/main/org/jboss/test/cluster/invokerha/JRMPInvokerHaMockUtils.java	2008-02-13 19:55:24 UTC (rev 69835)
@@ -0,0 +1,139 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2007, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY 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 along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.test.cluster.invokerha;
+
+import java.util.ArrayList;
+
+import org.jboss.ha.framework.interfaces.LoadBalancePolicy;
+import org.jboss.invocation.Invocation;
+import org.jboss.invocation.Invoker;
+import org.jboss.invocation.jrmp.interfaces.JRMPInvokerProxyHA;
+import org.jboss.invocation.jrmp.server.JRMPInvokerHA;
+
+/**
+ * JrmpInvokerHaMockUtils.
+ * 
+ * @author <a href="mailto:galder.zamarreno at jboss.com">Galder Zamarreno</a>
+ */
+public class JRMPInvokerHaMockUtils
+{
+   /**
+    * Mock version of JRMPInvokerHA that eases debugging and swallows an 
+    * exception being thrown when unregistering the invoker ha mbean.
+    * 
+    * @author <a href="mailto:galder.zamarreno at jboss.com">Galder Zamarreno</a>
+    */
+   public static class MockJRMPInvokerHA extends JRMPInvokerHA
+   {
+      /** The serialVersionUID */
+      private static final long serialVersionUID = -4557124707606766661L;
+      
+      private String name;
+      
+      public MockJRMPInvokerHA(String name)
+      {
+         this.name = name;
+      }
+      
+      /**
+       * Override postDeregister() to avoid the following exception being 
+       * thrown on tearDown():
+       * 
+       * javax.management.InstanceNotFoundException: jboss.system:service=ServiceController
+       *    at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.getMBean(DefaultMBeanServerInterceptor.java:1010)
+       *    at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:804)
+       *    at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:784)
+       *    at org.jboss.system.ServiceMBeanSupport.postDeregister(ServiceMBeanSupport.java:424)
+       *    at org.jboss.invocation.jrmp.server.JRMPInvoker.postDeregister(JRMPInvoker.java:665)
+       */
+      @Override
+      public void postDeregister()
+      {
+      }
+      
+      /**
+       * Override toString because in absence of RemoteRef 
+       * java.rmi.server.RemoteObject's toString implementation prints just 
+       * the class name which makes it pretty ackward for assertions and 
+       * debugging.
+       */
+      @Override
+      public String toString()
+      {         
+         return name;
+      }
+
+      @Override
+      protected Invoker createProxy(ArrayList targets, LoadBalancePolicy policy, String proxyFamilyName,
+            long viewId)
+      {
+         return new MockJRMPInvokerProxyHA(targets, policy, proxyFamilyName, viewId);
+      }
+
+      @Override
+      public Object invoke(Invocation invocation) throws Exception
+      {
+         InvokerHaFailureType failureType = (InvokerHaFailureType)invocation.getValue("FAILURE_TYPE");
+         if (failureType != null)
+         {
+            failureType.injectFailureIfExistsAfterServer((Integer)invocation.getAsIsValue("FAILOVER_COUNTER"));
+         }
+         
+         return super.invoke(invocation);
+      }
+      
+   }
+   
+   public static class MockJRMPInvokerProxyHA extends JRMPInvokerProxyHA
+   {
+
+      public MockJRMPInvokerProxyHA(ArrayList targets, LoadBalancePolicy policy, String proxyFamilyName, long viewId)
+      {
+         super(targets, policy, proxyFamilyName, viewId);
+      }
+
+      @Override
+      public boolean txContextAllowsFailover(Invocation invocation)
+      {
+         return super.txContextAllowsFailover(invocation);
+      }
+      
+      @Override
+      public Object invoke(Invocation invocation) throws Exception
+      {
+         return super.invoke(invocation);
+      }
+      
+      @Override
+      protected void putIfExistsTransactionTarget(Invocation invocation, Object tpc)
+      {
+         InvokerHaFailureType failureType = (InvokerHaFailureType)invocation.getValue("FAILURE_TYPE");
+         if (failureType != null)
+         {
+            failureType.injectFailureIfExistsBeforeServer();
+         }
+         
+         super.putIfExistsTransactionTarget(invocation, tpc);
+      }      
+   }
+
+}

Added: branches/JBPAPP_4_2_0_GA_CP/testsuite/src/main/org/jboss/test/cluster/invokerha/JRMPInvokerHaTransactionStickyUnitTestCase.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/testsuite/src/main/org/jboss/test/cluster/invokerha/JRMPInvokerHaTransactionStickyUnitTestCase.java	                        (rev 0)
+++ branches/JBPAPP_4_2_0_GA_CP/testsuite/src/main/org/jboss/test/cluster/invokerha/JRMPInvokerHaTransactionStickyUnitTestCase.java	2008-02-13 19:55:24 UTC (rev 69835)
@@ -0,0 +1,54 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2007, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY 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 along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.test.cluster.invokerha;
+
+import org.jboss.test.cluster.invokerha.JRMPInvokerHaUnitTestCase.JRMPInvokerHaFactory;
+import org.jboss.test.cluster.invokerha.AbstractInvokerHaTransactionSticky;
+
+/**
+ * JRMPInvokerHaTransactionStickyUnitTestCase.
+ * 
+ * @author <a href="mailto:galder.zamarreno at jboss.com">Galder Zamarreno</a>
+ */
+public class JRMPInvokerHaTransactionStickyUnitTestCase extends AbstractInvokerHaTransactionSticky
+{
+   @Override
+   protected void setUp() throws Exception
+   {
+      setUp(2, new JRMPInvokerHaTransactionStickyFactory());
+   }
+
+   @Override
+   protected void tearDown() throws Exception
+   {
+      super.tearDown();
+   }   
+   
+   public static class JRMPInvokerHaTransactionStickyFactory extends JRMPInvokerHaFactory
+   {
+      @Override
+      public String getChosenTargetKey()
+      {
+         return "TX_STICKY_TARGET";
+      }
+   }
+}

Added: branches/JBPAPP_4_2_0_GA_CP/testsuite/src/main/org/jboss/test/cluster/invokerha/JRMPInvokerHaUnitTestCase.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/testsuite/src/main/org/jboss/test/cluster/invokerha/JRMPInvokerHaUnitTestCase.java	                        (rev 0)
+++ branches/JBPAPP_4_2_0_GA_CP/testsuite/src/main/org/jboss/test/cluster/invokerha/JRMPInvokerHaUnitTestCase.java	2008-02-13 19:55:24 UTC (rev 69835)
@@ -0,0 +1,81 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2007, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY 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 along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.test.cluster.invokerha;
+
+import java.util.WeakHashMap;
+
+import org.jboss.invocation.InvokerHA;
+import org.jboss.invocation.jrmp.interfaces.JRMPInvokerProxyHA;
+import org.jboss.test.cluster.invokerha.AbstractInvokerHa;
+import org.jboss.test.cluster.invokerha.InvokerHaInfrastructure;
+import org.jboss.test.cluster.invokerha.InvokerHaInfrastructure.InvokerHaFactory;
+import org.jboss.test.cluster.invokerha.JRMPInvokerHaMockUtils.MockJRMPInvokerHA;
+
+/**
+ * Unit test case for jrmp invoker ha proxy and invoker at the other side.
+ *  
+ * @author <a href="mailto:galder.zamarreno at jboss.com">Galder Zamarreno</a>
+ */
+public class JRMPInvokerHaUnitTestCase extends AbstractInvokerHa
+{
+   @Override
+   protected void setUp() throws Exception
+   {
+      setUp(2, new JRMPInvokerHaFactory());
+   }
+
+   @Override
+   protected void tearDown() throws Exception
+   {
+      super.tearDown();
+   }
+   
+   /** Classes **/
+   
+   public static class JRMPInvokerHaFactory implements InvokerHaFactory
+   {
+      public String getInvokerTypeName()
+      {
+         return "JRMPInvokerHa";
+      }
+
+      public InvokerHaInfrastructure getInvokerHaInfrastructure(int serverCount)
+      {
+         return new InvokerHaInfrastructure(serverCount, this);
+      }
+      
+      public WeakHashMap getTxFailoverAuthorizationsMap()
+      {
+         return JRMPInvokerProxyHA.txFailoverAuthorizations;
+      }
+
+      public InvokerHA createInvokerHaServer(String serverName, int serverNumber)
+      {
+         return new MockJRMPInvokerHA(getInvokerTypeName() + "-" + serverName + "-" + serverNumber);
+      }
+      
+      public String getChosenTargetKey()
+      {
+         return "TEST_CHOSEN_TARGET";
+      }
+   }
+}

Modified: branches/JBPAPP_4_2_0_GA_CP/testsuite/src/main/org/jboss/test/cluster/invokerha/UnifiedInvokerHaMockUtils.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/testsuite/src/main/org/jboss/test/cluster/invokerha/UnifiedInvokerHaMockUtils.java	2008-02-13 19:53:44 UTC (rev 69834)
+++ branches/JBPAPP_4_2_0_GA_CP/testsuite/src/main/org/jboss/test/cluster/invokerha/UnifiedInvokerHaMockUtils.java	2008-02-13 19:55:24 UTC (rev 69835)
@@ -72,7 +72,7 @@
       @Override
       public String toString()
       {         
-         return name;
+         return name + "," + super.toString();
       }
 
       public void setLocator(InvokerLocator locator)
@@ -101,6 +101,21 @@
       }
       
       @Override
+      public Object invoke(InvocationRequest invocationReq) throws Throwable
+      {
+         Invocation invocation = (Invocation) invocationReq.getParameter(); 
+         InvokerHaFailureType failureType = (InvokerHaFailureType)invocation.getValue("FAILURE_TYPE");
+         if (failureType != null)
+         {
+            failureType.injectFailureIfExistsAfterServer((Integer)invocation.getAsIsValue("FAILOVER_COUNTER"));
+         }
+         
+         log.debug("invoking on " + invocation.getObjectName());
+         
+         return super.invoke(invocationReq);
+      }
+            
+      @Override
       protected SerializationManager getSerializationManager() throws IOException
       {
          return new JavaSerializationManager();
@@ -127,6 +142,17 @@
          return ((MockInvokerLocator)locator).getClient();
       }
 
+      @Override
+      protected void putIfExistsTransactionTarget(Invocation invocation, Object tpc)
+      {
+         InvokerHaFailureType failureType = (InvokerHaFailureType)invocation.getValue("FAILURE_TYPE");
+         if (failureType != null)
+         {
+            failureType.injectFailureIfExistsBeforeServer();
+         }
+         
+         super.putIfExistsTransactionTarget(invocation, tpc);
+      }
    }
 
    public static class MockInvokerLocator extends InvokerLocator
@@ -147,6 +173,20 @@
       {
          return client;
       }
+      
+      @Override
+      public String toString()
+      {
+         return super.toString() + ",[client=" + client + "]";
+      }
+      
+      @Override
+      public boolean equals(Object obj)
+      {
+         /* reimplemented equals to avoid lingering static family cluster info 
+          * references being valid in latter tests */
+         return super.equals(obj) && client.equals(((MockInvokerLocator)obj).getClient());
+      }      
    }
 
    public static class MockClient extends Client
@@ -197,6 +237,12 @@
          TransactionPropagationContextFactory tpcFactory = TransactionPropagationContextUtil.getTPCFactoryClientSide();
          return (tpcFactory == null) ? null : tpcFactory.getTransactionPropagationContext();
       }
+      
+      @Override
+      public String toString()
+      {
+         return invoker.toString();
+      }      
    }
    
    public static class MockClientInvoker implements ClientInvoker

Added: branches/JBPAPP_4_2_0_GA_CP/testsuite/src/main/org/jboss/test/cluster/invokerha/UnifiedInvokerHaTransactionStickyUnitTestCase.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/testsuite/src/main/org/jboss/test/cluster/invokerha/UnifiedInvokerHaTransactionStickyUnitTestCase.java	                        (rev 0)
+++ branches/JBPAPP_4_2_0_GA_CP/testsuite/src/main/org/jboss/test/cluster/invokerha/UnifiedInvokerHaTransactionStickyUnitTestCase.java	2008-02-13 19:55:24 UTC (rev 69835)
@@ -0,0 +1,54 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2007, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY 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 along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.test.cluster.invokerha;
+
+import org.jboss.test.cluster.invokerha.UnifiedInvokerHaUnitTestCase.UnifiedInvokerHaFactory;
+import org.jboss.test.cluster.invokerha.AbstractInvokerHaTransactionSticky;
+
+/**
+ * UnifiedInvokerHaTransactionStickyUnitTestCase.
+ * 
+ * @author <a href="mailto:galder.zamarreno at jboss.com">Galder Zamarreno</a>
+ */
+public class UnifiedInvokerHaTransactionStickyUnitTestCase extends AbstractInvokerHaTransactionSticky
+{
+   @Override
+   protected void setUp() throws Exception
+   {
+      setUp(2, new UnifiedInvokerHaTransactionStickyFactory());
+   }
+
+   @Override
+   protected void tearDown() throws Exception
+   {
+      super.tearDown();
+   }   
+   
+   public static class UnifiedInvokerHaTransactionStickyFactory extends UnifiedInvokerHaFactory
+   {
+      @Override
+      public String getChosenTargetKey()
+      {
+         return "TX_STICKY_TARGET";
+      }
+   }
+}

Modified: branches/JBPAPP_4_2_0_GA_CP/testsuite/src/main/org/jboss/test/cluster/invokerha/UnifiedInvokerHaUnitTestCase.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/testsuite/src/main/org/jboss/test/cluster/invokerha/UnifiedInvokerHaUnitTestCase.java	2008-02-13 19:53:44 UTC (rev 69834)
+++ branches/JBPAPP_4_2_0_GA_CP/testsuite/src/main/org/jboss/test/cluster/invokerha/UnifiedInvokerHaUnitTestCase.java	2008-02-13 19:55:24 UTC (rev 69835)
@@ -23,6 +23,7 @@
 
 import java.util.ArrayList;
 import java.util.List;
+import java.util.WeakHashMap;
 
 import javax.management.ObjectName;
 
@@ -31,7 +32,6 @@
 import org.jboss.invocation.unified.interfaces.UnifiedInvokerHAProxy;
 import org.jboss.remoting.InvokerLocator;
 import org.jboss.test.cluster.invokerha.InvokerHaInfrastructure.InvokerHaFactory;
-import org.jboss.test.cluster.invokerha.InvokerHaInfrastructure.TraceRoundRobin;
 import org.jboss.test.cluster.invokerha.UnifiedInvokerHaMockUtils.MockClient;
 import org.jboss.test.cluster.invokerha.UnifiedInvokerHaMockUtils.MockInvokerLocator;
 import org.jboss.test.cluster.invokerha.UnifiedInvokerHaMockUtils.MockUnifiedInvokerHA;
@@ -58,21 +58,16 @@
       super.tearDown();
    }
    
-   public void testSuccessfulCallsRoundRobin() throws Exception
-   {
-      successfulCalls(TraceRoundRobin.class, UnifiedInvokerHAProxy.txFailoverAuthorizations);      
-   }
-
    /** Classes **/
    
    /**
     * Unified invoker ha factory. 
     */
-   public class UnifiedInvokerHaFactory implements InvokerHaFactory
+   public static class UnifiedInvokerHaFactory implements InvokerHaFactory
    {
       public String getInvokerTypeName()
       {
-         return "UnifiedInvokerHA";
+         return "UnifiedInvokerHa";
       }
       
       public InvokerHaInfrastructure getInvokerHaInfrastructure(int serverCount)
@@ -80,8 +75,13 @@
          return new UnifiedInvokerHaInfrastructure(serverCount, this);
       }
       
-      public InvokerHA createInvokerHAServer(String serverName, int serverNumber)
+      public WeakHashMap getTxFailoverAuthorizationsMap()
       {
+         return UnifiedInvokerHAProxy.txFailoverAuthorizations;
+      }
+      
+      public InvokerHA createInvokerHaServer(String serverName, int serverNumber)
+      {
          MockUnifiedInvokerHA invoker = new MockUnifiedInvokerHA(getInvokerTypeName() + "-" + serverName + "-" + serverNumber);
          MockClient client = new MockClient(invoker);
          MockInvokerLocator locator = new MockInvokerLocator("127.0.0.1", serverNumber, client);
@@ -89,12 +89,17 @@
          
          return invoker;          
       }
+      
+      public String getChosenTargetKey()
+      {
+         return "TEST_CHOSEN_TARGET";
+      }
    }
    
    /**
     * Unified invoker specific infrastructure class.
     */
-   public class UnifiedInvokerHaInfrastructure extends InvokerHaInfrastructure
+   public static class UnifiedInvokerHaInfrastructure extends InvokerHaInfrastructure
    {
       public UnifiedInvokerHaInfrastructure(int serverCount, InvokerHaFactory invokerHaFactory)
       {




More information about the jboss-cvs-commits mailing list