[jboss-cvs] JBossAS SVN: r112519 - in projects/ejb3/branches/jboss-ejb3-core-1.3/src: test/java/org/jboss/ejb3/test and 2 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Dec 14 16:55:28 EST 2011


Author: bmaxwell
Date: 2011-12-14 16:55:28 -0500 (Wed, 14 Dec 2011)
New Revision: 112519

Added:
   projects/ejb3/branches/jboss-ejb3-core-1.3/src/test/java/org/jboss/ejb3/test/ejbthree2275/
   projects/ejb3/branches/jboss-ejb3-core-1.3/src/test/java/org/jboss/ejb3/test/ejbthree2275/Counter.java
   projects/ejb3/branches/jboss-ejb3-core-1.3/src/test/java/org/jboss/ejb3/test/ejbthree2275/SimpleSFSB2.java
Modified:
   projects/ejb3/branches/jboss-ejb3-core-1.3/src/main/java/org/jboss/ejb3/cache/simple/SimpleStatefulCache.java
   projects/ejb3/branches/jboss-ejb3-core-1.3/src/test/java/org/jboss/ejb3/test/ejbthree2030/unit/SimpleStatefulCacheTestCase.java
Log:
[EJBTHREE-2275] fix RemovalTimeoutTask so that it calls remove(..) which invokes PreDestory callback

Modified: projects/ejb3/branches/jboss-ejb3-core-1.3/src/main/java/org/jboss/ejb3/cache/simple/SimpleStatefulCache.java
===================================================================
--- projects/ejb3/branches/jboss-ejb3-core-1.3/src/main/java/org/jboss/ejb3/cache/simple/SimpleStatefulCache.java	2011-12-14 10:50:59 UTC (rev 112518)
+++ projects/ejb3/branches/jboss-ejb3-core-1.3/src/main/java/org/jboss/ejb3/cache/simple/SimpleStatefulCache.java	2011-12-14 21:55:28 UTC (rev 112519)
@@ -173,8 +173,8 @@
                      if (now - centry.lastUsed >= removalTimeout * 1000)
                      {
                         synchronized (centry)
-                        {                                                                    
-                           it.remove();
+                        {
+                           remove(centry.getId(), it);
                         }
                      }
                   }                  
@@ -571,6 +571,11 @@
 
    public void remove(Object key)
    {
+	   remove(key, null);
+   }
+   
+   public void remove(Object key, Iterator it)
+   {
       if(log.isTraceEnabled())
       {
          log.trace("Removing context " + key);
@@ -589,10 +594,17 @@
       
       if (ctx.getCanRemoveFromCache())
       {
-         synchronized (cacheMap)
+         if(it == null)
          {
-            cacheMap.remove(key);
+            synchronized (cacheMap)
+            {
+               cacheMap.remove(key);
+            }
          }
+         else
+         {
+        	 it.remove();
+         }
       }
    }
 

Modified: projects/ejb3/branches/jboss-ejb3-core-1.3/src/test/java/org/jboss/ejb3/test/ejbthree2030/unit/SimpleStatefulCacheTestCase.java
===================================================================
--- projects/ejb3/branches/jboss-ejb3-core-1.3/src/test/java/org/jboss/ejb3/test/ejbthree2030/unit/SimpleStatefulCacheTestCase.java	2011-12-14 10:50:59 UTC (rev 112518)
+++ projects/ejb3/branches/jboss-ejb3-core-1.3/src/test/java/org/jboss/ejb3/test/ejbthree2030/unit/SimpleStatefulCacheTestCase.java	2011-12-14 21:55:28 UTC (rev 112519)
@@ -21,6 +21,8 @@
 */
 package org.jboss.ejb3.test.ejbthree2030.unit;
 
+import java.util.Date;
+
 import javax.ejb.NoSuchEJBException;
 
 import org.jboss.ejb3.cache.simple.SimpleStatefulCache;
@@ -28,6 +30,7 @@
 import org.jboss.ejb3.session.SessionContainer;
 import org.jboss.ejb3.stateful.StatefulBeanContext;
 import org.jboss.ejb3.test.ejbthree2030.SimpleSFSB;
+import org.jboss.ejb3.test.ejbthree2275.SimpleSFSB2;
 import org.jboss.logging.Logger;
 import org.junit.AfterClass;
 import org.junit.Assert;
@@ -57,11 +60,15 @@
     * Container for {@link SimpleSFSB}
     */
    private static SessionContainer container;
+   
+   private static SessionContainer container2;
 
    /**
     * A {@link SimpleStatefulCache} for the {@link #container}
     */
    private static SimpleStatefulCache cache;
+   
+   private static SimpleStatefulCache cache2;
 
    /**
     * Deploy the bean, create the container and init/start the cache
@@ -74,10 +81,15 @@
 
       // Deploy the test SLSB
       container = deploySessionEjb(SimpleSFSB.class);
-
       cache = new SimpleStatefulCache();
       cache.initialize(container);
       cache.start();
+      
+      // EJBTHREE-2275 - test ejb3 with removal timeout < passivation timeout
+      container2 = deploySessionEjb(SimpleSFSB2.class);
+      cache2 = new SimpleStatefulCache();
+      cache2.initialize(container2);
+      cache2.start();
    }
 
    /**
@@ -88,10 +100,12 @@
    public static void afterClass() throws Exception
    {
       cache.stop();
-
+      cache2.stop();
+      
       // Undeploy the test SLSB
       undeployEjb(container);
-
+      undeployEjb(container2);
+      
       AbstractEJB3TestCase.afterClass();
 
    }
@@ -141,4 +155,42 @@
          // expected
       }
    }
+   
+   // JBPAPP-7724
+   /**
+    * Tests that when a {@link StatefulBeanContext} is passivated and later a remove() for that
+    * context is invoked, the {@link SimpleStatefulCache} first activates the session and then
+    * successfully removes it
+    * 
+    * @throws Exception
+    */
+   @Test
+   public void testRemovalAfterRemovalTimeout() throws Exception
+   {
+      // create a session
+      StatefulBeanContext sfsbContext = cache2.create();
+      Object sessionId = sfsbContext.getId();      
+      logger.info("Created StatefulBeanContext with session id " + sessionId);
+      // mark it as *not in use* so that it can be passivated
+      sfsbContext.setInUse(true);
+      // set last used to now
+      sfsbContext.lastUsed = new Date().getTime();
+      
+      // wait for 3 (or more seconds for removal to happen)
+      // The SimpleSFSB is configured for a removalTimeoutSeconds of 1 seconds (so that it will be 
+      // removed after 1 seconds, idleTimeout is set to 10)
+      logger.info("Sleeping for 3 seconds to allow removal thread to remove the bean context with id "
+            + sessionId);
+      Thread.sleep(3000);
+      
+      if(! sfsbContext.isRemoved())
+      {
+    	  Assert.fail("SFSB context should be removed now EJBTHREE-2275");
+           
+    	  logger.info("Clean up - trying to remove session " + sessionId + " from cache");
+    	  cache2.remove(sessionId);
+    	  logger.info("Successfully removed " + sessionId + " from cache");
+      }
+   }
+
 }

