[jboss-cvs] JBossAS SVN: r99138 - in trunk/testsuite/src: main/org/jboss/test/cts/test and 1 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Jan 7 23:19:01 EST 2010


Author: bstansberry at jboss.com
Date: 2010-01-07 23:19:00 -0500 (Thu, 07 Jan 2010)
New Revision: 99138

Added:
   trunk/testsuite/src/main/org/jboss/test/cts/ejb/BadUserTxInterceptor.java
Modified:
   trunk/testsuite/src/main/org/jboss/test/cts/test/StatefulSessionUnitTestCase.java
   trunk/testsuite/src/resources/cts/META-INF/jboss.xml
Log:
[JBAS-7493] Use an Interceptor+Synchronization+JNDI to track bad tx

Added: trunk/testsuite/src/main/org/jboss/test/cts/ejb/BadUserTxInterceptor.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/cts/ejb/BadUserTxInterceptor.java	                        (rev 0)
+++ trunk/testsuite/src/main/org/jboss/test/cts/ejb/BadUserTxInterceptor.java	2010-01-08 04:19:00 UTC (rev 99138)
@@ -0,0 +1,110 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt 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.cts.ejb;
+
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+import javax.transaction.Synchronization;
+import javax.transaction.Transaction;
+import javax.transaction.TransactionManager;
+
+import org.jboss.ejb.plugins.AbstractInterceptor;
+import org.jboss.invocation.Invocation;
+
+/**
+ * Used by StatefulSessionUnitTestCase.testBadUserTx() to
+ * confirm that the user tx is properly rolled back
+ *
+ * @author Brian Stansberry
+ * 
+ * @version $Revision$
+ */
+public class BadUserTxInterceptor extends AbstractInterceptor
+{
+   /**
+    * Local reference to the container's TransactionManager.
+    */
+   private TransactionManager tm;
+   
+   public void create() throws Exception
+   {
+      super.create();
+      tm = getContainer().getTransactionManager();
+   }
+
+   @Override
+   public Object invoke(Invocation mi) throws Exception
+   {
+      try
+      {
+         return super.invoke(mi);
+      }
+      finally
+      {   
+         // The bean started a transaction; we register a 
+         // synchronization to monitor that another interceptor
+         // rolls it back
+         if ("testBadUserTx".equals(mi.getMethod().getName()))
+         {
+            Transaction tx = tm.getTransaction();
+            if (tx != null)
+            {
+               tx.registerSynchronization(new BadTxSynchronization());
+               log.debug("Registered BdTxSynchronization");
+            }
+            else
+            {
+               log.error("No transaction registered!!");
+            }
+         }
+         else
+         {
+            log.trace("ignoring method " + mi.getMethod().getName());
+         }
+      }
+   }
+   
+   private class BadTxSynchronization implements Synchronization
+   {
+      public void beforeCompletion()
+      {
+         log.debug("BdTxSynchronization received beforeCompletion() callback");
+      }
+
+      public void afterCompletion(int status)
+      {
+         // Store the status in JNDI so the test driver can read it. Hack-a-licious!
+         try
+         {
+            new InitialContext().bind("testBadUserTx", Integer.valueOf(status));
+            log.debug("BdTxSynchronization afterCompletion() status = " + status);
+         }
+         catch (NamingException e)
+         {
+            log.error("Cannot bind bad user tx status in JNDI", e);
+         }         
+      }
+      
+   }
+
+}


Property changes on: trunk/testsuite/src/main/org/jboss/test/cts/ejb/BadUserTxInterceptor.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision

Modified: trunk/testsuite/src/main/org/jboss/test/cts/test/StatefulSessionUnitTestCase.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/cts/test/StatefulSessionUnitTestCase.java	2010-01-08 03:36:56 UTC (rev 99137)
+++ trunk/testsuite/src/main/org/jboss/test/cts/test/StatefulSessionUnitTestCase.java	2010-01-08 04:19:00 UTC (rev 99138)
@@ -21,33 +21,36 @@
  */
 package org.jboss.test.cts.test;
 
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
 import java.io.FileInputStream;
 import java.io.FileOutputStream;
 import java.io.ObjectInputStream;
 import java.io.ObjectOutputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.ByteArrayInputStream;
 import java.rmi.RemoteException;
 import java.util.Properties;
