[jboss-cvs] JBossAS SVN: r112118 - in branches/JBPAPP_5_1/testsuite/src/main/org/jboss/test/cluster: ejb3/ustxsticky and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Aug 24 12:13:49 EDT 2011


Author: pferraro
Date: 2011-08-24 12:13:49 -0400 (Wed, 24 Aug 2011)
New Revision: 112118

Modified:
   branches/JBPAPP_5_1/testsuite/src/main/org/jboss/test/cluster/defaultcfg/ejb3/ustxsticky/test/UserTransactionStickyUnitTestCase.java
   branches/JBPAPP_5_1/testsuite/src/main/org/jboss/test/cluster/ejb3/ustxsticky/UserTransactionStickyBean.java
Log:
Enhance EJB3 transaction stickiness test to validate invocations from multiple bean instances.

Modified: branches/JBPAPP_5_1/testsuite/src/main/org/jboss/test/cluster/defaultcfg/ejb3/ustxsticky/test/UserTransactionStickyUnitTestCase.java
===================================================================
--- branches/JBPAPP_5_1/testsuite/src/main/org/jboss/test/cluster/defaultcfg/ejb3/ustxsticky/test/UserTransactionStickyUnitTestCase.java	2011-08-24 15:50:08 UTC (rev 112117)
+++ branches/JBPAPP_5_1/testsuite/src/main/org/jboss/test/cluster/defaultcfg/ejb3/ustxsticky/test/UserTransactionStickyUnitTestCase.java	2011-08-24 16:13:49 UTC (rev 112118)
@@ -38,14 +38,14 @@
 
 /**
  * UserTransactionStickyTestCase.
- * 
+ *
  * @author Paul Ferraro
  */
 public class UserTransactionStickyUnitTestCase extends JBossClusteredTestCase