Added: projects/ejb3/branches/jboss-ejb3-core-1.3/src/test/java/org/jboss/ejb3/test/ejbthree2275/Counter.java
===================================================================
--- projects/ejb3/branches/jboss-ejb3-core-1.3/src/test/java/org/jboss/ejb3/test/ejbthree2275/Counter.java	                        (rev 0)
+++ projects/ejb3/branches/jboss-ejb3-core-1.3/src/test/java/org/jboss/ejb3/test/ejbthree2275/Counter.java	2011-12-14 21:55:28 UTC (rev 112519)
@@ -0,0 +1,35 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.ejb3.test.ejbthree2275;
+
+/**
+ * Counter
+ *
+ * @author Jaikiran Pai
+ * @version $Revision: $
+ */
+public interface Counter
+{
+   void incrementCount();
+
+   int getCount();
+}

Added: projects/ejb3/branches/jboss-ejb3-core-1.3/src/test/java/org/jboss/ejb3/test/ejbthree2275/SimpleSFSB2.java
===================================================================
--- projects/ejb3/branches/jboss-ejb3-core-1.3/src/test/java/org/jboss/ejb3/test/ejbthree2275/SimpleSFSB2.java	                        (rev 0)
+++ projects/ejb3/branches/jboss-ejb3-core-1.3/src/test/java/org/jboss/ejb3/test/ejbthree2275/SimpleSFSB2.java	2011-12-14 21:55:28 UTC (rev 112519)
@@ -0,0 +1,61 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.ejb3.test.ejbthree2275;
+
+import javax.ejb.Remote;
+import javax.ejb.Stateful;
+
+import org.jboss.ejb3.annotation.CacheConfig;
+
+/**
+ * SimpleSFSB2
+ *
+ * @author Brad Maxwell
+ * @version $Revision: $
+ */
+ at Stateful(name="EJBTHREE-2275-SFSB")
+ at Remote(Counter.class)
+// set removalTimeoutSeconds to 1 second and idletimeout to 10 seconds to allow removal to occur before passivation
+ at CacheConfig(idleTimeoutSeconds = 10, removalTimeoutSeconds=1)
+public class SimpleSFSB2 implements Counter
+{
+
+   private int count;
+
+   /**
+    * @see org.jboss.ejb3.test.ejbthree2275.Counter#getCount()
+    */
+   public int getCount()
+   {
+      return this.count;
+   }
+
+   /**
+    * @see org.jboss.ejb3.test.ejbthree2275.Counter#incrementCount()
+    */
+   public void incrementCount()
+   {
+      this.count++;
+
+   }
+
+}



More information about the jboss-cvs-commits mailing list