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

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Dec 14 18:31:01 EST 2011


Author: bmaxwell
Date: 2011-12-14 18:31:00 -0500 (Wed, 14 Dec 2011)
New Revision: 112520

Added:
   projects/ejb3/branches/jboss-ejb3-core-1.3/src/test/java/org/jboss/ejb3/test/ejbthree2275/SimpleSFSB.java
   projects/ejb3/branches/jboss-ejb3-core-1.3/src/test/java/org/jboss/ejb3/test/ejbthree2275/unit/
   projects/ejb3/branches/jboss-ejb3-core-1.3/src/test/java/org/jboss/ejb3/test/ejbthree2275/unit/SimpleStatefulCacheRemovalTestCase.java
Removed:
   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/test/java/org/jboss/ejb3/test/ejbthree2030/unit/SimpleStatefulCacheTestCase.java
Log:
[EJBTHREE-2275] moved testcase to its own testcase file

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 21:55:28 UTC (rev 112519)
+++ projects/ejb3/branches/jboss-ejb3-core-1.3/src/test/java/org/jboss/ejb3/test/ejbthree2030/unit/SimpleStatefulCacheTestCase.java	2011-12-14 23:31:00 UTC (rev 112520)
@@ -21,8 +21,6 @@
 */
 package org.jboss.ejb3.test.ejbthree2030.unit;
 
-import java.util.Date;
-
 import javax.ejb.NoSuchEJBException;
 
 import org.jboss.ejb3.cache.simple.SimpleStatefulCache;
@@ -30,7 +28,6 @@
 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;
@@ -60,15 +57,11 @@
     * 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
@@ -81,15 +74,10 @@
 
       // 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();
    }
 
    /**
@@ -100,12 +88,10 @@
    public static void afterClass() throws Exception
    {
       cache.stop();
-      cache2.stop();
-      
+
       // Undeploy the test SLSB
       undeployEjb(container);
-      undeployEjb(container2);
-      
+
       AbstractEJB3TestCase.afterClass();
 
    }
@@ -155,42 +141,4 @@
          // 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/SimpleSFSB.java
===================================================================
--- projects/ejb3/branches/jboss-ejb3-core-1.3/src/test/java/org/jboss/ejb3/test/ejbthree2275/SimpleSFSB.java	                        (rev 0)
+++ projects/ejb3/branches/jboss-ejb3-core-1.3/src/test/java/org/jboss/ejb3/test/ejbthree2275/SimpleSFSB.java	2011-12-14 23:31:00 UTC (rev 112520)
@@ -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;
+
+/**
+ * SimpleSFSB
+ *
+ * @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 SimpleSFSB 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++;
+
+   }
+
+}

Deleted: 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	2011-12-14 21:55:28 UTC (rev 112519)
+++ projects/ejb3/branches/jboss-ejb3-core-1.3/src/test/java/org/jboss/ejb3/test/ejbthree2275/SimpleSFSB2.java	2011-12-14 23:31:00 UTC (rev 112520)
@@ -1,61 +0,0 @@
-/*
-* 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++;
-
-   }
-
-}

Added: projects/ejb3/branches/jboss-ejb3-core-1.3/src/test/java/org/jboss/ejb3/test/ejbthree2275/unit/SimpleStatefulCacheRemovalTestCase.java
===================================================================
--- projects/ejb3/branches/jboss-ejb3-core-1.3/src/test/java/org/jboss/ejb3/test/ejbthree2275/unit/SimpleStatefulCacheRemovalTestCase.java	                        (rev 0)
+++ projects/ejb3/branches/jboss-ejb3-core-1.3/src/test/java/org/jboss/ejb3/test/ejbthree2275/unit/SimpleStatefulCacheRemovalTestCase.java	2011-12-14 23:31:00 UTC (rev 112520)
@@ -0,0 +1,135 @@
+/*
+* 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.unit;
+
+import java.util.Date;
+
+import javax.ejb.NoSuchEJBException;
+
+import org.jboss.ejb3.cache.simple.SimpleStatefulCache;
+import org.jboss.ejb3.core.test.common.AbstractEJB3TestCase;
+import org.jboss.ejb3.session.SessionContainer;
+import org.jboss.ejb3.stateful.StatefulBeanContext;
+import org.jboss.ejb3.test.ejbthree2275.SimpleSFSB;
+import org.jboss.logging.Logger;
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ * SimpleStatefulCacheRemovalTest
+ * 
+ * Tests the {@link SimpleStatefulCache}
+ * <p>
+ *  More specifically, tests the fix for https://jira.jboss.org/jira/browse/EJBTHREE-2030, where
+ *  a remove() on the cache was *not* checking for passivated sessions.
+ * </p>
+ * @author Brad Maxwell
+ * @version $Revision: $
+ */
+public class SimpleStatefulCacheRemovalTestCase extends AbstractEJB3TestCase
+{
+
+   /**
+    * Logger
+    */
+   private static Logger logger = Logger.getLogger(SimpleStatefulCacheRemovalTestCase.class);
+
+   /**
+    * Container for {@link SimpleSFSB}
+    */
+   private static SessionContainer container;
+   
+   /**
+    * A {@link SimpleStatefulCache} for the {@link #container}
+    */
+   private static SimpleStatefulCache cache;
+   
+   /**
+    * Deploy the bean, create the container and init/start the cache
+    * @throws Exception
+    */
+   @BeforeClass
+   public static void beforeClass() throws Exception
+   {
+      AbstractEJB3TestCase.beforeClass();
+
+      // Deploy the test SLSB
+      // EJBTHREE-2275 - test ejb3 with removal timeout < passivation timeout
+      container = deploySessionEjb(SimpleSFSB.class);
+      cache = new SimpleStatefulCache();
+      cache.initialize(container);
+      cache.start();
+   }
+
+   /**
+    * Cleanup
+    * @throws Exception
+    */
+   @AfterClass
+   public static void afterClass() throws Exception
+   {
+      cache.stop();
+      
+      // Undeploy the test SLSB
+      undeployEjb(container);
+      
+      AbstractEJB3TestCase.afterClass();
+   }
+
+   /**
+    * 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 = cache.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");
+    	  cache.remove(sessionId);
+    	  logger.info("Successfully removed " + sessionId + " from cache");
+      }
+   }
+}



More information about the jboss-cvs-commits mailing list