+
 import javax.ejb.Handle;
 import javax.ejb.RemoveException;
-import javax.management.MBeanServerConnection;
 import javax.management.ObjectName;
+import javax.naming.Context;
 import javax.naming.InitialContext;
-import javax.naming.Context;
+import javax.naming.NameNotFoundException;
+import javax.naming.NamingException;
 import javax.rmi.PortableRemoteObject;
+import javax.transaction.Status;
 import javax.transaction.UserTransaction;
 
+import junit.framework.Test;
+
 import org.jboss.mx.util.ObjectNameFactory;
+import org.jboss.test.JBossTestCase;
+import org.jboss.test.cts.interfaces.BeanContextInfo;
 import org.jboss.test.cts.interfaces.StatefulSession;
 import org.jboss.test.cts.interfaces.StatefulSessionHome;
-import org.jboss.test.cts.interfaces.BeanContextInfo;
 import org.jboss.test.cts.interfaces.StrictlyPooledSessionHome;
 import org.jboss.test.cts.keys.AccountPK;
-import org.jboss.test.JBossTestCase;
 
-import junit.framework.Test;
-
 import EDU.oswego.cs.dl.util.concurrent.CountDown;
 
 
@@ -356,13 +359,13 @@
       // Get the EJBMetaData constructs
       getLog().debug("Get Home interface class");
 
-      java.lang.Class homeInterface = md.getHomeInterfaceClass();
+      java.lang.Class<?> homeInterface = md.getHomeInterfaceClass();
 
       getLog().debug("home Interface : " + homeInterface.getName());
       assertTrue(homeInterface.getName().equals("org.jboss.test.cts.interfaces.StatefulSessionHome"));
       getLog().debug("Get Remote Interface class");
 
-      java.lang.Class remoteInterface = md.getRemoteInterfaceClass();
+      java.lang.Class<?> remoteInterface = md.getRemoteInterfaceClass();
 
       getLog().debug("remote Interface: " + remoteInterface.getName());
       assertTrue(remoteInterface.getName().equals("org.jboss.test.cts.interfaces.StatefulSession"));
@@ -770,8 +773,7 @@
          StatefulSessionHome.class);
       StatefulSession bean = home.create("testBadUserTx");     
 
-      MBeanServerConnection server = getServer(); 
-      Long before = (Long) server.getAttribute(OBJECT_NAME, "TransactionCount");
+      clearJndiTxTracking();
       try
       {
          bean.testBadUserTx();
@@ -780,11 +782,44 @@
       catch (Throwable expected)
       {
          log.debug("Got exception", expected);
+         // A SessionSynchronization on the server stores the committed 
+         // status of the tx in JNDI; read it from there
+         Integer status = getBadUserTxStatus();
+         assertNotNull("Bad user tx status not found in JNDI", status);
+         assertTrue("Bad tx was rolled back", status == Status.STATUS_ROLLEDBACK || status == Status.STATUS_ROLLING_BACK);
       }
-      Long after = (Long) server.getAttribute(OBJECT_NAME, "TransactionCount");
-      assertEquals("Transaction should no longer be active before=" + before + " after=" + after, before, after);
+      finally
+      {
+         clearJndiTxTracking();
+      }
    }
 
