[jboss-cvs] JBossAS SVN: r60066 - in trunk/ejb3/src/test/org/jboss/ejb3/test/stateful: unit and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Sat Jan 27 18:08:22 EST 2007


Author: bstansberry at jboss.com
Date: 2007-01-27 18:08:22 -0500 (Sat, 27 Jan 2007)
New Revision: 60066

Added:
   trunk/ejb3/src/test/org/jboss/ejb3/test/stateful/nested/BaseNestedStatefulBean.java
   trunk/ejb3/src/test/org/jboss/ejb3/test/stateful/nested/LocalNestedStatefulBean.java
   trunk/ejb3/src/test/org/jboss/ejb3/test/stateful/nested/Removable.java
Modified:
   trunk/ejb3/src/test/org/jboss/ejb3/test/stateful/nested/NestedStateful.java
   trunk/ejb3/src/test/org/jboss/ejb3/test/stateful/nested/NestedStatefulBean.java
   trunk/ejb3/src/test/org/jboss/ejb3/test/stateful/nested/ParentStatefulBean.java
   trunk/ejb3/src/test/org/jboss/ejb3/test/stateful/nested/ParentStatefulRemote.java
   trunk/ejb3/src/test/org/jboss/ejb3/test/stateful/unit/NestedBeanUnitTestCase.java
Log:
Test nested sfsbs with @Local vs @Remote
Strengthen cleanup after nested SFSB tests

Added: trunk/ejb3/src/test/org/jboss/ejb3/test/stateful/nested/BaseNestedStatefulBean.java
===================================================================
--- trunk/ejb3/src/test/org/jboss/ejb3/test/stateful/nested/BaseNestedStatefulBean.java	                        (rev 0)
+++ trunk/ejb3/src/test/org/jboss/ejb3/test/stateful/nested/BaseNestedStatefulBean.java	2007-01-27 23:08:22 UTC (rev 60066)
@@ -0,0 +1,54 @@
+/*
+ * JBoss, Home of Professional Open Source
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+
+package org.jboss.ejb3.test.stateful.nested;
+
+import javax.ejb.Remove;
+
+import org.jboss.logging.Logger;
+
+/**
+ * Base class for a nested SFSB. Declares no class annotations,
+ * giving subclasses configuration freedom.
+ *
+ * @author Ben Wang
+ * @author Brian Stansberry
+ * 
+ * @version $Revision: 45372 $
+ */
+public abstract class BaseNestedStatefulBean 
+   implements java.io.Serializable, NestedStateful
+{
+   /** The serialVersionUID */
+   private static final long serialVersionUID = 1L;
+   
+   protected Logger log = Logger.getLogger(getClass());
+   private int counter = 0;
+
+   public int increment()
+   {
+      counter++;
+      log.debug("INCREMENT - counter: " + counter);
+      return counter;
+   }
+
+   public void reset()
+   {
+      counter = 0;
+   }
+   
+   @Remove
+   public void remove() 
+   {
+      log.debug("Being removed");
+   }
+
+   protected int getCounter()
+   {
+      return counter;
+   }
+}

Added: trunk/ejb3/src/test/org/jboss/ejb3/test/stateful/nested/LocalNestedStatefulBean.java
===================================================================
--- trunk/ejb3/src/test/org/jboss/ejb3/test/stateful/nested/LocalNestedStatefulBean.java	                        (rev 0)
+++ trunk/ejb3/src/test/org/jboss/ejb3/test/stateful/nested/LocalNestedStatefulBean.java	2007-01-27 23:08:22 UTC (rev 60066)
@@ -0,0 +1,69 @@
+/*
+ * JBoss, Home of Professional Open Source
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+
+package org.jboss.ejb3.test.stateful.nested;
+
+import javax.ejb.Local;
+import javax.ejb.PostActivate;
+import javax.ejb.PrePassivate;
+import javax.ejb.Stateful;
+
+import org.jboss.annotation.ejb.cache.simple.CacheConfig;
+
+/**
+ * Nested SFSB with only a local interface.
+ *
+ * @author Ben Wang
+ * @author Brian Stansberry
+ * 
+ * @version $Revision: 45372 $
+ */
+ at Stateful(name="testLocalNestedStateful")
+// We don't want this passivated, so give it a very long timeout
+ at CacheConfig(maxSize=10000, idleTimeoutSeconds=10000) 
+ at Local(NestedStateful.class)
+public class LocalNestedStatefulBean extends BaseNestedStatefulBean
+{
+   /** The serialVersionUID */
+   private static final long serialVersionUID = 1L;
+
+   public static int postActivateCalled = 0;
+   public static int prePassivateCalled = 0;
+
+   @PostActivate
+   public void postActivate()
+   {
+      ++postActivateCalled;
+      log.debug("Activate with counter: " + getCounter() + " -- activate count: "
+            + postActivateCalled );
+   }
+
+   @PrePassivate
+   public void prePassivate()
+   {
+      ++prePassivateCalled;
+      log.debug("Passivate with counter: " + getCounter() + " -- passivate count: "
+            + prePassivateCalled );
+   }
+
+   public int getPostActivate()
+   {
+      return postActivateCalled;
+   }
+
+   public int getPrePassivate()
+   {
+      return prePassivateCalled;
+   }
+
+   public void reset()
+   {
+      super.reset();
+      postActivateCalled = 0;
+      prePassivateCalled = 0;
+   }
+}