-{   
+{
    private static final String deployment = "ustxsticky-ejb3.jar";
 
-   private static final Logger log = Logger.getLogger(UserTransactionStickyUnitTestCase.class);   
+   private static final Logger log = Logger.getLogger(UserTransactionStickyUnitTestCase.class);
 
    public UserTransactionStickyUnitTestCase(String name)
    {
@@ -56,57 +56,116 @@
    {
       return getDeploySetup(UserTransactionStickyUnitTestCase.class, deployment);
    }
-   
+
    public void testSeveralTransactionalStickyCalls() throws Exception
    {
-      severalTransactionalCalls("ejb3/UserTransactionSticky");
+      test(1);
    }
 
-   private void severalTransactionalCalls(String jndiName) throws Exception
+   public void testMoreBeansInTransaction() throws Exception
    {
+      test(3);
+   }
+
+   private void test(int beanCount) throws Exception
+   {
       // Connect to the server0 JNDI
       String[] urls = getNamingURLs();
       Properties env1 = new Properties();
       env1.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.NamingContextFactory");
       env1.setProperty(Context.PROVIDER_URL, urls[0]);
       Context ctx = new InitialContext(env1);
-      
-      UserTransactionSticky bean = (UserTransactionSticky)ctx.lookup(jndiName);
-      bean.test(-1);
-      bean.test(-1);
-      bean.test(-1);
-      
+
+      UserTransactionSticky[] beans = new UserTransactionSticky[beanCount];
+      // Validate non-tx behavior
+      for (int i = 0; i < beanCount; ++i)
+      {
+         beans[i] = (UserTransactionSticky) ctx.lookup("ejb3/UserTransactionSticky");
+         try
+         {
+            beans[i].test(-1);
+            beans[i].test(-1);
+         }
+         catch (Exception e)
+         {
+            e.printStackTrace(System.err);
+            fail("Bean[" + i + "]");
+         }
+      }
+
       javax.transaction.UserTransaction tx = (javax.transaction.UserTransaction) ctx.lookup("UserTransaction");
       tx.begin();
-      // Stick tx to a node
-      bean.test(-1);
-      bean.test(-1);
-      bean.test(-1);
-      try
+      for (int i = 0; i < beanCount; ++i)
       {
-         // This should fail since tx prevents failover
-         bean.test(GenericClusteringException.COMPLETED_NO);
-         fail();
+         // Stick tx to a node
+         beans[i] = (UserTransactionSticky) ctx.lookup("ejb3/UserTransactionSticky");
+         try
+         {
+            beans[i].test(-1);
+            beans[i].test(-1);
+         }
+         catch (Exception e)
+         {
+            e.printStackTrace(System.err);
+            fail("Bean[" + i + "]");
+         }
+         try
+         {
+            // This would normally trigger failover, except tx stickiness should prevent this
+            beans[i].test(GenericClusteringException.COMPLETED_NO);
+            fail("Bean[" + i + "]");
+         }
+         catch (Exception e)
+         {
+            assertTrue("Bean[" + i + "] " + e.getMessage(), e.getMessage().startsWith("Current transaction is stuck to"));
+         }
+         try
+         {
+            // This would normally failover, except tx stickiness should prevent this
+            beans[i].test(-1);
+            fail("Bean[" + i + "]");
+         }
+         catch (Exception e)
+         {
+            assertTrue("Bean[" + i + "] " + e.getMessage(), e.getMessage().startsWith("Current transaction is stuck to"));
+         }
       }
-      catch (Exception e)
-      {
-         assertTrue(e.getMessage(), e.getMessage().startsWith("Current transaction is stuck to"));
-      }
       tx.rollback();
 
       // Not in tx anymore
-      bean.test(-1);
-      bean.test(-1);
-      bean.test(-1);
-      try
+      for (int i = 0; i < beanCount; ++i)
       {
-         // This should fail since there are no more cluster members left
-         bean.test(GenericClusteringException.COMPLETED_NO);
-         fail();
+         beans[i] = (UserTransactionSticky) ctx.lookup("ejb3/UserTransactionSticky");
+         try
+         {
+            beans[i].test(-1);
+            beans[i].test(-1);
+         }
+         catch (Exception e)
+         {
+            e.printStackTrace(System.err);
+            fail("Bean[" + i + "]");
+         }
+         try
+         {
+            // This should fail since there are no more cluster members left
+            beans[i].test(GenericClusteringException.COMPLETED_NO);
+            fail("Bean[" + i + "]");
+         }
+         catch (Exception e)
+         {
+            assertTrue("Bean[" + i + "] " + e.getMessage(), e.getMessage().startsWith("cluster invocation failed"));
+         }
+         try
+         {
+            // This should fail since there are no more cluster members left
+            beans[i].test(-1);
+            fail("Bean[" + i + "]");
+         }
+         catch (Exception e)
+         {
+            assertTrue("Bean[" + i + "] " + e.getMessage(), e.getMessage().startsWith("Unreachable?"));
+         }
       }
-      catch (Exception e)
-      {
-         assertTrue(e.getMessage(), e.getMessage().startsWith("cluster invocation failed"));
-      }
    }
 }

Modified: branches/JBPAPP_5_1/testsuite/src/main/org/jboss/test/cluster/ejb3/ustxsticky/UserTransactionStickyBean.java
===================================================================
--- branches/JBPAPP_5_1/testsuite/src/main/org/jboss/test/cluster/ejb3/ustxsticky/UserTransactionStickyBean.java	2011-08-24 15:50:08 UTC (rev 112117)
+++ branches/JBPAPP_5_1/testsuite/src/main/org/jboss/test/cluster/ejb3/ustxsticky/UserTransactionStickyBean.java	2011-08-24 16:13:49 UTC (rev 112118)
@@ -76,22 +76,12 @@
    @AroundInvoke
    public Object intercept(InvocationContext ctx) throws Exception
    {
-      System.out.println(ctx.getMethod().getName());
-      try
-      {
-         javax.transaction.Transaction tx = org.jboss.ejb3.tx.TxUtil.getTransactionManager().getTransaction();
-         System.out.println("Transaction is " + ((tx != null) ? "not " : "") + "null");
-//         UserTransaction tpc = this.context.getUserTransaction();
-//         System.out.println("UserTransaction is " + ((tpc != null) ? "not " : "") + "null");
+      javax.transaction.Transaction tx = org.jboss.ejb3.tx.TxUtil.getTransactionManager().getTransaction();
+      System.out.println("Transaction is " + ((tx != null) ? "not " : "") + "null");
          
-         Object tpc = TransactionPropagationContextUtil.getTPCFactoryClientSide().getTransactionPropagationContext();
-         System.out.println("TPC = " + tpc);
-/*
-         UserTransaction tpcFactory = this.context.getUserTransaction();
-      Object tpc = ((TransactionPropagationContextFactory) tpcFactory).getTransactionPropagationContext();
-      TransactionPropagationContextImporter tpcImporter = TransactionPropagationContextUtil.getTPCImporter();
-      Transaction tx = tpcImporter.importTransactionPropagationContext(tpc);
-      */
+      Object tpc = TransactionPropagationContextUtil.getTPCFactoryClientSide().getTransactionPropagationContext();
+      System.out.println("TPC = " + tpc);
+
       log.debug("Tpc " + tpc + " is associated with tx " + tx);
       
       /* If a tpc is retrieved on the server side but matches no transaction 
@@ -105,16 +95,5 @@
       }
       
       return ctx.proceed();
-      }
-      catch (Exception e)
-      {
-         e.printStackTrace(System.err);
-         throw e;
-      }
-      catch (Error e)
-      {
-         e.printStackTrace(System.err);
-         throw e;
-      }
    }
 }



More information about the jboss-cvs-commits mailing list