+   private Integer getBadUserTxStatus() throws Exception
+   {
+      Integer result = null;
+      try
+      {
+         result = (Integer) getInitialContext().lookup("testBadUserTx");
+      }
+      catch (NamingException e)
+      {
+         log.error(e);
+      }
+      return result;
+   }
+
+   private void clearJndiTxTracking() throws Exception
+   {
+      try
+      {
+         getInitialContext().unbind("testBadUserTx");
+      }
+      catch (NameNotFoundException ignored)
+      {
+         log.debug(ignored);
+      }
+   }
+
    public static Test suite() throws Exception
    {
       return getDeploySetup(StatefulSessionUnitTestCase.class, "cts.jar");

Modified: trunk/testsuite/src/resources/cts/META-INF/jboss.xml
===================================================================
--- trunk/testsuite/src/resources/cts/META-INF/jboss.xml	2010-01-08 03:36:56 UTC (rev 99137)
+++ trunk/testsuite/src/resources/cts/META-INF/jboss.xml	2010-01-08 04:19:00 UTC (rev 99138)
@@ -20,7 +20,7 @@
          <ejb-name>BMTStatefulSessionBean</ejb-name>
          <jndi-name>ejbcts/BMTStatefulSessionBean</jndi-name>
          <local-jndi-name>ejbcts/BMTStatefulSessionLocalBean</local-jndi-name>
-         <configuration-name>MaxOne Stateful Session</configuration-name>
+         <configuration-name>Bad User Tx Stateful Session</configuration-name>
       </session>
       <session>
          <ejb-name>FacadeStatefulSessionBean</ejb-name>
@@ -131,6 +131,44 @@
             </cache-policy-conf>
          </container-cache-conf>
       </container-configuration>
+      
+      <container-configuration extends="Standard Stateful SessionBean">
+         <container-name>Bad User Tx Stateful Session</container-name>
+        <container-interceptors>
+          <interceptor>org.jboss.ejb.plugins.ProxyFactoryFinderInterceptor</interceptor>
+          <interceptor>org.jboss.ejb.plugins.LogInterceptor</interceptor>
+          <interceptor>org.jboss.ejb.plugins.security.PreSecurityInterceptor</interceptor>
+          <!-- CMT -->
+          <interceptor transaction="Container">org.jboss.ejb.plugins.TxInterceptorCMT</interceptor>
+          <interceptor transaction="Container">org.jboss.ejb.plugins.CallValidationInterceptor</interceptor>
+          <interceptor transaction="Container">org.jboss.ejb.plugins.StatefulSessionInstanceInterceptor</interceptor>
+          <!-- BMT -->
+          <interceptor transaction="Bean">org.jboss.ejb.plugins.StatefulSessionInstanceInterceptor</interceptor>
+          <interceptor transaction="Bean">org.jboss.ejb.plugins.TxInterceptorBMT</interceptor>
+          <interceptor transaction="Bean">org.jboss.ejb.plugins.CallValidationInterceptor</interceptor>
+          <interceptor>org.jboss.resource.connectionmanager.CachedConnectionInterceptor</interceptor>
+          <interceptor>org.jboss.ejb.plugins.SecurityInterceptor</interceptor>
+          <interceptor>org.jboss.ejb.plugins.StatefulSessionSecurityInterceptor</interceptor>
+          <!-- Here's the new one we add for the test -->
+          <interceptor>org.jboss.test.cts.ejb.BadUserTxInterceptor</interceptor>
+        </container-interceptors>
+         <container-cache-conf>
+            <cache-policy>org.jboss.ejb.plugins.LRUStatefulContextCachePolicy</cache-policy>
+            <cache-policy-conf>
+               <min-capacity>1</min-capacity>
+               <max-capacity>1</max-capacity>
+               <!-- Times are in seconds -->
+               <!-- How often to check for beans with an expired max-bean-life -->
+               <remover-period>20</remover-period>
+               <!-- How long before a passivated bean is a candidate for removal -->
+               <max-bean-life>45</max-bean-life>
+               <!-- How often to check for beans with an expired max-bean-age -->
+               <overager-period>15</overager-period>
+               <!-- How long before a bean is a candidate for passivation -->
+               <max-bean-age>15</max-bean-age>
+            </cache-policy-conf>
+         </container-cache-conf>
+      </container-configuration>
 
       <container-configuration extends="Standard Stateful SessionBean">
          <container-name>Long Wait Stateful Session</container-name>




More information about the jboss-cvs-commits mailing list