Modified: trunk/ejb3/src/test/org/jboss/ejb3/test/stateful/nested/NestedStateful.java
===================================================================
--- trunk/ejb3/src/test/org/jboss/ejb3/test/stateful/nested/NestedStateful.java	2007-01-27 23:05:44 UTC (rev 60065)
+++ trunk/ejb3/src/test/org/jboss/ejb3/test/stateful/nested/NestedStateful.java	2007-01-27 23:08:22 UTC (rev 60066)
@@ -13,8 +13,11 @@
  * @author Ben Wang
  * @version $Revision$
  */
-public interface NestedStateful
+public interface NestedStateful extends Removable
 {
    int increment();   
-   void reset();
+   void reset(); 
+
+   int getPostActivate();
+   int getPrePassivate();
 }

Modified: trunk/ejb3/src/test/org/jboss/ejb3/test/stateful/nested/NestedStatefulBean.java
===================================================================
--- trunk/ejb3/src/test/org/jboss/ejb3/test/stateful/nested/NestedStatefulBean.java	2007-01-27 23:05:44 UTC (rev 60065)
+++ trunk/ejb3/src/test/org/jboss/ejb3/test/stateful/nested/NestedStatefulBean.java	2007-01-27 23:08:22 UTC (rev 60066)
@@ -7,32 +7,47 @@
 
 package org.jboss.ejb3.test.stateful.nested;
 
-import org.jboss.annotation.ejb.cache.tree.CacheConfig;
-import org.jboss.logging.Logger;
+import javax.ejb.PostActivate;
+import javax.ejb.PrePassivate;
+import javax.ejb.Remote;
+import javax.ejb.Stateful;
 
-import javax.ejb.*;
+import org.jboss.annotation.ejb.cache.simple.CacheConfig;
 
 /**
- * Nested SFSB
+ * Nested SFSB with a remote interface
  *
  * @author Ben Wang
+ * @author Brian Stansberry
+ * 
  * @version $Revision$
  */
 @Stateful(name="testNestedStateful")
- at CacheConfig(maxSize=1000, idleTimeoutSeconds=3)   // this will get evicted the second time eviction thread wakes up
-public class NestedStatefulBean implements java.io.Serializable, NestedStateful
+ at CacheConfig(maxSize=1000, idleTimeoutSeconds=1) // this will get evicted the second time eviction thread wakes up
+ at Remote(NestedStateful.class)
+public class NestedStatefulBean extends BaseNestedStatefulBean
 {
-   private Logger log = Logger.getLogger(NestedStatefulBean.class);
-   private int counter = 0;
+   /** The serialVersionUID */
+   private static final long serialVersionUID = 1L;
 
-   public int increment()
+   public static int postActivateCalled = 0;
+   public static int prePassivateCalled = 0;
+
+   @PostActivate
+   public void postActivate()
    {
-      log.debug("INCREMENT - counter: " + (counter++));
-      return counter;
+      ++postActivateCalled;
+      log.debug("Activate with counter: " + getCounter() + " -- activate count: "
+            + postActivateCalled );
    }
 
-   public static int postActivateCalled = 0;
-   public static int prePassivateCalled = 0;
+   @PrePassivate
+   public void prePassivate()
+   {
+      ++prePassivateCalled;
+      log.debug("Passivate with counter: " + getCounter() + " -- passivate count: "
+            + prePassivateCalled );
+   }
 
    public int getPostActivate()
    {
@@ -46,23 +61,8 @@
 
    public void reset()
    {
-      counter = 0;
-      NestedStatefulBean.postActivateCalled = 0;
-      NestedStatefulBean.prePassivateCalled = 0;
+      super.reset();
+      postActivateCalled = 0;
+      prePassivateCalled = 0;
    }
-
-   @PostActivate
-   public void postActivate()
-   {
-      ++NestedStatefulBean.postActivateCalled;
-      log.debug("Activate with counter: " + counter);
-   }
-
-   @PrePassivate
-   public void prePassivate()
-   {
-      ++NestedStatefulBean.prePassivateCalled;
-      log.debug("Passivate with counter: " + counter);
-   }
-
 }

Modified: trunk/ejb3/src/test/org/jboss/ejb3/test/stateful/nested/ParentStatefulBean.java
===================================================================
--- trunk/ejb3/src/test/org/jboss/ejb3/test/stateful/nested/ParentStatefulBean.java	2007-01-27 23:05:44 UTC (rev 60065)
+++ trunk/ejb3/src/test/org/jboss/ejb3/test/stateful/nested/ParentStatefulBean.java	2007-01-27 23:08:22 UTC (rev 60066)
@@ -21,16 +21,20 @@
  * @version $Revision$
  */
 @Stateful(name="testParentStateful")
- at CacheConfig(maxSize=1000, idleTimeoutSeconds=3)   // this will get evicted the second time eviction thread wakes up
+ at CacheConfig(maxSize=1000, idleTimeoutSeconds=1)   // this will get evicted the second time eviction thread wakes up
 @Remote(ParentStatefulRemote.class)
 public class ParentStatefulBean implements java.io.Serializable, ParentStatefulRemote
 {
    private Logger log = Logger.getLogger(ParentStatefulBean.class);
    private int counter = 0;
-
-   @EJB
+   private int localCounter = 0;
+   
+   @EJB(beanName="testNestedStateful")
    private NestedStateful nested;
 
+   @EJB(beanName="testLocalNestedStateful")
+   private NestedStateful localNested;
+
    public int increment()
    {
       counter = nested.increment();
@@ -39,6 +43,14 @@
       return counter;
    }
 
+   public int incrementLocal()
+   {
+      localCounter = localNested.increment();
+
+      log.debug("INCREMENT - localCounter: " + localCounter);
+      return localCounter;
+   }
+
    public static int postActivateCalled = 0;
    public static int prePassivateCalled = 0;
 
@@ -52,6 +64,11 @@
       Thread.sleep(10000);
       log.debug("+++ longRunning() leave ");
    }
+   
+   public NestedStateful getNested()
+   {
+      return nested;
+   }
 
    public int getPostActivate()
    {
@@ -62,12 +79,24 @@
    {
       return ParentStatefulBean.prePassivateCalled;
    }
+   
+   public int getLocalNestedPostActivate()
+   {
+      return localNested.getPostActivate();
+   }
 
+   public int getLocalNestedPrePassivate()
+   {
+      return localNested.getPrePassivate();
+   }
+
    public void reset()
    {
       counter = 0;
       ParentStatefulBean.postActivateCalled = 0;
       ParentStatefulBean.prePassivateCalled = 0;
+      nested.reset();
+      localNested.reset();
    }
 
    @PostActivate
@@ -87,6 +116,7 @@
    @Remove
    public void remove()
    {
+      log.debug("Being removed");
    }
 
    @PostConstruct

Modified: trunk/ejb3/src/test/org/jboss/ejb3/test/stateful/nested/ParentStatefulRemote.java
===================================================================
--- trunk/ejb3/src/test/org/jboss/ejb3/test/stateful/nested/ParentStatefulRemote.java	2007-01-27 23:05:44 UTC (rev 60065)
+++ trunk/ejb3/src/test/org/jboss/ejb3/test/stateful/nested/ParentStatefulRemote.java	2007-01-27 23:08:22 UTC (rev 60066)
@@ -11,12 +11,15 @@
  * Parent sfsb interface
  *
  * @author Ben Wang
+ * @author Brian Stansberry
  * @version $Revision$
  */
-public interface ParentStatefulRemote
+public interface ParentStatefulRemote extends Removable
 {
    int increment();
 
+   int incrementLocal();
+   
    int getPostActivate();
 
    int getPrePassivate();
@@ -25,5 +28,9 @@
 
    void longRunning() throws Exception;
 
-   void remove();
+   NestedStateful getNested();
+
+   int getLocalNestedPostActivate();
+
+   int getLocalNestedPrePassivate();
 }

Added: trunk/ejb3/src/test/org/jboss/ejb3/test/stateful/nested/Removable.java
===================================================================
--- trunk/ejb3/src/test/org/jboss/ejb3/test/stateful/nested/Removable.java	                        (rev 0)
+++ trunk/ejb3/src/test/org/jboss/ejb3/test/stateful/nested/Removable.java	2007-01-27 23:08:22 UTC (rev 60066)
@@ -0,0 +1,34 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, 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.ejb3.test.stateful.nested;
+
+/**
+ * An SFSB with a remove method.
+ * 
+ * @author <a href="brian.stansberry at jboss.com">Brian Stansberry</a>
+ * @version $Revision: 1.1 $
+ */
+public interface Removable
+{
+   void remove();
+}

Modified: trunk/ejb3/src/test/org/jboss/ejb3/test/stateful/unit/NestedBeanUnitTestCase.java
===================================================================
--- trunk/ejb3/src/test/org/jboss/ejb3/test/stateful/unit/NestedBeanUnitTestCase.java	2007-01-27 23:05:44 UTC (rev 60065)
+++ trunk/ejb3/src/test/org/jboss/ejb3/test/stateful/unit/NestedBeanUnitTestCase.java	2007-01-27 23:08:22 UTC (rev 60066)
@@ -8,11 +8,15 @@
 package org.jboss.ejb3.test.stateful.unit;
 
 import org.jboss.test.JBossTestCase;
+import org.jboss.ejb3.test.stateful.nested.NestedStateful;
 import org.jboss.ejb3.test.stateful.nested.ParentStatefulRemote;
+import org.jboss.ejb3.test.stateful.nested.Removable;
 
 import javax.naming.Context;
 import javax.naming.InitialContext;
 import java.util.Date;
+import java.util.HashSet;
+import java.util.Set;
 
 import junit.framework.Test;
 
@@ -34,6 +38,8 @@
    protected final String providerURL =
    System.getProperty(Context.PROVIDER_URL);
 
+   private Set<Removable> removables = new HashSet<Removable>();
+   
    public NestedBeanUnitTestCase (String name)
    {
       super(name);
@@ -43,6 +49,26 @@
    {
       return getDeploySetup(NestedBeanUnitTestCase.class, "stateful-test.jar");
    }
+   
+   
+   @Override
+   protected void tearDown() throws Exception
+   {
+      super.tearDown();
+      
+      // Remove any EJBs so they don't spuriously passivate and
+      // throw off the passivation counts
+      for (Removable removable : removables)
+      {
+         try
+         {
+            removable.remove();
+         }
+         catch (Exception ignored) {}
+      }
+      
+      removables.clear();
+   }
 
    public void testBasic()
    throws Exception
@@ -58,11 +84,21 @@
       getLog().debug(++NestedBeanUnitTestCase.test +"- "
               +"Looking up testBasic...");
       ParentStatefulRemote stateful = (ParentStatefulRemote) ctx.lookup("testParentStateful/remote");
-
+      removables.add(stateful);
+      
       assertEquals("Counter: ", 1, stateful.increment());
       assertEquals("Counter: ", 2, stateful.increment());
-
-      stateful.remove();
+      
+      NestedStateful nested = stateful.getNested();
+      removables.add(nested);
+      
+      removeBean(stateful);
+      
+      // Confirm nested still works following parent remove
+      assertEquals("Counter: ", 3, nested.increment());
+      
+      removeBean(nested);
+      
       getLog().debug("ok");
    }
 
@@ -78,17 +114,37 @@
       getLog().debug(++NestedBeanUnitTestCase.test +"- "
               +"Looking up testParentStateful...");
       ParentStatefulRemote stateful = (ParentStatefulRemote) ctx.lookup("testParentStateful/remote");
-
+      removables.add(stateful);
+      stateful.reset();
+      
       assertEquals("Counter: ", 1, stateful.increment());
       assertEquals("Counter: ", 2, stateful.increment());
-      _sleep(10000);  // should passivated
+      assertEquals("Counter: ", 1, stateful.incrementLocal());
+      assertEquals("Counter: ", 2, stateful.incrementLocal());
+      
+      NestedStateful nested = stateful.getNested();
+      removables.add(nested);
+      
+      _sleep(2500);  // should passivate
 
+      assertEquals(1, stateful.getPrePassivate());
+      assertEquals(1, stateful.getPostActivate());
+      assertEquals(1, nested.getPrePassivate());
+      assertEquals(1, nested.getPostActivate());
+      assertEquals(1, stateful.getLocalNestedPrePassivate());
+      assertEquals(1, stateful.getLocalNestedPostActivate());
       assertEquals("Counter: ", 3, stateful.increment());
       assertEquals("Counter: ", 4, stateful.increment());
-      assertEquals(1, stateful.getPrePassivate());
-      assertEquals(1, stateful.getPostActivate());
-
-      stateful.remove();
+      assertEquals("Counter: ", 3, stateful.incrementLocal());
+      assertEquals("Counter: ", 4, stateful.incrementLocal());
+      
+      removeBean(stateful);
+      
+      // Confirm nested still works following parent remove
+      assertEquals("Counter: ", 5, nested.increment());
+      
+      removeBean(nested);
+      
       getLog().debug("ok");
    }
 
@@ -104,24 +160,58 @@
       getLog().debug(++NestedBeanUnitTestCase.test +"- "
               +"Looking up testParentStateful...");
       ParentStatefulRemote stateful = (ParentStatefulRemote) ctx.lookup("testParentStateful/remote");
+      removables.add(stateful);
       stateful.reset();
 
       assertEquals("Counter: ", 1, stateful.increment());
       assertEquals("Counter: ", 2, stateful.increment());
+      assertEquals("Counter: ", 1, stateful.incrementLocal());
+      assertEquals("Counter: ", 2, stateful.incrementLocal());
+      
+      NestedStateful nested = stateful.getNested();
+      removables.add(nested);
+      
       _sleep(10000);  // should passivated
 
+      assertEquals(1, stateful.getPrePassivate());
+      assertEquals(1, stateful.getPostActivate());
+      assertEquals(1, nested.getPrePassivate());
+      assertEquals(1, nested.getPostActivate());
+      assertEquals(1, stateful.getLocalNestedPrePassivate());
+      assertEquals(1, stateful.getLocalNestedPostActivate());
       assertEquals("Counter: ", 3, stateful.increment());
       assertEquals("Counter: ", 4, stateful.increment());
-      assertEquals(1, stateful.getPrePassivate());
-      assertEquals(1, stateful.getPostActivate());
+      assertEquals("Counter: ", 3, stateful.incrementLocal());
+      assertEquals("Counter: ", 4, stateful.incrementLocal());
+      
+      
       _sleep(10000);  // should passivated
 
+      assertEquals(2, stateful.getPrePassivate());
+      assertEquals(2, stateful.getPostActivate());
+      assertEquals(2, nested.getPrePassivate());
+      assertEquals(2, nested.getPostActivate());
+      assertEquals(2, stateful.getLocalNestedPrePassivate());
+      assertEquals(2, stateful.getLocalNestedPostActivate());
       assertEquals("Counter: ", 5, stateful.increment());
       assertEquals("Counter: ", 6, stateful.increment());
-      assertEquals(2, stateful.getPrePassivate());
-      assertEquals(2, stateful.getPostActivate());
-
-      stateful.remove();
+      assertEquals("Counter: ", 5, stateful.incrementLocal());
+      assertEquals("Counter: ", 6, stateful.incrementLocal());
+      
+      removeBean(stateful);
+      
+      // Force the nested bean to go through another passivation
+      // to check the activation process can survive the removal 
+      // of its parent
+      _sleep(2500);
+      
+      // Confirm nested still works following parent remove
+      assertEquals("Counter: ", 7, nested.increment());
+      assertEquals(3, nested.getPrePassivate());
+      assertEquals(3, nested.getPostActivate());
+      
+      removeBean(nested);
+      
       getLog().debug("ok");
    }
 
@@ -133,4 +223,10 @@
          e.printStackTrace();
       }
    }
+   
+   private void removeBean(Removable bean)
+   {
+      bean.remove();
+      removables.remove(bean);
+   }
 }




More information about the jboss-cvs-commits mailing list