[jboss-cvs] JBossAS SVN: r60658 - in branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test: clusteredsession/nested and 3 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Feb 19 04:12:26 EST 2007


Author: bstansberry at jboss.com
Date: 2007-02-19 04:12:25 -0500 (Mon, 19 Feb 2007)
New Revision: 60658

Added:
   branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredsession/IgnoreReplicationStatefulBean.java
   branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredsession/OptimizedStatefulBean.java
   branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredsession/nested/ClusteredDeepNestedContainedBean.java
   branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredsession/nested/ClusteredDeepNestedStatefulBean.java
   branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredsession/nested/ClusteredLocalContainedBean.java
   branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredsession/nested/ClusteredLocalNestedStatefulBean.java
   branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredsession/nested/ClusteredParentStatefulBean.java
   branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredsession/nested/ClusteredRemoteContainedBean.java
   branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredsession/nested/ClusteredRemoteNestedStatefulBean.java
   branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredsession/nested/ClusteredShoppingCartBean.java
   branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/stateful/nested/SimpleContainedBean.java
   branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/stateful/nested/SimpleDeepNestedContainedBean.java
   branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/stateful/nested/SimpleDeepNestedStatefulBean.java
   branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/stateful/nested/SimpleLocalContainedBean.java
   branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/stateful/nested/SimpleLocalNestedStatefulBean.java
   branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/stateful/nested/SimpleParentStatefulBean.java
   branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/stateful/nested/SimpleRemoteNestedStatefulBean.java
   branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/stateful/nested/SimpleShoppingCartBean.java
   branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/stateful/nested/base/
   branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/stateful/unit/BaseTestRunner.java
   branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/stateful/unit/ExtendedPersistenceUnitTestCase.java
   branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/stateful/unit/NestedBeanTestRunner.java
   branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/stateful/unit/XPCTestRunner.java
Removed:
   branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredsession/Contained.java
   branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredsession/ContainedBean.java
   branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredsession/Customer.java
   branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredsession/ShoppingCart.java
   branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredsession/ShoppingCartBean.java
   branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredsession/StatelessLocal.java
   branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredsession/StatelessRemote.java
   branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredsession/StatelessSessionBean.java
   branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredsession/nested/NestedStateful.java
   branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredsession/nested/NestedStatefulBean.java
   branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredsession/nested/ParentStatefulBean.java
   branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredsession/nested/ParentStatefulRemote.java
   branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/stateful/nested/BaseNestedStatefulBean.java
   branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/stateful/nested/LocalNestedStatefulBean.java
   branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/stateful/nested/NestedStateful.java
   branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/stateful/nested/NestedStatefulBean.java
   branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/stateful/nested/ParentStatefulBean.java
   branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/stateful/nested/ParentStatefulRemote.java
   branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/stateful/nested/Removable.java
Modified:
   branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredsession/NonAnnotationStatefulBean.java
   branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredsession/unit/ExtendedPersistenceUnitTestCase.java
   branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredsession/unit/NestedBeanUnitTestCase.java
   branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredsession/unit/PassivationUnitTestCase.java
   branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/stateful/unit/NestedBeanUnitTestCase.java
Log:
Refactor and expand testing of nested SFSBs
[EJBTHREE-867] Loosen coupling of lifecycle of nested SFSBs
[EJBTHREE-849] Properly handle passivation/activation callbacks for nested SFSBs
[EJBTHREE-851] Invoke passivation/activation callbacks around replication

Deleted: branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredsession/Contained.java
===================================================================
--- branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredsession/Contained.java	2007-02-19 09:08:42 UTC (rev 60657)
+++ branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredsession/Contained.java	2007-02-19 09:12:25 UTC (rev 60658)
@@ -1,41 +0,0 @@
-/*
- * 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.clusteredsession;
-
-/**
- * Comment
- *
- * @author Ben Wang
- * @version $Revision$
- */
-public interface Contained
-{
-   Customer find(long id);
-
-   void setCustomer(long id);
-
-   Customer getCustomer();
-
-   void updateCustomer();
-
-   boolean isActivated();
-}

Deleted: branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredsession/ContainedBean.java
===================================================================
--- branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredsession/ContainedBean.java	2007-02-19 09:08:42 UTC (rev 60657)
+++ branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredsession/ContainedBean.java	2007-02-19 09:12:25 UTC (rev 60658)
@@ -1,102 +0,0 @@
-/*
- * 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.clusteredsession;
-
-import javax.persistence.PersistenceContext;
-import javax.persistence.PersistenceContextType;
-import javax.persistence.EntityManager;
-import javax.annotation.PreDestroy;
-import javax.ejb.Stateful;
-import javax.ejb.PrePassivate;
-import javax.ejb.PostActivate;
-
-import org.jboss.annotation.ejb.cache.tree.CacheConfig;
-import org.jboss.annotation.ejb.Clustered;
-
-/**
- * Comment
- *
- * @author Ben Wang
- * @version $Revision$
- */
- at Stateful
- at Clustered
- at CacheConfig(maxSize = 1000, idleTimeoutSeconds = 2)
-public class ContainedBean implements Contained
-{
-   @PersistenceContext(type= PersistenceContextType.EXTENDED) EntityManager em;
-
-   Customer customer;
-
-   public Customer find(long id)
-   {
-      return em.find(Customer.class, id);
-   }
-
-   public void setCustomer(long id)
-   {
-      customer = find(id);
-   }
-
-   public Customer getCustomer()
-   {
-      return customer;
-   }
-
-   public void updateCustomer()
-   {
-      customer.setName("contained modified");
-   }
-
-   public boolean isActivated()
-   {
-      return activated;
-   }
-
-   public static boolean destroyed = false;
-   public static boolean passivated = false;
-   public static boolean activate = false;
-   private boolean activated = false;
-
-   @PrePassivate
-   public void passivate()
-   {
-      passivated = true;
-   }
-
-   @PostActivate
-   public void activate()
-   {
-      System.out.println("*********** ACTIVATED *****************");
-      if (activated) throw new RuntimeException("ACTIVATED TWICE");
-      activated = true;
-      if (activate) throw new RuntimeException("ACTIVATED TWICE IN TWO DIFFERENT INSTANCES");
-      activate = true;
-
-   }
-
-   @PreDestroy
-   public void destroy()
-   {
-      destroyed = true;
-   }
-}

Deleted: branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredsession/Customer.java
===================================================================
--- branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredsession/Customer.java	2007-02-19 09:08:42 UTC (rev 60657)
+++ branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredsession/Customer.java	2007-02-19 09:12:25 UTC (rev 60658)
@@ -1,70 +0,0 @@
-/*
- * 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.clusteredsession;
-
-import javax.persistence.Entity;
-import javax.persistence.GeneratedValue; import javax.persistence.GenerationType;
-import javax.persistence.Id;
-
-/**
- * Company customer
- *
- * @author Ben Wang
- */
- at Entity
-public class Customer implements java.io.Serializable
-{
-   long id;
-   String name;
-
-   public
-   Customer()
-   {
-   }
-
-   @Id @GeneratedValue(strategy=GenerationType.IDENTITY)
-   public
-   long getId()
-   {
-      return id;
-   }
-
-   public
-   String getName()
-   {
-      return name;
-   }
-
-   public
-   void setId(long long1)
-   {
-      id = long1;
-   }
-
-   public
-   void setName(String string)
-   {
-      name = string;
-   }
-
-}
-

Copied: branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredsession/IgnoreReplicationStatefulBean.java (from rev 60635, trunk/ejb3/src/test/org/jboss/ejb3/test/clusteredsession/IgnoreReplicationStatefulBean.java)
===================================================================
--- branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredsession/IgnoreReplicationStatefulBean.java	                        (rev 0)
+++ branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredsession/IgnoreReplicationStatefulBean.java	2007-02-19 09:12:25 UTC (rev 60658)
@@ -0,0 +1,46 @@
+/*
+ * 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.clusteredsession;
+
+import javax.ejb.Remote;
+import javax.ejb.Stateful;
+
+import org.jboss.annotation.ejb.Clustered;
+import org.jboss.annotation.ejb.cache.tree.CacheConfig;
+
+/**
+ * Stateful bean that configures clustering via annotations.
+ *
+ * @author Ben Wang
+ * @version $Revision: 59445 $
+ */
+ at Stateful(name="testIgnoreReplicationStateful")
+ at Clustered
+ at CacheConfig(maxSize=1000, idleTimeoutSeconds=1, replicationIsPassivation=false)   // this will get evicted the second time eviction thread wakes up
+ at Remote(StatefulRemote.class)
+public class IgnoreReplicationStatefulBean extends NonAnnotationStatefulBean
+{
+   /** The serialVersionUID */
+   private static final long serialVersionUID = 1L;
+   
+   // Only difference from superclass is the added class-level annotations
+}

Modified: branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredsession/NonAnnotationStatefulBean.java
===================================================================
--- branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredsession/NonAnnotationStatefulBean.java	2007-02-19 09:08:42 UTC (rev 60657)
+++ branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredsession/NonAnnotationStatefulBean.java	2007-02-19 09:12:25 UTC (rev 60658)
@@ -30,6 +30,7 @@
 import javax.ejb.Remove;
 import javax.interceptor.Interceptors;
 
+import org.jboss.ejb3.test.stateful.nested.base.VMTracker;
 import org.jboss.logging.Logger;
 import org.jboss.system.server.ServerConfig;
 
@@ -47,12 +48,18 @@
  */
 public class NonAnnotationStatefulBean implements java.io.Serializable, StatefulRemote
 {
+   /** The serialVersionUID */
+   private static final long serialVersionUID = 1L;
+   
    private Logger log = Logger.getLogger(getClass());
    private int counter = 0;
    private String state;
-   public transient VMID myId = null;
+   public static final VMID myId = VMTracker.VMID;
    public String name;
 
+   private int postActivateCalled = 0;
+   private int prePassivateCalled = 0;
+
    public int increment()
    {
       System.out.println("INCREMENT - counter: " + (counter++));
@@ -64,9 +71,6 @@
       return System.getProperty(ServerConfig.SERVER_BIND_ADDRESS);
    }
 
-   public static int postActivateCalled = 0;
-   public static int prePassivateCalled = 0;
-
    /**
     * Sleep to test
     * @throws Exception
@@ -106,7 +110,8 @@
       prePassivateCalled = 0;
    }
 
-   public void resetActivationCounter() {
+   public void resetActivationCounter() 
+   {
       postActivateCalled = 0;
       prePassivateCalled = 0;
    }
@@ -114,20 +119,15 @@
    @PostActivate
    public void postActivate()
    {
-      ++postActivateCalled;
-      if (this.myId == null)
-      {
-         //it is a failover: we need to assign ourself an id
-         this.myId = new VMID();
-      }
-      log.debug("Activate. My ID: " + this.myId + " name: " + this.name);
+      postActivateCalled++;
+      log.debug("Activate. My ID: " + myId + " name: " + this.name);
    }
 
    @PrePassivate
    public void prePassivate()
    {
-      ++prePassivateCalled;
-      log.debug("Passivate. My ID: " + this.myId + " name: " + this.name);
+      prePassivateCalled++;
+      log.debug("Passivate. My ID: " + myId + " name: " + this.name);
    }
 
    @Remove
@@ -138,8 +138,7 @@
    @PostConstruct
    public void ejbCreate()
    {
-      this.myId = new VMID();
-      log.debug("My ID: " + this.myId);
+      log.debug("My ID: " + myId);
    }
 
    // Remote Interface implementation ----------------------------------------------
@@ -148,13 +147,7 @@
    @Interceptors({ExplicitFailoverInterceptor.class})
    public NodeAnswer getNodeState()
    {
-      if (this.myId == null)
-      {
-         //it is a failover: we need to assign ourself an id because of transient nature
-         this.myId = new VMID();
-      }
-
-      NodeAnswer state = new NodeAnswer(this.myId, this.name);
+      NodeAnswer state = new NodeAnswer(myId, this.name);
       log.debug("getNodeState, " + state);
       return state;
    }
@@ -167,10 +160,10 @@
 
    public void setNameOnlyOnNode(String name, VMID node)
    {
-      if (node.equals(this.myId))
+      if (node.equals(myId))
          this.setName(name);
       else
-         throw new EJBException("Trying to assign value on node " + this.myId + " but this node expected: " + node);
+         throw new EJBException("Trying to assign value on node " + myId + " but this node expected: " + node);
    }
 
    public void setUpFailover(String failover) {

Copied: branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredsession/OptimizedStatefulBean.java (from rev 60635, trunk/ejb3/src/test/org/jboss/ejb3/test/clusteredsession/OptimizedStatefulBean.java)
===================================================================
--- branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredsession/OptimizedStatefulBean.java	                        (rev 0)
+++ branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredsession/OptimizedStatefulBean.java	2007-02-19 09:12:25 UTC (rev 60658)
@@ -0,0 +1,79 @@
+/*
+ * 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.clusteredsession;
+
+import javax.ejb.Remote;
+import javax.ejb.Stateful;
+
+import org.jboss.annotation.ejb.Clustered;
+import org.jboss.annotation.ejb.cache.tree.CacheConfig;
+import org.jboss.ejb3.cache.Optimized;
+
+/**
+ * Stateful bean that configures clustering via annotations.
+ *
+ * @author Ben Wang
+ * @version $Revision: 59445 $
+ */
+ at Stateful(name="testOptimizedStateful")
+ at Clustered
+ at CacheConfig(maxSize=1000, idleTimeoutSeconds=1)   // this will get evicted the second time eviction thread wakes up
+ at Remote(StatefulRemote.class)
+public class OptimizedStatefulBean 
+   extends NonAnnotationStatefulBean
+   implements Optimized
+{
+   /** The serialVersionUID */
+   private static final long serialVersionUID = 1L;
+
+   private boolean modified = true;
+   
+   public boolean isModified()
+   {
+      boolean answer = modified;
+      modified = true;
+      return answer;
+   }
+
+   @Override
+   public int getPostActivate()
+   {
+      modified = false;
+      return super.getPostActivate();
+   }
+
+   @Override
+   public int getPrePassivate()
+   {
+      modified = false;
+      return super.getPrePassivate();
+   }
+
+   @Override
+   public void resetActivationCounter()
+   {
+      modified = false;
+      super.resetActivationCounter();
+   }
+   
+   
+}

Deleted: branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredsession/ShoppingCart.java
===================================================================
--- branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredsession/ShoppingCart.java	2007-02-19 09:08:42 UTC (rev 60657)
+++ branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredsession/ShoppingCart.java	2007-02-19 09:12:25 UTC (rev 60658)
@@ -1,60 +0,0 @@
-/*
- * 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.clusteredsession;
-
-import java.rmi.dgc.VMID;
-
-import javax.ejb.Remove;
-
-/**
- * comment
- *
- * @author Ben Wang
- */
-public interface ShoppingCart
-{
-   VMID getVMID();
-   
-   long createCustomer();
-
-   void update();
-
-   Customer find(long id);
-
-   @Remove void checkout();
-
-   void update2();
-
-   void update3();
-
-   void never();
-
-   void setContainedCustomer();
-
-   void updateContained();
-
-   void findAndUpdateStateless();
-
-   void checkContainedCustomer();
-
-   boolean isContainedActivated();
-}

Deleted: branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredsession/ShoppingCartBean.java
===================================================================
--- branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredsession/ShoppingCartBean.java	2007-02-19 09:08:42 UTC (rev 60657)
+++ branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredsession/ShoppingCartBean.java	2007-02-19 09:12:25 UTC (rev 60658)
@@ -1,138 +0,0 @@
-/*
- * 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.clusteredsession;
-
-import java.io.Serializable;
-import java.rmi.dgc.VMID;
-
-import javax.ejb.EJB;
-import javax.ejb.Remote;
-import javax.ejb.Remove;
-import javax.ejb.Stateful;
-import javax.ejb.TransactionAttribute;
-import javax.ejb.TransactionAttributeType;
-import javax.ejb.PostActivate;
-import javax.persistence.EntityManager;
-import javax.persistence.PersistenceContext;
-import javax.persistence.PersistenceContextType;
-import org.jboss.annotation.ejb.cache.tree.CacheConfig;
-import org.jboss.annotation.ejb.Clustered;
-
-/**
- * comment
- *
- * @author Ben Wang
- */
- at Stateful
- at Clustered
- at Remote(ShoppingCart.class)
- at CacheConfig(maxSize = 1000, idleTimeoutSeconds = 2)
-public class ShoppingCartBean implements ShoppingCart, Serializable
-{
-   @PersistenceContext(type=PersistenceContextType.EXTENDED) EntityManager em;
-
-   @EJB StatelessLocal stateless;
-   
-   private Customer customer;
-
-   @EJB private Contained contained;
-
-   public VMID getVMID()
-   {
-      return stateless.getVMID();
-   }
-   
-   public long createCustomer()
-   {
-      customer = new Customer();
-      customer.setName("William");
-      em.persist(customer);
-      System.out.println("********* created *****");
-      return customer.getId();
-   }
-
-   public void setContainedCustomer()
-   {
-      contained.setCustomer(customer.getId());
-   }
-
-   public void checkContainedCustomer()
-   {
-      if (contained.getCustomer() != customer) throw new RuntimeException("not same customer");
-   }
-
-   public boolean isContainedActivated()
-   {
-      return contained.isActivated();
-   }
-
-   public void updateContained()
-   {
-      contained.updateCustomer();
-   }
-
-   public void update()
-   {
-      System.out.println("********* update() *****");
-      customer.setName("Bill");
-   }
-   public void update2()
-   {
-      customer.setName("Billy");
-   }
-
-   public void update3()
-   {
-      stateless.update(customer);
-   }
-
-   public void findAndUpdateStateless()
-   {
-      stateless.findAndUpdate(customer.getId());
-      if (!customer.getName().equals("stateless modified")) throw new RuntimeException("stateless didn't get propagated pc");
-   }
-
-   public Customer find(long id)
-   {
-      return em.find(Customer.class, id);
-   }
-
-   @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
-   public void never()
-   {
-      customer.setName("Bob");
-   }
-
-   @PostActivate
-   public void activate()
-   {
-      System.out.println("*********** ACTIVATED *****************");
-   }
-
-
-   @Remove
-   public void checkout() 
-   {
-      if (customer != null)
-         em.remove(customer);
-   }
-}

Deleted: branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredsession/StatelessLocal.java
===================================================================
--- branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredsession/StatelessLocal.java	2007-02-19 09:08:42 UTC (rev 60657)
+++ branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredsession/StatelessLocal.java	2007-02-19 09:12:25 UTC (rev 60658)
@@ -1,47 +0,0 @@
-/*
- * 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.clusteredsession;
-
-import java.rmi.dgc.VMID;
-
-
-/**
- * comment
- *
- * @author Ben Wang
- */
-public interface StatelessLocal
-{
-   VMID getVMID();
-   
-   void update(Customer c);
-
-   void findAndUpdate(long id);
-
-   boolean isDestroyed();
-
-   void clearDestroyed();
-
-   boolean isPassivated();
-
-   void clearPassivated();
-}

Deleted: branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredsession/StatelessRemote.java
===================================================================
--- branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredsession/StatelessRemote.java	2007-02-19 09:08:42 UTC (rev 60657)
+++ branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredsession/StatelessRemote.java	2007-02-19 09:12:25 UTC (rev 60658)
@@ -1,46 +0,0 @@
-/*
- * 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.clusteredsession;
-
-import java.rmi.dgc.VMID;
-
-
-
-/**
- * comment
- *
- * @author Ben Wang
- */
-public interface StatelessRemote
-{
-   VMID getVMID();
-   
-   Customer find(long id);
-
-   void findAndUpdate(long id);
-
-   boolean isDestroyed();
-   void clearDestroyed();
-   boolean isPassivated();
-
-   void clearPassivated();   
-}

Deleted: branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredsession/StatelessSessionBean.java
===================================================================
--- branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredsession/StatelessSessionBean.java	2007-02-19 09:08:42 UTC (rev 60657)
+++ branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredsession/StatelessSessionBean.java	2007-02-19 09:12:25 UTC (rev 60658)
@@ -1,93 +0,0 @@
-/*
- * 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.clusteredsession;
-
-import javax.ejb.Local;
-import javax.ejb.Remote;
-import javax.ejb.Stateless;
-import javax.persistence.EntityManager;
-import javax.persistence.PersistenceContext;
-import java.rmi.dgc.VMID;
-
-/**
- * comment
- *
- * @author Ben Wang
- */
- at Stateless
- at Remote(StatelessRemote.class)
- at Local(StatelessLocal.class)
-public class StatelessSessionBean implements StatelessLocal, StatelessRemote
-{
-   @PersistenceContext EntityManager em;
-
-   public static VMID myId = null;
-
-   public VMID getVMID()
-   {
-      if(myId == null)
-      {
-         myId = new VMID();
-      }
-      return myId;
-   }
-   
-   public void update(Customer c)
-   {
-      c.setName("Bill Jr.");
-   }
-
-   public void findAndUpdate(long id)
-   {
-      Customer cust = find(id);
-      cust.setName("stateless modified");
-   }
-
-   public Customer find(long id)
-   {
-      return em.find(Customer.class, id);
-   }
-
-   public boolean isDestroyed()
-   {
-      return ContainedBean.destroyed;
-   }
-
-   public void clearDestroyed()
-   {
-      ContainedBean.destroyed = false;
-   }
-
-   public boolean isPassivated()
-   {
-      return ContainedBean.passivated;
-   }
-
-   public void clearPassivated()
-   {
-      ContainedBean.passivated = false;
-   }
-
-   public NodeAnswer getNodeState() {
-      return new NodeAnswer(getVMID(), "test");
-   }
-}

Copied: branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredsession/nested/ClusteredDeepNestedContainedBean.java (from rev 60635, trunk/ejb3/src/test/org/jboss/ejb3/test/clusteredsession/nested/ClusteredDeepNestedContainedBean.java)
===================================================================
--- branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredsession/nested/ClusteredDeepNestedContainedBean.java	                        (rev 0)
+++ branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredsession/nested/ClusteredDeepNestedContainedBean.java	2007-02-19 09:12:25 UTC (rev 60658)
@@ -0,0 +1,47 @@
+/*
+ * 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.clusteredsession.nested;
+
+import javax.ejb.Local;
+import javax.ejb.Stateful;
+
+import org.jboss.annotation.ejb.Clustered;
+import org.jboss.annotation.ejb.cache.tree.CacheConfig;
+import org.jboss.ejb3.test.stateful.nested.base.xpc.DeepNestedContained;
+import org.jboss.ejb3.test.stateful.nested.base.xpc.DeepNestedContainedBean;
+
+/**
+ * A ClusteredDeepNestedStatefulBean.
+ * 
+ * @author <a href="brian.stansberry at jboss.com">Brian Stansberry</a>
+ * @version $Revision: 1.1 $
+ */
+ at Stateful(name="testDeepNestedContained")
+ at Clustered
+ at CacheConfig(maxSize=10000, idleTimeoutSeconds=1, replicationIsPassivation=false) 
+ at Local(DeepNestedContained.class)
+public class ClusteredDeepNestedContainedBean extends DeepNestedContainedBean
+{
+   /** The serialVersionUID */
+   private static final long serialVersionUID = 1L;
+}

Copied: branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredsession/nested/ClusteredDeepNestedStatefulBean.java (from rev 60635, trunk/ejb3/src/test/org/jboss/ejb3/test/clusteredsession/nested/ClusteredDeepNestedStatefulBean.java)
===================================================================
--- branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredsession/nested/ClusteredDeepNestedStatefulBean.java	                        (rev 0)
+++ branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredsession/nested/ClusteredDeepNestedStatefulBean.java	2007-02-19 09:12:25 UTC (rev 60658)
@@ -0,0 +1,47 @@
+/*
+ * 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.clusteredsession.nested;
+
+import javax.ejb.Local;
+import javax.ejb.Stateful;
+
+import org.jboss.annotation.ejb.Clustered;
+import org.jboss.annotation.ejb.cache.tree.CacheConfig;
+import org.jboss.ejb3.test.stateful.nested.base.DeepNestedStateful;
+import org.jboss.ejb3.test.stateful.nested.base.DeepNestedStatefulBean;
+
+/**
+ * A ClusteredDeepNestedStatefulBean.
+ * 
+ * @author <a href="brian.stansberry at jboss.com">Brian Stansberry</a>
+ * @version $Revision: 1.1 $
+ */
+ at Stateful(name="testDeepNestedStateful")
+ at Clustered
+ at CacheConfig(maxSize=10000, idleTimeoutSeconds=1, replicationIsPassivation=false) 
+ at Local(DeepNestedStateful.class)
+public class ClusteredDeepNestedStatefulBean extends DeepNestedStatefulBean
+{
+   /** The serialVersionUID */
+   private static final long serialVersionUID = 1L;
+}

Copied: branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredsession/nested/ClusteredLocalContainedBean.java (from rev 60635, trunk/ejb3/src/test/org/jboss/ejb3/test/clusteredsession/nested/ClusteredLocalContainedBean.java)
===================================================================
--- branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredsession/nested/ClusteredLocalContainedBean.java	                        (rev 0)
+++ branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredsession/nested/ClusteredLocalContainedBean.java	2007-02-19 09:12:25 UTC (rev 60658)
@@ -0,0 +1,47 @@
+/*
+ * 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.clusteredsession.nested;
+
+import javax.ejb.Local;
+import javax.ejb.Stateful;
+
+import org.jboss.annotation.ejb.Clustered;
+import org.jboss.annotation.ejb.cache.tree.CacheConfig;
+import org.jboss.ejb3.test.stateful.nested.base.xpc.Contained;
+import org.jboss.ejb3.test.stateful.nested.base.xpc.ContainedBean;
+
+/**
+ * ContainedBean bean meant for testing with a clustered SFSB cache.
+ * 
+ * @author <a href="brian.stansberry at jboss.com">Brian Stansberry</a>
+ * @version $Revision: 1.1 $
+ */
+ at Stateful(name="testLocalShoppingCartContained")
+ at Clustered
+ at CacheConfig(maxSize = 1000, idleTimeoutSeconds = 1)
+ at Local(Contained.class)
+public class ClusteredLocalContainedBean extends ContainedBean
+{
+   /** The serialVersionUID */
+   private static final long serialVersionUID = 1L;
+}

Copied: branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredsession/nested/ClusteredLocalNestedStatefulBean.java (from rev 60635, trunk/ejb3/src/test/org/jboss/ejb3/test/clusteredsession/nested/ClusteredLocalNestedStatefulBean.java)
===================================================================
--- branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredsession/nested/ClusteredLocalNestedStatefulBean.java	                        (rev 0)
+++ branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredsession/nested/ClusteredLocalNestedStatefulBean.java	2007-02-19 09:12:25 UTC (rev 60658)
@@ -0,0 +1,34 @@
+/*
+ * JBoss, Home of Professional Open Source
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+
+package org.jboss.ejb3.test.clusteredsession.nested;
+
+import javax.ejb.Local;
+import javax.ejb.Stateful;
+
+import org.jboss.annotation.ejb.Clustered;
+import org.jboss.annotation.ejb.cache.tree.CacheConfig;
+import org.jboss.ejb3.test.stateful.nested.base.std.NestedStateful;
+import org.jboss.ejb3.test.stateful.nested.base.std.NestedStatefulBean;
+
+/**
+ * Nested SFSB with only a local interface.
+ *
+ * @author Ben Wang
+ * @author Brian Stansberry
+ * 
+ * @version $Revision: 45372 $
+ */
+ at Clustered
+ at Stateful(name="testLocalNestedStateful")
+ at CacheConfig(maxSize=10000, idleTimeoutSeconds=1) 
+ at Local(NestedStateful.class)
+public class ClusteredLocalNestedStatefulBean extends NestedStatefulBean
+{
+   /** The serialVersionUID */
+   private static final long serialVersionUID = 1L;
+}

Copied: branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredsession/nested/ClusteredParentStatefulBean.java (from rev 60635, trunk/ejb3/src/test/org/jboss/ejb3/test/clusteredsession/nested/ClusteredParentStatefulBean.java)
===================================================================
--- branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredsession/nested/ClusteredParentStatefulBean.java	                        (rev 0)
+++ branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredsession/nested/ClusteredParentStatefulBean.java	2007-02-19 09:12:25 UTC (rev 60658)
@@ -0,0 +1,44 @@
+/*
+ * JBoss, Home of Professional Open Source
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+
+package org.jboss.ejb3.test.clusteredsession.nested;
+
+import java.rmi.dgc.VMID;
+
+import javax.ejb.Remote;
+import javax.ejb.Stateful;
+import javax.interceptor.Interceptors;
+
+import org.jboss.annotation.ejb.Clustered;
+import org.jboss.annotation.ejb.cache.tree.CacheConfig;
+import org.jboss.ejb3.test.clusteredsession.ExplicitFailoverInterceptor;
+import org.jboss.ejb3.test.stateful.nested.base.std.ParentStatefulBean;
+import org.jboss.ejb3.test.stateful.nested.base.std.ParentStatefulRemote;
+
+/**
+ * Parent SFSB that contains nested SFSB.
+ *
+ * @author Ben Wang
+ * @author Brian Stansberry
+ * @version $Revision: 60408 $
+ */
+ at Clustered
+ at Stateful(name="testParentStateful")
+ at CacheConfig(maxSize=1000, idleTimeoutSeconds=1)   // this will get evicted the second time eviction thread wakes up
+ at Remote(ParentStatefulRemote.class)
+public class ClusteredParentStatefulBean extends ParentStatefulBean
+{
+   /** The serialVersionUID */
+   private static final long serialVersionUID = 1L;
+   
+   // Mimic explict failover
+   @Interceptors({ExplicitFailoverInterceptor.class})
+   public VMID getVMID()
+   {
+      return super.getVMID();
+   }
+}

Copied: branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredsession/nested/ClusteredRemoteContainedBean.java (from rev 60635, trunk/ejb3/src/test/org/jboss/ejb3/test/clusteredsession/nested/ClusteredRemoteContainedBean.java)
===================================================================
--- branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredsession/nested/ClusteredRemoteContainedBean.java	                        (rev 0)
+++ branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredsession/nested/ClusteredRemoteContainedBean.java	2007-02-19 09:12:25 UTC (rev 60658)
@@ -0,0 +1,47 @@
+/*
+ * 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.clusteredsession.nested;
+
+import javax.ejb.Remote;
+import javax.ejb.Stateful;
+
+import org.jboss.annotation.ejb.Clustered;
+import org.jboss.annotation.ejb.cache.tree.CacheConfig;
+import org.jboss.ejb3.test.stateful.nested.base.xpc.Contained;
+import org.jboss.ejb3.test.stateful.nested.base.xpc.ContainedBean;
+
+/**
+ * ContainedBean bean meant for testing with a clustered SFSB cache.
+ * 
+ * @author <a href="brian.stansberry at jboss.com">Brian Stansberry</a>
+ * @version $Revision: 1.1 $
+ */
+ at Stateful(name="testShoppingCartContained")
+ at Clustered
+ at CacheConfig(maxSize = 1000, idleTimeoutSeconds = 1)
+ at Remote(Contained.class)
+public class ClusteredRemoteContainedBean extends ContainedBean
+{
+   /** The serialVersionUID */
+   private static final long serialVersionUID = 1L;
+}

Copied: branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredsession/nested/ClusteredRemoteNestedStatefulBean.java (from rev 60635, trunk/ejb3/src/test/org/jboss/ejb3/test/clusteredsession/nested/ClusteredRemoteNestedStatefulBean.java)
===================================================================
--- branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredsession/nested/ClusteredRemoteNestedStatefulBean.java	                        (rev 0)
+++ branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredsession/nested/ClusteredRemoteNestedStatefulBean.java	2007-02-19 09:12:25 UTC (rev 60658)
@@ -0,0 +1,34 @@
+/*
+ * JBoss, Home of Professional Open Source
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+
+package org.jboss.ejb3.test.clusteredsession.nested;
+
+import javax.ejb.Remote;
+import javax.ejb.Stateful;
+
+import org.jboss.annotation.ejb.Clustered;
+import org.jboss.annotation.ejb.cache.tree.CacheConfig;
+import org.jboss.ejb3.test.stateful.nested.base.std.NestedStateful;
+import org.jboss.ejb3.test.stateful.nested.base.std.OptimizedNestedStatefulBean;
+
+/**
+ * Nested SFSB with a remote interface.
+ *
+ * @author Ben Wang
+ * @author Brian Stansberry
+ * 
+ * @version $Revision: 60066 $
+ */
+ at Clustered
+ at Stateful(name="testNestedStateful")
+ at CacheConfig(maxSize=1000, idleTimeoutSeconds=1)
+ at Remote(NestedStateful.class)
+public class ClusteredRemoteNestedStatefulBean extends OptimizedNestedStatefulBean
+{
+   /** The serialVersionUID */
+   private static final long serialVersionUID = 1L;
+}

Copied: branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredsession/nested/ClusteredShoppingCartBean.java (from rev 60635, trunk/ejb3/src/test/org/jboss/ejb3/test/clusteredsession/nested/ClusteredShoppingCartBean.java)
===================================================================
--- branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredsession/nested/ClusteredShoppingCartBean.java	                        (rev 0)
+++ branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredsession/nested/ClusteredShoppingCartBean.java	2007-02-19 09:12:25 UTC (rev 60658)
@@ -0,0 +1,58 @@
+/*
+ * 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.clusteredsession.nested;
+
+import java.rmi.dgc.VMID;
+
+import javax.ejb.Remote;
+import javax.ejb.Stateful;
+import javax.interceptor.Interceptors;
+
+import org.jboss.annotation.ejb.Clustered;
+import org.jboss.annotation.ejb.cache.tree.CacheConfig;
+import org.jboss.ejb3.test.clusteredsession.ExplicitFailoverInterceptor;
+import org.jboss.ejb3.test.stateful.nested.base.xpc.ShoppingCart;
+import org.jboss.ejb3.test.stateful.nested.base.xpc.ShoppingCartBean;
+
+/**
+ * ShoppingCartBean subclass for testing with a clustered SFSB cache.
+ * 
+ * @author <a href="brian.stansberry at jboss.com">Brian Stansberry</a>
+ * @version $Revision: 1.1 $
+ */
+ at Stateful(name="testShoppingCart")
+ at Remote(ShoppingCart.class)
+ at Clustered
+ at CacheConfig(maxSize = 1000, idleTimeoutSeconds = 1)
+public class ClusteredShoppingCartBean extends ShoppingCartBean
+{
+   /** The serialVersionUID */
+   private static final long serialVersionUID = 1L;
+   
+   // Mimic explict failover
+   @Interceptors({ExplicitFailoverInterceptor.class})
+   public VMID getVMID()
+   {
+      return super.getVMID();
+   }
+}

Deleted: branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredsession/nested/NestedStateful.java
===================================================================
--- branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredsession/nested/NestedStateful.java	2007-02-19 09:08:42 UTC (rev 60657)
+++ branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredsession/nested/NestedStateful.java	2007-02-19 09:12:25 UTC (rev 60658)
@@ -1,25 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- *
- * Distributable under LGPL license.
- * See terms of license at gnu.org.
- */
-
-package org.jboss.ejb3.test.clusteredsession.nested;
-
-import org.jboss.ejb3.test.clusteredsession.NodeAnswer;
-
-import java.rmi.dgc.VMID;
-
-/**
- * Comment
- *
- * @author Ben Wang
- * @version $Revision$
- */
-public interface NestedStateful
-{
-   int increment();   
-   void reset();   
-   void remove();
-}

Deleted: branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredsession/nested/NestedStatefulBean.java
===================================================================
--- branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredsession/nested/NestedStatefulBean.java	2007-02-19 09:08:42 UTC (rev 60657)
+++ branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredsession/nested/NestedStatefulBean.java	2007-02-19 09:12:25 UTC (rev 60658)
@@ -1,81 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- *
- * Distributable under LGPL license.
- * See terms of license at gnu.org.
- */
-
-package org.jboss.ejb3.test.clusteredsession.nested;
-
-import org.jboss.annotation.ejb.Clustered;
-import org.jboss.annotation.ejb.cache.tree.CacheConfig;
-import org.jboss.logging.Logger;
-
-import javax.ejb.*;
-
-/**
- * Nested SFSB
- *
- * @author Ben Wang
- * @version $Revision$
- */
- at Stateful(name="testNestedStateful")
- at Clustered
- 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
-{
-   /** The serialVersionUID */
-   private static final long serialVersionUID = 1L;
-   
-   private static Logger log = Logger.getLogger(NestedStatefulBean.class);
-   private int counter = 0;
-
-   public int increment()
-   {
-      counter++;
-      log.debug("INCREMENT - nested counter: " + counter);
-      return counter;
-   }
-
-   public static int postActivateCalled = 0;
-   public static int prePassivateCalled = 0;
-
-   public int getPostActivate()
-   {
-      return postActivateCalled;
-   }
-
-   public int getPrePassivate()
-   {
-      return prePassivateCalled;
-   }
-
-   public void reset()
-   {
-      counter = 0;
-      NestedStatefulBean.postActivateCalled = 0;
-      NestedStatefulBean.prePassivateCalled = 0;
-   }
-   
-   @Remove
-   public void remove() 
-   {
-      log.debug("Being removed");
-   }
-
-   @PostActivate
-   public void postActivate()
-   {
-      ++NestedStatefulBean.postActivateCalled;
-      log.debug("postActivate: - counter: " + counter + 
-            " -- activate count:" + postActivateCalled);
-   }
-
-   @PrePassivate
-   public void prePassivate()
-   {
-      ++NestedStatefulBean.prePassivateCalled;
-      log.debug("prePassivate: - counter: " + counter + 
-            " -- passivate count:" + prePassivateCalled);
-   }
-}

Deleted: branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredsession/nested/ParentStatefulBean.java
===================================================================
--- branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredsession/nested/ParentStatefulBean.java	2007-02-19 09:08:42 UTC (rev 60657)
+++ branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredsession/nested/ParentStatefulBean.java	2007-02-19 09:12:25 UTC (rev 60658)
@@ -1,206 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- *
- * Distributable under LGPL license.
- * See terms of license at gnu.org.
- */
-
-package org.jboss.ejb3.test.clusteredsession.nested;
-
-import org.jboss.annotation.ejb.Clustered;
-import org.jboss.annotation.ejb.cache.tree.CacheConfig;
-import org.jboss.logging.Logger;
-import org.jboss.system.server.ServerConfig;
-import org.jboss.ejb3.test.clusteredsession.ExplicitFailoverInterceptor;
-import org.jboss.ejb3.test.clusteredsession.NodeAnswer;
-import org.jboss.ejb3.test.clusteredsession.ClusteredStatelessRemote;
-
-import javax.interceptor.Interceptors;
-import javax.annotation.PostConstruct;
-import javax.ejb.EJB;
-import javax.ejb.Stateful;
-import javax.ejb.Remote;
-import javax.ejb.PostActivate;
-import javax.ejb.PrePassivate;
-import javax.ejb.Remove;
-import javax.ejb.EJBException;
-import java.rmi.dgc.VMID;
-
-/**
- * SFSB with nested bean
- *
- * @author Ben Wang
- * @version $Revision$
- */
- at Stateful(name="testParentStateful")
- at Clustered
-// Mimic explict failover
- at Interceptors({ExplicitFailoverInterceptor.class})
- at CacheConfig(maxSize=1000, idleTimeoutSeconds=3)   // this will get evicted the second time eviction thread wakes up
- at Remote(ParentStatefulRemote.class)
-public class ParentStatefulBean implements java.io.Serializable, ParentStatefulRemote
-{
-   /** The serialVersionUID */
-   private static final long serialVersionUID = 1L;
-   
-   private static Logger log = Logger.getLogger(ParentStatefulBean.class);
-   private int counter = 0;
-   private String state;
-   public transient VMID myId = null;
-   public String name;
-
-   @EJB
-   private NestedStateful nested;
-
-   @EJB
-   private ClusteredStatelessRemote slsb;
-
-   public int increment()
-   {
-      counter = nested.increment();
-
-      log.debug("INCREMENT - parent counter: " + counter);
-      return counter;
-   }
-
-   public String getHostAddress()
-   {
-      return System.getProperty(ServerConfig.SERVER_BIND_ADDRESS);
-   }
-
-   public static int postActivateCalled = 0;
-   public static int prePassivateCalled = 0;
-
-   /**
-    * Sleep to test
-    * @throws Exception
-    */
-   public void longRunning() throws Exception
-   {
-      log.debug("+++ longRunning() enter ");
-      Thread.sleep(10000);
-      log.debug("+++ longRunning() leave ");
-   }
-
-   public int getPostActivate()
-   {
-      return ParentStatefulBean.postActivateCalled;
-   }
-
-   public int getPrePassivate()
-   {
-      return ParentStatefulBean.prePassivateCalled;
-   }
-
-   public int getNestedPostActivate()
-   {
-      return NestedStatefulBean.postActivateCalled;
-   }
-
-   public int getNestedPrePassivate()
-   {
-      return NestedStatefulBean.prePassivateCalled;
-   }
-
-   public void setState(String state)
-   {
-      this.state = state;
-   }
-
-   public String getState()
-   {
-      log.debug("getState(): entering ...");
-      return this.state;
-   }
-
-   public NodeAnswer getStatelessState() {
-      return slsb.getNodeState();
-   }
-
-   public void reset()
-   {
-      state = null;
-      counter = 0;
-      ParentStatefulBean.postActivateCalled = 0;
-      ParentStatefulBean.prePassivateCalled = 0;
-      NestedStatefulBean.postActivateCalled = 0;
-      NestedStatefulBean.prePassivateCalled = 0;
-   }
-
-   public void resetActivationCounter()
-   {
-      ParentStatefulBean.postActivateCalled = 0;
-      ParentStatefulBean.prePassivateCalled = 0;
-      NestedStatefulBean.postActivateCalled = 0;
-      NestedStatefulBean.prePassivateCalled = 0;
-   }
-
-   @PostActivate
-   public void postActivate()
-   {
-      ++ParentStatefulBean.postActivateCalled;
-      if (this.myId == null)
-      {
-         //it is a failover: we need to assign ourself an id
-         this.myId = new VMID();
-      }
-      log.debug("Activate. My ID: " + this.myId + " name: " + this.name +
-            " activate count: " + postActivateCalled);
-   }
-
-   @PrePassivate
-   public void prePassivate()
-   {
-      ++ParentStatefulBean.prePassivateCalled;
-      log.debug("Passivate. My ID: " + this.myId + " name: " + this.name +
-                " passivate count: " + prePassivateCalled);
-   }
-
-   @Remove
-   public void remove()
-   {
-      log.debug("Being removed");
-   }
-
-   @PostConstruct
-   public void ejbCreate()
-   {
-      this.myId = new VMID();
-      log.debug("My ID: " + this.myId);
-   }
-
-   // Remote Interface implementation ----------------------------------------------
-
-   public NodeAnswer getNodeState()
-   {
-      if (this.myId == null)
-      {
-         //it is a failover: we need to assign ourself an id
-         this.myId = new VMID();
-      }
-
-      NodeAnswer state = new NodeAnswer(this.myId, this.name);
-      log.debug("getNodeState, " + state);
-      return state;
-   }
-
-   public void setName(String name)
-   {
-      this.name = name;
-      log.debug("Name set to " + name);
-   }
-
-   public void setNameOnlyOnNode(String name, VMID node)
-   {
-      if (node.equals(this.myId))
-         this.setName(name);
-      else
-         throw new EJBException("Trying to assign value on node " + this.myId + " but this node expected: " + node);
-   }
-
-   public void setUpFailover(String failover) {
-      // To setup the failover property
-      log.debug("Setting up failover property: " +failover);
-      System.setProperty ("JBossCluster-DoFail", failover);
-   }
-}

Deleted: branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredsession/nested/ParentStatefulRemote.java
===================================================================
--- branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredsession/nested/ParentStatefulRemote.java	2007-02-19 09:08:42 UTC (rev 60657)
+++ branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredsession/nested/ParentStatefulRemote.java	2007-02-19 09:12:25 UTC (rev 60658)
@@ -1,54 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- *
- * Distributable under LGPL license.
- * See terms of license at gnu.org.
- */
-
-package org.jboss.ejb3.test.clusteredsession.nested;
-
-import org.jboss.ejb3.test.clusteredsession.NodeAnswer;
-
-import java.rmi.dgc.VMID;
-
-/**
- * Comment
- *
- * @author Ben Wang
- * @version $Revision$
- */
-public interface ParentStatefulRemote
-{
-   int increment();
-   String getHostAddress();
-
-   int getPostActivate();
-
-   int getPrePassivate();
-
-   int getNestedPostActivate();
-
-   int getNestedPrePassivate();
-
-   void setState(String state);
-
-   String getState();
-
-   NodeAnswer getStatelessState();
-
-   void reset();
-
-   void resetActivationCounter();
-
-   void longRunning() throws Exception;
-
-   void remove();
-
-   public NodeAnswer getNodeState();
-
-   public void setName(String name);
-
-   public void setNameOnlyOnNode(String name, VMID node);
-
-   public void setUpFailover(String failover);
-}

Modified: branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredsession/unit/ExtendedPersistenceUnitTestCase.java
===================================================================
--- branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredsession/unit/ExtendedPersistenceUnitTestCase.java	2007-02-19 09:08:42 UTC (rev 60657)
+++ branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredsession/unit/ExtendedPersistenceUnitTestCase.java	2007-02-19 09:12:25 UTC (rev 60658)
@@ -21,44 +21,74 @@
  */
 package org.jboss.ejb3.test.clusteredsession.unit;
 
-import org.jboss.ejb3.test.clusteredentity.unit.DBSetup;
-import org.jboss.ejb3.test.clusteredsession.Customer;
-import org.jboss.ejb3.test.clusteredsession.NodeAnswer;
-import org.jboss.ejb3.test.clusteredsession.ShoppingCart;
-import org.jboss.ejb3.test.clusteredsession.StatelessRemote;
-import org.jboss.test.JBossClusteredTestCase;
+import java.rmi.dgc.VMID;
+import java.util.Properties;
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+
+import junit.framework.Assert;
 import junit.framework.Test;
 import junit.framework.TestSuite;
 
-import javax.naming.InitialContext;
-import javax.naming.Context;
+import org.jboss.ejb3.test.clusteredentity.unit.DBSetup;
+import org.jboss.ejb3.test.stateful.nested.base.xpc.Customer;
+import org.jboss.ejb3.test.stateful.nested.base.xpc.NestedXPCMonitor;
+import org.jboss.ejb3.test.stateful.nested.base.xpc.ShoppingCart;
+import org.jboss.ejb3.test.stateful.unit.XPCTestRunner;
+import org.jboss.ejb3.test.stateful.unit.XPCTestRunner.BeanSet;
+import org.jboss.logging.Logger;
+import org.jboss.test.JBossClusteredTestCase;
 
-import java.rmi.dgc.VMID;
-import java.util.Properties;
-
 /**
- * Tests for extended persistence under clustering.
+ * Tests for ExtendedPersistenceContext management.
+ * 
+ * This class uses a delegate to execute the tests so the clustered
+ * version of the tests (which derive from a different base class)
+ * can use the same delegate code.
  *
  * @author Ben Wang
  * @version $Id$
  */
-
-public class ExtendedPersistenceUnitTestCase extends JBossClusteredTestCase
+public class ExtendedPersistenceUnitTestCase 
+   extends JBossClusteredTestCase
 {
-   org.apache.log4j.Logger log = getLog();
-
-   static boolean deployed = false;
-   static int test = 0;
-
+   private static final Logger log = Logger.getLogger(ExtendedPersistenceUnitTestCase.class);
+   
+   private XPCTestRunner runner;
+   
    public ExtendedPersistenceUnitTestCase(String name)
    {
-
       super(name);
+   }
 
+   public static Test suite() throws Exception
+   {
+      TestSuite suite = new TestSuite();
+      Test t1 = getDeploySetup(ExtendedPersistenceUnitTestCase.class,
+                               "clusteredsession-test.jar");
+
+      suite.addTest(t1);
+
+      // Create an initializer for the test suite
+      DBSetup wrapper = new DBSetup(suite);
+      return wrapper;     
    }
 
-   protected InitialContext getInitialContext(int node) throws Exception {
-      // Connect to the server0 JNDI
+   
+   @Override
+   protected void setUp() throws Exception
+   {
+      super.setUp();
+      
+      runner = new XPCTestRunner(getInitialContext(0), log);
+      runner.setUp();
+      // Use a sleep time equal to 2 thread runs + a 100 ms fudge
+      runner.setSleepTime(10100L);
+   }
+
+   private InitialContext getInitialContext(int node) throws Exception {
+      // Connect to the serverX JNDI
       String[] urls = getNamingURLs();
       Properties env1 = new Properties();
       env1.setProperty(Context.INITIAL_CONTEXT_FACTORY,
@@ -67,104 +97,160 @@
       return new InitialContext(env1);
    }
 
+
+   @Override
+   protected void tearDown() throws Exception
+   {
+      super.tearDown();
+      
+      if (runner != null)
+         runner.tearDown();
+   }
+
+
    public void testBasic() throws Exception
    {
-      ShoppingCart cart = (ShoppingCart) getInitialContext(0).lookup("ShoppingCartBean/remote");
-      StatelessRemote stateless = (StatelessRemote) getInitialContext(0).lookup("StatelessSessionBean/remote");
-      Customer customer;
-
-      long id = cart.createCustomer();
-      customer = stateless.find(id);
-      assertEquals("William", customer.getName());
-      customer = cart.find(id);
-      assertEquals("William", customer.getName());
-      cart.update();
-      customer = stateless.find(id);
-      assertEquals("Bill", customer.getName());
-      customer = cart.find(id);
-      assertEquals("Bill", customer.getName());
-      cart.update2();
-      customer = stateless.find(id);
-      assertEquals("Billy", customer.getName());
-      customer = cart.find(id);
-      assertEquals("Billy", customer.getName());
-      cart.update3();
-      customer = stateless.find(id);
-      assertEquals("Bill Jr.", customer.getName());
-      customer = cart.find(id);
-      assertEquals("Bill Jr.", customer.getName());
-      cart.setContainedCustomer();
-      cart.checkout();
+      runner.testBasic();
    }
+   
+   public void testDependentLifecycle() throws Exception
+   {
+      runner.testDependentLifecycle();
+   }
+   
+   public void testXPCSharing() throws Exception
+   {
+      runner.testXPCSharing();
+   }
 
    public void testPassivation() throws Exception
    {
-      // We want a colocated SLSB and SFSB to test passivation/destruction
-      // StatelessRemoteBean is not clustered, so once we have it's VMID
-      // we can keep creating SFSBs until we get one we want
-      StatelessRemote stateless = (StatelessRemote) getInitialContext(0).lookup("StatelessSessionBean/remote");
-      VMID statelessVM = stateless.getVMID();
+      runner.testPassivation();
+   }
+   
+   public void testFailover() throws Exception
+   {
+      failoverTest(false, false, false);
+   }
+   
+   public void testRepeatedFailover() throws Exception
+   {
+      failoverTest(false, false, true);
+   }
+   
+   public void testFailoverWithPassivation() throws Exception
+   {
+      failoverTest(true, false, false);
+   }
+   
+   public void testRepeatedFailoverWithPassivation() throws Exception
+   {
+      failoverTest(true, true, true);
+   }
+   
+   private void failoverTest(boolean passivate, boolean passivateAgain, boolean repeated)
+   throws Exception
+   {
+      BeanSet beanSet = runner.getBeanSet();
+      ShoppingCart parent = beanSet.cart;
+      NestedXPCMonitor monitor = beanSet.monitor;
       
-      ShoppingCart cart = null;      
-      boolean vmMatch = false;
-      for (int i = 0; i < 10 && !vmMatch; i++)
+      // Confirm the nested beans are there
+      String deepId = monitor.getDeepNestedId();
+      Assert.assertNotNull("Got a deepId", deepId);
+      Assert.assertFalse("Got a non-ERROR deepId", "ERROR".equals(deepId));
+      String localDeepId = monitor.getLocalDeepNestedId();
+      Assert.assertNotNull("Got a localDeepId", localDeepId);
+      Assert.assertFalse("Got a non-ERROR localDeepId", "ERROR".equals(localDeepId));
+      
+      VMID origId = parent.getVMID();
+      Assert.assertNotNull("Got a VMID", origId);
+      
+      long id = parent.createCustomer();  
+      Customer customer = parent.find(id);
+      Assert.assertNotNull("Customer created and found on parent", customer);
+      
+      parent.setContainedCustomer();
+      Assert.assertTrue("Parent and contained share customer", parent.checkContainedCustomer());
+      
+      Assert.assertTrue("Parent and remote nested do not share ref", 
+                        monitor.compareTopToNested(id));
+      Assert.assertTrue("Parent and local nested do share ref", 
+                         monitor.compareTopToLocalNested(id));
+      Assert.assertTrue("Remote nested and local nested do not share a ref",
+                        monitor.compareNestedToLocalNested(id));
+      Assert.assertTrue("Remote nested and deepNested share a ref", 
+                        monitor.compareNestedToDeepNested(id));
+      Assert.assertTrue("Local nested and localDeepNested share a ref", 
+                        monitor.compareLocalNestedToLocalDeepNested(id));
+      
+      VMID newId = parent.getVMID();
+      Assert.assertTrue("VMID remained the same", origId.equals(newId));
+      
+      if (passivate)
       {
-         cart = (ShoppingCart) getInitialContext(0).lookup("ShoppingCartBean/remote");
-         vmMatch = statelessVM.equals(cart.getVMID());
-         if (!vmMatch)
-            cart.checkout();
+         runner.sleep();
       }
       
-      assertTrue("SLSB and SFSB in same VM", vmMatch);
+      parent.setUpFailover("once");
       
-      Customer customer;
+      newId = parent.getVMID();
+      assertNotNull("Got a new VMID", newId);
+      assertFalse("Failover has occurred", origId.equals(newId));
       
-      long id = cart.createCustomer();
-      customer = stateless.find(id);
-      assertEquals("William", customer.getName());
-      customer = cart.find(id);
-      assertEquals("William", customer.getName());
-      cart.update();
-      customer = stateless.find(id);
-      assertEquals("Bill", customer.getName());
-      customer = cart.find(id);
-      assertEquals("Bill", customer.getName());
-      cart.update2();
-      customer = stateless.find(id);
-      assertEquals("Billy", customer.getName());
-      customer = cart.find(id);
-      assertEquals("Billy", customer.getName());
-      cart.update3();
-      customer = stateless.find(id);
-      assertEquals("Bill Jr.", customer.getName());
-      customer = cart.find(id);
-      assertEquals("Bill Jr.", customer.getName());
-      cart.setContainedCustomer();
+      InitialContext[] ctxs = new InitialContext[2];
+      ctxs[0] = getInitialContext(1);
+      ctxs[1] = getInitialContext(0);
+      monitor = runner.getXPCMonitor(ctxs, newId);      
       
-      Thread.sleep(11000); // passivation      
-      assertTrue("Contained bean was passivated", stateless.isPassivated());
+      monitor.monitor(parent);
       
-      cart.checkContainedCustomer();
-      cart.findAndUpdateStateless();
-      cart.updateContained();
+      Assert.assertTrue("Parent and remote nested do not share ref", 
+                        monitor.compareTopToNested(id));
+      Assert.assertTrue("Parent and local nested do share ref", 
+                         monitor.compareTopToLocalNested(id));
+      Assert.assertTrue("Remote nested and local nested do not share a ref",
+                        monitor.compareNestedToLocalNested(id));
+      Assert.assertTrue("Remote nested and deepNested share a ref", 
+                        monitor.compareNestedToDeepNested(id));
+      Assert.assertTrue("Local nested and localDeepNested share a ref", 
+                        monitor.compareLocalNestedToLocalDeepNested(id));
       
-      stateless.clearDestroyed();
-      assertTrue(cart.isContainedActivated());      
-      cart.checkout();
-      assertFalse("Contained bean was not destroyed", stateless.isDestroyed());
+      if (repeated)
+      {
+         if (passivateAgain)
+         {
+            runner.sleep();
+         }
+         origId = newId;
+         
+         parent.setUpFailover("once");
+         
+         newId = parent.getVMID();
+         assertNotNull("Got a new VMID", newId);
+         assertFalse("Failover has occurred", origId.equals(newId));
+         
+         // Swap the contexts so we try node0 first
+         InitialContext ctx = ctxs[1];
+         ctxs[1] = ctxs[0];
+         ctxs[0] = ctx;
+         
+         monitor = runner.getXPCMonitor(ctxs, newId);      
+         
+         monitor.monitor(parent);
+         
+         Assert.assertTrue("Parent and remote nested do not share ref", 
+                           monitor.compareTopToNested(id));
+         Assert.assertTrue("Parent and local nested do share ref", 
+                            monitor.compareTopToLocalNested(id));
+         Assert.assertTrue("Remote nested and local nested do not share a ref",
+                           monitor.compareNestedToLocalNested(id));
+         Assert.assertTrue("Remote nested and deepNested share a ref", 
+                           monitor.compareNestedToDeepNested(id));
+         Assert.assertTrue("Local nested and localDeepNested share a ref", 
+                           monitor.compareLocalNestedToLocalDeepNested(id));
+         
+      }  
    }
 
-   public static Test suite() throws Exception
-   {
-      TestSuite suite = new TestSuite();
-      Test t1 = getDeploySetup(ExtendedPersistenceUnitTestCase.class,
-                               "clusteredsession-test.jar");
-
-      suite.addTest(t1);
-
-      // Create an initializer for the test suite
-      DBSetup wrapper = new DBSetup(suite);
-      return wrapper;     
-   }
-
 }

Modified: branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredsession/unit/NestedBeanUnitTestCase.java
===================================================================
--- branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredsession/unit/NestedBeanUnitTestCase.java	2007-02-19 09:08:42 UTC (rev 60657)
+++ branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredsession/unit/NestedBeanUnitTestCase.java	2007-02-19 09:12:25 UTC (rev 60658)
@@ -7,36 +7,36 @@
 
 package org.jboss.ejb3.test.clusteredsession.unit;
 
-import org.jboss.test.JBossClusteredTestCase;
-import org.jboss.ejb3.test.clusteredsession.NodeAnswer;
-import org.jboss.ejb3.test.clusteredsession.nested.ParentStatefulRemote;
+import java.rmi.dgc.VMID;
+import java.util.Properties;
 
 import javax.naming.Context;
 import javax.naming.InitialContext;
-import java.util.Date;
-import java.util.Properties;
 
 import junit.framework.Test;
 
+import org.jboss.ejb3.test.stateful.nested.base.std.ParentStatefulRemote;
+import org.jboss.ejb3.test.stateful.unit.NestedBeanTestRunner;
+import org.jboss.ejb3.test.stateful.unit.NestedBeanTestRunner.NestedBeanSet;
+import org.jboss.logging.Logger;
+import org.jboss.test.JBossClusteredTestCase;
+
 /**
- * Test nested SFSB for load-balancing and failover behaviour
- *
- * @author  Ben.Wang at jboss.org
+ * Overrides the parent test to use clustered versions of
+ * the beans.
+ * 
+ * @author <a href="brian.stansberry at jboss.com">Brian Stansberry</a>
  * @version $Revision$
  */
-public class NestedBeanUnitTestCase extends JBossClusteredTestCase
+public class NestedBeanUnitTestCase 
+   extends JBossClusteredTestCase
 {
-   static boolean deployed = false;
-   public static int test = 0;
-   static Date startDate = new Date();
-
-   protected final String namingFactory =
-   System.getProperty(Context.INITIAL_CONTEXT_FACTORY);
-
-   protected final String providerURL =
-   System.getProperty(Context.PROVIDER_URL);
-
-   public NestedBeanUnitTestCase (String name)
+   private static final Logger log = Logger.getLogger(NestedBeanUnitTestCase.class);
+   
+   private NestedBeanTestRunner runner;
+   
+   
+   public NestedBeanUnitTestCase(String name)
    {
       super(name);
    }
@@ -44,13 +44,30 @@
    public static Test suite() throws Exception
    {
       final String jarName = "clusteredsession-test.jar";
-      Test t1 = JBossClusteredTestCase.getDeploySetup(NestedBeanUnitTestCase.class,
-              jarName);
+      Test t1 = getDeploySetup(NestedBeanUnitTestCase.class,
+                               jarName);
       return t1;
    }
+   
+   
+   @Override
+   protected void setUp() throws Exception
+   {
+      super.setUp();
+      
+      runner = new NestedBeanTestRunner(getInitialContext(0), log);
+      runner.setUp();
+      // Use a sleep time equal to 2 thread runs + a 100 ms fudge
+      runner.setSleepTime(10100L);
+      // For clustered beans, an invocation is a passivation
+      runner.setPassivationPerInvocation(1);
+      // For clustered beans, passivation occurs after already called
+      // @PrePassivate for replication, so don't get a 2nd event
+      runner.setPassivationPerSleep(0);
+   }
 
-   protected InitialContext getInitialContext(int node) throws Exception {
-      // Connect to the server0 JNDI
+   private InitialContext getInitialContext(int node) throws Exception {
+      // Connect to the serverX JNDI
       String[] urls = getNamingURLs();
       Properties env1 = new Properties();
       env1.setProperty(Context.INITIAL_CONTEXT_FACTORY,
@@ -59,122 +76,95 @@
       return new InitialContext(env1);
    }
 
+   @Override
+   protected void tearDown() throws Exception
+   {
+      super.tearDown();
+      
+      if (runner != null)
+         runner.tearDown();
+   }
 
    public void testBasic()
    throws Exception
    {
-      getLog().debug(++NestedBeanUnitTestCase.test +"- "
-              +"Trying the context...");
+      runner.testBasic();
+   }
+   
+   public void testDependentLifecycle()
+   throws Exception
+   {
+      runner.testDependentLifecycle();      
+   }
 
-      // Connect to the server0 JNDI
-      InitialContext ctx = getInitialContext(0);
+   public void testStatefulPassivation()
+   throws Exception
+   {
+      runner.testStatefulPassivation();
+   }
 
-      getLog().debug("Test Nested Stateful Bean");
-      getLog().debug("==================================");
-      getLog().debug(++NestedBeanUnitTestCase.test +"- "
-              +"Looking up testBasic...");
-      ParentStatefulRemote stateful = (ParentStatefulRemote) ctx.lookup("testParentStateful/remote");
 
-      stateful.reset();
-      stateful.setName("The Code");
-      _sleep(300);
-
-      NodeAnswer node1 = stateful.getNodeState ();
+   public void testStatefulBeanCounterFailoverWithRemote()
+   throws Exception
+   {
+      getLog().debug("Test Nested Stateful Bean Counter Failover with Remote");
+      getLog().debug("======================================================");
+      
+      NestedBeanSet beanSet = runner.getNestedBeanSet();
+      ParentStatefulRemote stateful = beanSet.parent;
+      VMID node1 = stateful.getVMID();
+      assertNotNull("State node: ", node1);
       getLog ().debug ("Node 1 ID: " +node1);
 
       assertEquals("Counter: ", 1, stateful.increment());
       assertEquals("Counter: ", 2, stateful.increment());
+      sleep(300);
 
-      stateful.remove();
-      getLog().debug("ok");
-      _sleep(11000);
-   }
+      // Now we switch to the other node, simulating a failure on node 1
+      stateful.setUpFailover("once");
+      VMID node2 = stateful.getVMID();
+      assertNotNull("State node: ", node2);
+      getLog ().debug ("Node 2 ID : " +node2);
 
-   public void testPassivation()
-   throws Exception
-   {
-      getLog().debug(++NestedBeanUnitTestCase.test +"- "
-              +"Trying the context...");
+      assertFalse("Failover has occured", node1.equals(node2));
 
-      // Connect to the server0 JNDI
-      InitialContext ctx = getInitialContext(0);
-
-      getLog().debug("Test Nested Stateful Bean");
-      getLog().debug("==================================");
-      getLog().debug(++NestedBeanUnitTestCase.test +"- "
-              +"Looking up remote...");
-      ParentStatefulRemote stateful = (ParentStatefulRemote) ctx.lookup("testParentStateful/remote");
-
-      stateful.setName("The Code");
-      _sleep(300);
-
-      NodeAnswer node1 = stateful.getNodeState ();
-      getLog ().debug ("Node 1 ID: " +node1);
-//      _sleep(300000);
-      assertEquals("Counter: ", 1, stateful.increment());
-      assertEquals("Counter: ", 2, stateful.increment());
-      assertEquals("SLSB state: ", "test", stateful.getStatelessState().getAnswer());
-      stateful.reset();
-      _sleep(11000);
       assertEquals("Counter: ", 3, stateful.increment());
-      assertEquals("SLSB state: ", "test", stateful.getStatelessState().getAnswer());
-      assertEquals(1, stateful.getPrePassivate());
-      assertEquals(1, stateful.getPostActivate());
-      assertEquals(1, stateful.getNestedPrePassivate());
-      assertEquals(1, stateful.getNestedPostActivate());
+      assertEquals("Counter: ", 4, stateful.increment());
 
-      stateful.remove();
-      getLog().debug("ok: done");
-      _sleep(12000);
+      runner.removeBean(stateful);
+      getLog().debug("ok");
    }
 
+
    public void testStatefulBeanCounterFailover()
    throws Exception
    {
-      getLog().debug(++NestedBeanUnitTestCase.test +"- "+"Trying the context...");
-
-      // Connect to the server0 JNDI
-      InitialContext ctx = getInitialContext(0);
-
-      getLog().debug("Test Stateful Bean Failover");
-      getLog().debug("==================================");
-      getLog().debug(++NestedBeanUnitTestCase.test +"- "
-              +"Looking up testParentStateful...");
-      ParentStatefulRemote stateful = (ParentStatefulRemote) ctx.lookup("testParentStateful/remote");
-
-      stateful.setName("The Code");
-      NodeAnswer node1 = stateful.getNodeState ();
+      getLog().debug("Test Nested Stateful Bean Counter Failover");
+      getLog().debug("==========================================");
+      
+      NestedBeanSet beanSet = runner.getNestedBeanSet();
+      ParentStatefulRemote stateful = beanSet.parent;
+      VMID node1 = stateful.getVMID();
+      assertNotNull("State node: ", node1);
       getLog ().debug ("Node 1 ID: " +node1);
 
-      assertEquals("Counter: ", 1, stateful.increment());
-      assertEquals("Counter: ", 2, stateful.increment());
-      _sleep(300);
+      assertEquals("Counter: ", 1, stateful.incrementLocal());
+      assertEquals("Counter: ", 2, stateful.incrementLocal());
+      sleep(300);
 
       // Now we switch to the other node, simulating a failure on node 1
-      //
       stateful.setUpFailover("once");
-      NodeAnswer node2 = stateful.getNodeState();
+      VMID node2 = stateful.getVMID();
       assertNotNull("State node: ", node2);
       getLog ().debug ("Node 2 ID : " +node2);
 
-      assertFalse("Failover has occured", node1.nodeId.equals(node2.nodeId));
+      assertFalse("Failover has occured", node1.equals(node2));
 
-      assertEquals ("Node 1: ", "The Code", node1.answer);
-      assertEquals ("Node 2: ", "The Code", node2.answer);
+      assertEquals("Counter: ", 3, stateful.incrementLocal());
+      assertEquals("Counter: ", 4, stateful.incrementLocal());
 
-      assertEquals("Counter: ", 3, stateful.increment());
-      assertEquals("Counter: ", 4, stateful.increment());
-
-      stateful.remove();
+      runner.removeBean(stateful);
       getLog().debug("ok");
    }
 
-   protected void _sleep(long time)
-   {
-      try {
-         Thread.sleep(time);
-      } catch (InterruptedException e) {
-         e.printStackTrace();
-      }
-   }
 }

Modified: branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredsession/unit/PassivationUnitTestCase.java
===================================================================
--- branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredsession/unit/PassivationUnitTestCase.java	2007-02-19 09:08:42 UTC (rev 60657)
+++ branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredsession/unit/PassivationUnitTestCase.java	2007-02-19 09:12:25 UTC (rev 60658)
@@ -74,21 +74,97 @@
               +"Looking up testStateful...");
       StatefulRemote remote = (StatefulRemote) ctx.lookup("testStateful/remote");
 
+      int invCount = 0;
+      
       remote.reset();
+      invCount++;
       remote.setState("hello");
-      sleep_(11000);
+      invCount++;
+      
+      sleep_(11100);
+      
       assertEquals("hello", remote.getState());
-      assertEquals(1, remote.getPrePassivate());
-      assertEquals(1, remote.getPostActivate());
+      invCount++;
+      
+      assertEquals(invCount, remote.getPrePassivate());
+      invCount++;
+      
+      assertEquals(invCount, remote.getPostActivate());
 
-      sleep_(11000);
       remote.remove();
 
    }
 
+   /**
+    * Tests that @CacheConfig.replicationIsPassivation=false works.
+    */
+   public void testIgnoreReplicationStatefulPassivation()
+      throws Exception
+   {
+      log.info("+++ testIgnoreReplicationStatefulPassivation");
+
+      // Connect to the server0 JNDI
+      InitialContext ctx = getInitialContext(0);
+
+      getLog().debug("==================================");
+      getLog().debug(++PassivationUnitTestCase.test +"- "
+              +"Looking up testIgnoreReplicationStateful...");
+      StatefulRemote remote = (StatefulRemote) ctx.lookup("testIgnoreReplicationStateful/remote");
+
+      remote.reset();
+      remote.setState("hello");
+      
+      sleep_(11100);
+      
+      assertEquals("hello", remote.getState());      
+      assertEquals("@PrePassivate count correct", 1, remote.getPrePassivate());
+      assertEquals("@PostActivate count correct", 1, remote.getPostActivate());
+
+      remote.remove();
+   }
+   
+   /**
+    * Tests that disabling replication via implementing Optimized works.
+    */
+   public void testOptimizedDisablesReplication()
+      throws Exception
+   {
+      log.info("+++ testOptimizedDisablesReplication");
+
+      // Connect to the server0 JNDI
+      InitialContext ctx = getInitialContext(0);
+
+      getLog().debug("==================================");
+      getLog().debug(++PassivationUnitTestCase.test +"- "
+              +"Looking up testOptimizedStateful...");
+      StatefulRemote remote = (StatefulRemote) ctx.lookup("testOptimizedStateful/remote");
+
+      int invCount = 0;
+      remote.reset();
+      invCount++;
+      remote.setState("hello");
+      invCount++;
+      
+      sleep_(10100);
+      
+      assertEquals("hello", remote.getState());
+      invCount++;
+      
+      // Don't include the regular passivation in the count
+      // since there won't be an event following replication
+      assertEquals(invCount, remote.getPrePassivate());
+      // don't increment count
+      assertEquals(invCount, remote.getPostActivate());
+      // don't increment count
+      // Check that getPostActivate() didn't cause replication
+      assertEquals(invCount, remote.getPrePassivate());
+      
+      remote.remove();
+   }
+
    /** This is to test failover with passivation
     */
-   public void XtestFailoverStatefulPassivation()
+   public void testFailoverStatefulPassivation()
       throws Exception
    {
       log.info("+++ testFiloverStatefulPassivation");
@@ -100,20 +176,21 @@
       getLog().debug(++PassivationUnitTestCase.test +"- "
               +"Looking up testStateful...");
       StatefulRemote stateful = (StatefulRemote) ctx.lookup("testStateful/remote");
+
       stateful.reset();
-
+      
       stateful.setName("The Code");
-      NodeAnswer node1 = stateful.getNodeState ();
+      NodeAnswer node1 = stateful.getNodeState();
       getLog ().debug ("Node 1 ID: " +node1);
 
       assertEquals("Counter: ", 1, stateful.increment());
       assertEquals("Counter: ", 2, stateful.increment());
-      sleep_(10000);
+      
+      sleep_(10100);
 
       // Now we switch to the other node, simulating a failure on node 1
-      //
       stateful.setUpFailover("once");
-      NodeAnswer node2 = stateful.getNodeState ();
+      NodeAnswer node2 = stateful.getNodeState();
       assertNotNull("State node: ", node2);
       getLog ().debug ("Node 2 ID : " +node2);
 
@@ -123,12 +200,19 @@
       assertEquals ("Node 2: ", "The Code", node2.answer);
 
       stateful.resetActivationCounter(); // This will activate the bean.
-      sleep_(10000); // let it get passivated again.
+      int invCount = 1;
+      
+      sleep_(10100); // let it get passivated again.
+      
       assertEquals("Counter: ", 3, stateful.increment());
+      invCount++;
       assertEquals("Counter: ", 4, stateful.increment());
-      assertEquals(1, stateful.getPostActivate());
-      assertEquals(1, stateful.getPrePassivate());
+      invCount++;
 
+      assertEquals(invCount, stateful.getPrePassivate());
+      invCount++;
+      assertEquals(invCount, stateful.getPostActivate());
+
       stateful.remove();
    }
 

Deleted: branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/stateful/nested/BaseNestedStatefulBean.java
===================================================================
--- branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/stateful/nested/BaseNestedStatefulBean.java	2007-02-19 09:08:42 UTC (rev 60657)
+++ branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/stateful/nested/BaseNestedStatefulBean.java	2007-02-19 09:12:25 UTC (rev 60658)
@@ -1,55 +0,0 @@
-/*
- * 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()
-   {
-      log.debug("Being reset");
-      counter = 0;
-   }
-   
-   @Remove
-   public void remove() 
-   {
-      log.debug("Being removed");
-   }
-
-   protected int getCounter()
-   {
-      return counter;
-   }
-}

Deleted: branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/stateful/nested/LocalNestedStatefulBean.java
===================================================================
--- branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/stateful/nested/LocalNestedStatefulBean.java	2007-02-19 09:08:42 UTC (rev 60657)
+++ branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/stateful/nested/LocalNestedStatefulBean.java	2007-02-19 09:12:25 UTC (rev 60658)
@@ -1,69 +0,0 @@
-/*
- * 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;
-   }
-}

Deleted: branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/stateful/nested/NestedStateful.java
===================================================================
--- branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/stateful/nested/NestedStateful.java	2007-02-19 09:08:42 UTC (rev 60657)
+++ branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/stateful/nested/NestedStateful.java	2007-02-19 09:12:25 UTC (rev 60658)
@@ -1,23 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- *
- * Distributable under LGPL license.
- * See terms of license at gnu.org.
- */
-
-package org.jboss.ejb3.test.stateful.nested;
-
-/**
- * Comment
- *
- * @author Ben Wang
- * @version $Revision$
- */
-public interface NestedStateful extends Removable
-{
-   int increment();   
-   void reset(); 
-
-   int getPostActivate();
-   int getPrePassivate();
-}

Deleted: branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/stateful/nested/NestedStatefulBean.java
===================================================================
--- branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/stateful/nested/NestedStatefulBean.java	2007-02-19 09:08:42 UTC (rev 60657)
+++ branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/stateful/nested/NestedStatefulBean.java	2007-02-19 09:12:25 UTC (rev 60658)
@@ -1,68 +0,0 @@
-/*
- * 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.PostActivate;
-import javax.ejb.PrePassivate;
-import javax.ejb.Remote;
-import javax.ejb.Stateful;
-
-import org.jboss.annotation.ejb.cache.simple.CacheConfig;
-
-/**
- * Nested SFSB with a remote interface
- *
- * @author Ben Wang
- * @author Brian Stansberry
- * 
- * @version $Revision$
- */
- at Stateful(name="testNestedStateful")
- 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
-{
-   /** 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;
-   }
-}

Deleted: branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/stateful/nested/ParentStatefulBean.java
===================================================================
--- branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/stateful/nested/ParentStatefulBean.java	2007-02-19 09:08:42 UTC (rev 60657)
+++ branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/stateful/nested/ParentStatefulBean.java	2007-02-19 09:12:25 UTC (rev 60658)
@@ -1,133 +0,0 @@
-/*
- * 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 org.jboss.annotation.ejb.cache.simple.CacheConfig;
-import org.jboss.logging.Logger;
-
-import javax.ejb.*;
-import javax.annotation.PostConstruct;
-import javax.ejb.EJB;
-
-/**
- * Parent SFSB that contains nested SFSB
- *
- * @author Ben Wang
- * @version $Revision$
- */
- at Stateful(name="testParentStateful")
- at CacheConfig(maxSize=1000, idleTimeoutSeconds=1)   // this will get evicted the second time eviction thread wakes up
- at Remote(ParentStatefulRemote.class)
-public class ParentStatefulBean implements java.io.Serializable, ParentStatefulRemote
-{
-   /** The serialVersionUID */
-   private static final long serialVersionUID = 1L;
-   
-   private Logger log = Logger.getLogger(ParentStatefulBean.class);
-   private int counter = 0;
-   private int localCounter = 0;
-   
-   @EJB(beanName="testNestedStateful")
-   private NestedStateful nested;
-
-   @EJB(beanName="testLocalNestedStateful")
-   private NestedStateful localNested;
-
-   public int increment()
-   {
-      counter = nested.increment();
-
-      log.debug("INCREMENT - counter: " + counter);
-      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;
-
-   /**
-    * Sleep to test
-    * @throws Exception
-    */
-   public void longRunning() throws Exception
-   {
-      log.debug("+++ longRunning() enter ");
-      Thread.sleep(10000);
-      log.debug("+++ longRunning() leave ");
-   }
-   
-   public NestedStateful getNested()
-   {
-      return nested;
-   }
-
-   public int getPostActivate()
-   {
-      return ParentStatefulBean.postActivateCalled;
-   }
-
-   public int getPrePassivate()
-   {
-      return ParentStatefulBean.prePassivateCalled;
-   }
-   
-   public int getLocalNestedPostActivate()
-   {
-      return localNested.getPostActivate();
-   }
-
-   public int getLocalNestedPrePassivate()
-   {
-      return localNested.getPrePassivate();
-   }
-
-   public void reset()
-   {
-      log.debug("Being reset");
-      counter = 0;
-      postActivateCalled = 0;
-      prePassivateCalled = 0;
-      nested.reset();
-      localNested.reset();
-   }
-
-   @PostActivate
-   public void postActivate()
-   {
-      ++ParentStatefulBean.postActivateCalled;
-      log.debug("Activate with counter: " + counter);
-   }
-
-   @PrePassivate
-   public void prePassivate()
-   {
-      ++ParentStatefulBean.prePassivateCalled;
-      log.debug("Passivate with counter: " + counter);
-   }
-
-   @Remove
-   public void remove()
-   {
-      log.debug("Being removed");
-   }
-
-   @PostConstruct
-   public void ejbCreate()
-   {
-   }
-
-   // Remote Interface implementation ----------------------------------------------
-
-}

Deleted: branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/stateful/nested/ParentStatefulRemote.java
===================================================================
--- branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/stateful/nested/ParentStatefulRemote.java	2007-02-19 09:08:42 UTC (rev 60657)
+++ branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/stateful/nested/ParentStatefulRemote.java	2007-02-19 09:12:25 UTC (rev 60658)
@@ -1,36 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- *
- * Distributable under LGPL license.
- * See terms of license at gnu.org.
- */
-
-package org.jboss.ejb3.test.stateful.nested;
-
-/**
- * Parent sfsb interface
- *
- * @author Ben Wang
- * @author Brian Stansberry
- * @version $Revision$
- */
-public interface ParentStatefulRemote extends Removable
-{
-   int increment();
-
-   int incrementLocal();
-   
-   int getPostActivate();
-
-   int getPrePassivate();
-
-   void reset();
-
-   void longRunning() throws Exception;
-
-   NestedStateful getNested();
-
-   int getLocalNestedPostActivate();
-
-   int getLocalNestedPrePassivate();
-}

Deleted: branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/stateful/nested/Removable.java
===================================================================
--- branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/stateful/nested/Removable.java	2007-02-19 09:08:42 UTC (rev 60657)
+++ branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/stateful/nested/Removable.java	2007-02-19 09:12:25 UTC (rev 60658)
@@ -1,34 +0,0 @@
-/*
- * 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();
-}

Copied: branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/stateful/nested/SimpleContainedBean.java (from rev 60635, trunk/ejb3/src/test/org/jboss/ejb3/test/stateful/nested/SimpleContainedBean.java)
===================================================================
--- branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/stateful/nested/SimpleContainedBean.java	                        (rev 0)
+++ branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/stateful/nested/SimpleContainedBean.java	2007-02-19 09:12:25 UTC (rev 60658)
@@ -0,0 +1,45 @@
+/*
+ * 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;
+
+import javax.ejb.Remote;
+import javax.ejb.Stateful;
+
+import org.jboss.annotation.ejb.cache.simple.CacheConfig;
+import org.jboss.ejb3.test.stateful.nested.base.xpc.Contained;
+import org.jboss.ejb3.test.stateful.nested.base.xpc.ContainedBean;
+
+/**
+ * ContainedBean bean meant for testing with a non-clustered SFSB cache.
+ * 
+ * @author <a href="brian.stansberry at jboss.com">Brian Stansberry</a>
+ * @version $Revision: 1.1 $
+ */
+ at Stateful(name="testShoppingCartContained")
+ at CacheConfig(maxSize = 1000, idleTimeoutSeconds = 1)
+ at Remote(Contained.class)
+public class SimpleContainedBean extends ContainedBean
+{
+   /** The serialVersionUID */
+   private static final long serialVersionUID = 1L;
+}

Copied: branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/stateful/nested/SimpleDeepNestedContainedBean.java (from rev 60635, trunk/ejb3/src/test/org/jboss/ejb3/test/stateful/nested/SimpleDeepNestedContainedBean.java)
===================================================================
--- branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/stateful/nested/SimpleDeepNestedContainedBean.java	                        (rev 0)
+++ branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/stateful/nested/SimpleDeepNestedContainedBean.java	2007-02-19 09:12:25 UTC (rev 60658)
@@ -0,0 +1,45 @@
+/*
+ * 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;
+
+import javax.ejb.Local;
+import javax.ejb.Stateful;
+
+import org.jboss.annotation.ejb.cache.simple.CacheConfig;
+import org.jboss.ejb3.test.stateful.nested.base.xpc.DeepNestedContained;
+import org.jboss.ejb3.test.stateful.nested.base.xpc.DeepNestedContainedBean;
+
+/**
+ * A SimpleDeepNestedStatefulBean.
+ * 
+ * @author <a href="brian.stansberry at jboss.com">Brian Stansberry</a>
+ * @version $Revision: 1.1 $
+ */
+ at Stateful(name="testDeepNestedContained")
+ at CacheConfig(maxSize=10000, idleTimeoutSeconds=1) 
+ at Local(DeepNestedContained.class)
+public class SimpleDeepNestedContainedBean extends DeepNestedContainedBean
+{
+   /** The serialVersionUID */
+   private static final long serialVersionUID = 1L;
+}

Copied: branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/stateful/nested/SimpleDeepNestedStatefulBean.java (from rev 60635, trunk/ejb3/src/test/org/jboss/ejb3/test/stateful/nested/SimpleDeepNestedStatefulBean.java)
===================================================================
--- branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/stateful/nested/SimpleDeepNestedStatefulBean.java	                        (rev 0)
+++ branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/stateful/nested/SimpleDeepNestedStatefulBean.java	2007-02-19 09:12:25 UTC (rev 60658)
@@ -0,0 +1,45 @@
+/*
+ * 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;
+
+import javax.ejb.Local;
+import javax.ejb.Stateful;
+
+import org.jboss.annotation.ejb.cache.simple.CacheConfig;
+import org.jboss.ejb3.test.stateful.nested.base.DeepNestedStateful;
+import org.jboss.ejb3.test.stateful.nested.base.DeepNestedStatefulBean;
+
+/**
+ * A SimpleDeepNestedStatefulBean.
+ * 
+ * @author <a href="brian.stansberry at jboss.com">Brian Stansberry</a>
+ * @version $Revision: 1.1 $
+ */
+ at Stateful(name="testDeepNestedStateful")
+ at CacheConfig(maxSize=10000, idleTimeoutSeconds=1) 
+ at Local(DeepNestedStateful.class)
+public class SimpleDeepNestedStatefulBean extends DeepNestedStatefulBean
+{
+   /** The serialVersionUID */
+   private static final long serialVersionUID = 1L;
+}

Copied: branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/stateful/nested/SimpleLocalContainedBean.java (from rev 60635, trunk/ejb3/src/test/org/jboss/ejb3/test/stateful/nested/SimpleLocalContainedBean.java)
===================================================================
--- branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/stateful/nested/SimpleLocalContainedBean.java	                        (rev 0)
+++ branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/stateful/nested/SimpleLocalContainedBean.java	2007-02-19 09:12:25 UTC (rev 60658)
@@ -0,0 +1,45 @@
+/*
+ * 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;
+
+import javax.ejb.Local;
+import javax.ejb.Stateful;
+
+import org.jboss.annotation.ejb.cache.simple.CacheConfig;
+import org.jboss.ejb3.test.stateful.nested.base.xpc.Contained;
+import org.jboss.ejb3.test.stateful.nested.base.xpc.ContainedBean;
+
+/**
+ * ContainedBean bean meant for testing with a non-clustered SFSB cache.
+ * 
+ * @author <a href="brian.stansberry at jboss.com">Brian Stansberry</a>
+ * @version $Revision: 1.1 $
+ */
+ at Stateful(name="testLocalShoppingCartContained")
+ at CacheConfig(maxSize = 1000, idleTimeoutSeconds = 1)
+ at Local(Contained.class)
+public class SimpleLocalContainedBean extends ContainedBean
+{
+   /** The serialVersionUID */
+   private static final long serialVersionUID = 1L;
+}

Copied: branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/stateful/nested/SimpleLocalNestedStatefulBean.java (from rev 60635, trunk/ejb3/src/test/org/jboss/ejb3/test/stateful/nested/SimpleLocalNestedStatefulBean.java)
===================================================================
--- branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/stateful/nested/SimpleLocalNestedStatefulBean.java	                        (rev 0)
+++ branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/stateful/nested/SimpleLocalNestedStatefulBean.java	2007-02-19 09:12:25 UTC (rev 60658)
@@ -0,0 +1,32 @@
+/*
+ * 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.Stateful;
+
+import org.jboss.annotation.ejb.cache.simple.CacheConfig;
+import org.jboss.ejb3.test.stateful.nested.base.std.NestedStateful;
+import org.jboss.ejb3.test.stateful.nested.base.std.NestedStatefulBean;
+
+/**
+ * Nested SFSB with only a local interface.
+ *
+ * @author Ben Wang
+ * @author Brian Stansberry
+ * 
+ * @version $Revision: 45372 $
+ */
+ at Stateful(name="testLocalNestedStateful")
+ at CacheConfig(maxSize=10000, idleTimeoutSeconds=1) 
+ at Local(NestedStateful.class)
+public class SimpleLocalNestedStatefulBean extends NestedStatefulBean
+{
+   /** The serialVersionUID */
+   private static final long serialVersionUID = 1L;
+}

Copied: branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/stateful/nested/SimpleParentStatefulBean.java (from rev 60635, trunk/ejb3/src/test/org/jboss/ejb3/test/stateful/nested/SimpleParentStatefulBean.java)
===================================================================
--- branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/stateful/nested/SimpleParentStatefulBean.java	                        (rev 0)
+++ branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/stateful/nested/SimpleParentStatefulBean.java	2007-02-19 09:12:25 UTC (rev 60658)
@@ -0,0 +1,31 @@
+/*
+ * 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.Remote;
+import javax.ejb.Stateful;
+
+import org.jboss.annotation.ejb.cache.simple.CacheConfig;
+import org.jboss.ejb3.test.stateful.nested.base.std.ParentStatefulBean;
+import org.jboss.ejb3.test.stateful.nested.base.std.ParentStatefulRemote;
+
+/**
+ * Parent SFSB that contains nested SFSB.
+ *
+ * @author Ben Wang
+ * @author Brian Stansberry
+ * @version $Revision$
+ */
+ at Stateful(name="testParentStateful")
+ at CacheConfig(maxSize=1000, idleTimeoutSeconds=1)   // this will get evicted the second time eviction thread wakes up
+ at Remote(ParentStatefulRemote.class)
+public class SimpleParentStatefulBean extends ParentStatefulBean
+{
+   /** The serialVersionUID */
+   private static final long serialVersionUID = 1L;
+}

Copied: branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/stateful/nested/SimpleRemoteNestedStatefulBean.java (from rev 60635, trunk/ejb3/src/test/org/jboss/ejb3/test/stateful/nested/SimpleRemoteNestedStatefulBean.java)
===================================================================
--- branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/stateful/nested/SimpleRemoteNestedStatefulBean.java	                        (rev 0)
+++ branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/stateful/nested/SimpleRemoteNestedStatefulBean.java	2007-02-19 09:12:25 UTC (rev 60658)
@@ -0,0 +1,32 @@
+/*
+ * 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.Remote;
+import javax.ejb.Stateful;
+
+import org.jboss.annotation.ejb.cache.simple.CacheConfig;
+import org.jboss.ejb3.test.stateful.nested.base.std.NestedStateful;
+import org.jboss.ejb3.test.stateful.nested.base.std.OptimizedNestedStatefulBean;
+
+/**
+ * Nested SFSB with a remote interface.
+ *
+ * @author Ben Wang
+ * @author Brian Stansberry
+ * 
+ * @version $Revision$
+ */
+ at Stateful(name="testNestedStateful")
+ at CacheConfig(maxSize=1000, idleTimeoutSeconds=1)
+ at Remote(NestedStateful.class)
+public class SimpleRemoteNestedStatefulBean extends OptimizedNestedStatefulBean
+{
+   /** The serialVersionUID */
+   private static final long serialVersionUID = 1L;
+}

Copied: branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/stateful/nested/SimpleShoppingCartBean.java (from rev 60635, trunk/ejb3/src/test/org/jboss/ejb3/test/stateful/nested/SimpleShoppingCartBean.java)
===================================================================
--- branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/stateful/nested/SimpleShoppingCartBean.java	                        (rev 0)
+++ branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/stateful/nested/SimpleShoppingCartBean.java	2007-02-19 09:12:25 UTC (rev 60658)
@@ -0,0 +1,45 @@
+/*
+ * 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;
+
+import javax.ejb.Remote;
+import javax.ejb.Stateful;
+
+import org.jboss.annotation.ejb.cache.simple.CacheConfig;
+import org.jboss.ejb3.test.stateful.nested.base.xpc.ShoppingCart;
+import org.jboss.ejb3.test.stateful.nested.base.xpc.ShoppingCartBean;
+
+/**
+ * ShoppingCartBean subclass for testing with a non-clustered SFSB cache.
+ * 
+ * @author <a href="brian.stansberry at jboss.com">Brian Stansberry</a>
+ * @version $Revision: 1.1 $
+ */
+ at Stateful(name="testShoppingCart")
+ at Remote(ShoppingCart.class)
+ at CacheConfig(maxSize = 1000, idleTimeoutSeconds = 1)
+public class SimpleShoppingCartBean extends ShoppingCartBean
+{
+   /** The serialVersionUID */
+   private static final long serialVersionUID = 1L;
+}

Copied: branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/stateful/nested/base (from rev 60635, trunk/ejb3/src/test/org/jboss/ejb3/test/stateful/nested/base)

Copied: branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/stateful/unit/BaseTestRunner.java (from rev 60635, trunk/ejb3/src/test/org/jboss/ejb3/test/stateful/unit/BaseTestRunner.java)
===================================================================
--- branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/stateful/unit/BaseTestRunner.java	                        (rev 0)
+++ branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/stateful/unit/BaseTestRunner.java	2007-02-19 09:12:25 UTC (rev 60658)
@@ -0,0 +1,154 @@
+/*
+ * 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.unit;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.ejb.NoSuchEJBException;
+import javax.naming.InitialContext;
+
+import org.jboss.ejb3.test.stateful.nested.base.Removable;
+import org.jboss.logging.Logger;
+
+/**
+ * Base class for test runners that can share test functionality between
+ * JBossTestCase subclasses and JBossClusteredTestCase subclasses.
+ * 
+ * @author <a href="brian.stansberry at jboss.com">Brian Stansberry</a>
+ * @version $Revision: 1.1 $
+ */
+public class BaseTestRunner
+{
+   protected InitialContext initialContext;
+   protected Set<Removable> removables = new HashSet<Removable>();
+   
+   private Logger log;
+   private long sleepTime = 11100L;
+   private int passivationPerInvocation = 0;
+   private int passivationPerSleep = 1;
+   
+   public BaseTestRunner(InitialContext context, Logger log)
+   {
+      this.initialContext = context;
+      this.log = log;
+   }
+
+   public void setUp() throws Exception
+   {      
+   }
+
+   public void tearDown() throws Exception
+   {
+      // 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();
+   }
+
+   protected InitialContext getInitialContext()
+   {
+      return initialContext;
+   }
+   
+   protected Logger getLog()
+   {
+      return log;
+   }
+
+   public long getSleepTime()
+   {
+      return sleepTime;
+   }
+
+   public void setSleepTime(long sleepTime)
+   {
+      this.sleepTime = sleepTime;
+   }
+
+   public void sleep(long time)
+   {
+      try {
+         Thread.sleep(time);
+      } catch (InterruptedException e) {
+         e.printStackTrace();
+      }
+   }
+   
+   public void sleep()
+   {
+      sleep(getSleepTime());
+   }
+
+   public int getPassivationPerInvocation()
+   {
+      return passivationPerInvocation;
+   }
+
+   public void setPassivationPerInvocation(int passivationPerInvocation)
+   {
+      this.passivationPerInvocation = passivationPerInvocation;
+   }
+
+   public int getPassivationPerSleep()
+   {
+      return passivationPerSleep;
+   }
+
+   public void setPassivationPerSleep(int passivationPerSleep)
+   {
+      this.passivationPerSleep = passivationPerSleep;
+   }
+   
+   public int getExpectedPassivations(int sleepCycles, int invocations)
+   {
+      return (sleepCycles * passivationPerSleep) + 
+             (invocations * passivationPerInvocation);
+   }
+   
+   public void addRemovable(Removable bean)
+   {
+      removables.add(bean);
+   }
+
+   public void removeBean(Removable bean)
+   {
+      try
+      {
+         bean.remove();
+      }
+      catch (NoSuchEJBException ignored) 
+      {
+         // this is OK; it was already removed
+      }
+      removables.remove(bean);
+   }
+
+}
\ No newline at end of file

Copied: branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/stateful/unit/ExtendedPersistenceUnitTestCase.java (from rev 60635, trunk/ejb3/src/test/org/jboss/ejb3/test/stateful/unit/ExtendedPersistenceUnitTestCase.java)
===================================================================
--- branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/stateful/unit/ExtendedPersistenceUnitTestCase.java	                        (rev 0)
+++ branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/stateful/unit/ExtendedPersistenceUnitTestCase.java	2007-02-19 09:12:25 UTC (rev 60658)
@@ -0,0 +1,108 @@
+/*
+  * 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.stateful.unit;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.jboss.ejb3.test.clusteredentity.unit.DBSetup;
+import org.jboss.logging.Logger;
+import org.jboss.test.JBossTestCase;
+
+/**
+ * Tests for ExtendedPersistenceContext management.
+ * 
+ * This class uses a delegate to execute the tests so the clustered
+ * version of the tests (which derive from a different base class)
+ * can use the same delegate code.
+ *
+ * @author Ben Wang
+ * @version $Id$
+ */
+public class ExtendedPersistenceUnitTestCase extends JBossTestCase
+{
+   private static final Logger log = Logger.getLogger(ExtendedPersistenceUnitTestCase.class);
+   
+   private XPCTestRunner runner;
+   
+   public ExtendedPersistenceUnitTestCase(String name)
+   {
+      super(name);
+   }
+
+   public static Test suite() throws Exception
+   {
+      TestSuite suite = new TestSuite();
+      Test t1 = getDeploySetup(ExtendedPersistenceUnitTestCase.class,
+                               "stateful-test.jar");
+
+      suite.addTest(t1);
+
+      // Create an initializer for the test suite
+      DBSetup wrapper = new DBSetup(suite);
+      return wrapper;     
+   }
+
+   
+   @Override
+   protected void setUp() throws Exception
+   {
+      super.setUp();
+      
+      runner = new XPCTestRunner(getInitialContext(), log);
+      runner.setUp();
+      // Use a sleep time just a bit longer than twice the bean timeout
+      runner.setSleepTime(2100L);
+   }
+
+
+   @Override
+   protected void tearDown() throws Exception
+   {
+      super.tearDown();
+      
+      if (runner != null)
+         runner.tearDown();
+   }
+
+
+   public void testBasic() throws Exception
+   {
+      runner.testBasic();
+   }
+   
+   public void testDependentLifecycle() throws Exception
+   {
+      runner.testDependentLifecycle();
+   }
+   
+   public void testXPCSharing() throws Exception
+   {
+      runner.testXPCSharing();
+   }
+
+   public void testPassivation() throws Exception
+   {
+      runner.testPassivation();
+   }
+
+}

Copied: branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/stateful/unit/NestedBeanTestRunner.java (from rev 60635, trunk/ejb3/src/test/org/jboss/ejb3/test/stateful/unit/NestedBeanTestRunner.java)
===================================================================
--- branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/stateful/unit/NestedBeanTestRunner.java	                        (rev 0)
+++ branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/stateful/unit/NestedBeanTestRunner.java	2007-02-19 09:12:25 UTC (rev 60658)
@@ -0,0 +1,355 @@
+/*
+ * 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.unit;
+
+import java.rmi.dgc.VMID;
+
+import javax.naming.InitialContext;
+
+import junit.framework.Assert;
+
+import org.jboss.ejb3.test.stateful.nested.base.std.NestedBeanMonitor;
+import org.jboss.ejb3.test.stateful.nested.base.std.NestedStateful;
+import org.jboss.ejb3.test.stateful.nested.base.std.ParentStatefulRemote;
+import org.jboss.logging.Logger;
+
+/**
+ * Encapsulates the functions needed for tests of nested SFSBs in
+ * a class that can be used either by a JBossTestCase subclass or
+ * a JBossClusteredTestCase subclass.
+ * 
+ * @author <a href="brian.stansberry at jboss.com">Brian Stansberry</a>
+ * @version $Revision: 1.1 $
+ */
+public class NestedBeanTestRunner extends BaseTestRunner
+{
+   public NestedBeanTestRunner(InitialContext context, Logger log)
+   {
+      super(context, log);
+   }
+   
+   
+   public void testBasic()
+   throws Exception
+   {
+      getLog().debug("Running testBasic()");
+      getLog().debug("==================================");
+      
+      NestedBeanSet beanSet = getNestedBeanSet();
+      ParentStatefulRemote stateful = beanSet.parent;
+      
+      Assert.assertEquals("Remote counter: ", 1, stateful.increment());
+      Assert.assertEquals("Remote counter: ", 2, stateful.increment());
+      Assert.assertEquals("Local counter: ", 1, stateful.incrementLocal());
+      Assert.assertEquals("Local counter: ", 2, stateful.incrementLocal());
+      
+      removeBean(stateful);
+      
+      getLog().debug("ok");
+   }
+   
+   public void testDependentLifecycle()
+   throws Exception
+   {
+      getLog().debug("Running testDependentLifecycle()");
+      getLog().debug("==================================");
+      
+      NestedBeanSet beanSet = getNestedBeanSet();
+      ParentStatefulRemote parent = beanSet.parent;
+      NestedStateful nested = beanSet.nested;
+      NestedBeanMonitor monitor = beanSet.monitor;
+      
+      Assert.assertEquals("Remote counter (via parent): ", 1, parent.increment());  
+      
+      String deepId = monitor.getDeepNestedId();
+      Assert.assertNotNull("Got a deepId", deepId);
+      Assert.assertFalse("Got a non-ERROR deepId", "ERROR".equals(deepId));
+      String localDeepId = monitor.getLocalDeepNestedId();
+      Assert.assertNotNull("Got a localDeepId", localDeepId);
+      Assert.assertFalse("Got a non-ERROR localDeepId", "ERROR".equals(localDeepId));
+       
+      removeBean(parent);
+       
+      // Confirm parent is dead
+      Assert.assertEquals("Remote counter (via dead parent): ", -1, monitor.incrementParent());
+      Assert.assertFalse("parent.remove() fails", monitor.removeParent());
+      
+      // Confirm nested beans still work following parent remove
+      Assert.assertEquals("Remote counter (direct):", 2 ,nested.increment());      
+      Assert.assertEquals("Local counter (monitor):", 1 , monitor.incrementLocalNested());
+      Assert.assertEquals("Deep nested id", deepId, monitor.getDeepNestedId());
+      Assert.assertEquals("Local deep nested id", localDeepId, monitor.getLocalDeepNestedId());
+      
+      // Remove the bottom tier
+      Assert.assertTrue("Local deep nested removed", monitor.removeLocalDeepNested());
+      
+      // Confirm it is dead
+      Assert.assertEquals("Local deep nested removed", "ERROR", monitor.getLocalDeepNestedId());
+      Assert.assertFalse("localDeepNested.remove() fails", monitor.removeLocalDeepNested());
+      
+      // Confirm other beans still work following parent remove
+      Assert.assertEquals("Remote counter (direct):", 3 ,nested.increment());      
+      Assert.assertEquals("Local counter (monitor):", 2 , monitor.incrementLocalNested());
+      Assert.assertEquals("Deep nested id", deepId, monitor.getDeepNestedId());
+      
+      // Remove the nested bean
+      removeBean(nested);
+      
+      Assert.assertEquals("Remote counter (via monitor): ", -1, monitor.incrementNested());
+      Assert.assertFalse("nested.remove() fails", monitor.removeNested());
+      
+      // Confirm other beans still work
+      Assert.assertEquals("Local counter (monitor):", 3 , monitor.incrementLocalNested());
+      Assert.assertEquals("Deep nested id", deepId, monitor.getDeepNestedId());
+      
+      // Remove the local nested bean
+      Assert.assertTrue("Local nested removed", monitor.removeLocalNested());
+      
+      // Confirm it is dead
+      Assert.assertEquals("Local nested removed", -1, monitor.incrementLocalNested());
+      Assert.assertFalse("localNested.remove() fails", monitor.removeLocalNested());
+      
+      // Confirm other beans still work following parent remove
+      Assert.assertEquals("Deep nested id", deepId, monitor.getDeepNestedId());
+      
+      // Remove the deep nested bean
+      Assert.assertTrue("Deep removed", monitor.removeDeepNested());
+      
+      // Confirm it is dead
+      Assert.assertEquals("Local nested removed", "ERROR", monitor.getDeepNestedId());
+      Assert.assertFalse("deepNested.remove() fails", monitor.removeDeepNested());
+      
+      removeBean(monitor);
+      
+      getLog().debug("ok");
+      
+   }
+
+   public void testStatefulPassivation()
+   throws Exception
+   {
+      getLog().debug("Running testStatefulPassivation()");
+      getLog().debug("==================================");
+      
+      NestedBeanSet beanSet = getNestedBeanSet();
+      NestedBeanMonitor monitor = beanSet.monitor;
+      ParentStatefulRemote parent = beanSet.parent;
+      NestedStateful nested = beanSet.nested;
+      
+      int parentInv = beanSet.parentInvocations;
+      int nestedInv = beanSet.nestedInvocations;
+
+      Assert.assertEquals("Remote counter: ", 1, parent.increment());
+      parentInv++;
+      nestedInv++;
+      Assert.assertEquals("Remote counter: ", 2, parent.increment());
+      parentInv++;
+      nestedInv++;
+      Assert.assertEquals("Local counter: ", 1, parent.incrementLocal());
+      parentInv++;
+      Assert.assertEquals("Local counter: ", 2, parent.incrementLocal());
+      parentInv++;
+      
+      sleep(getSleepTime());  // should passivate
+
+      Assert.assertEquals("Parent passivate count: ",
+                          getExpectedPassivations(1, parentInv), 
+                          parent.getPrePassivate());
+      parentInv++;
+      Assert.assertEquals("Parent activate count: ",
+                          getExpectedPassivations(1, parentInv), 
+                          parent.getPostActivate());
+      parentInv++;
+      Assert.assertEquals("Remote nested passivate count: ",
+                          getExpectedPassivations(1, nestedInv), 
+                          nested.getPrePassivate());
+      Assert.assertEquals("Remote nested activate count: ",
+                          getExpectedPassivations(1, nestedInv), 
+                          nested.getPostActivate());
+      Assert.assertEquals("Local nested passivate count: ",
+                          getExpectedPassivations(1, parentInv), 
+                          parent.getLocalNestedPrePassivate());
+      parentInv++;
+      Assert.assertEquals("Local nested activate count: ",
+                          getExpectedPassivations(1, parentInv), 
+                          parent.getLocalNestedPostActivate());
+      parentInv++;
+      
+      // Use the monitor to check the deep nested beans.  In a cluster these
+      // are marked not to treat replication as passivation, so we ignore 
+      // the number of invocations
+      Assert.assertEquals("Deep nested passivate count: ", 1, monitor.getDeepNestedPassivations());
+      nestedInv++;
+      Assert.assertEquals("Deep nested activate count: ", 1, monitor.getDeepNestedActivations());
+      nestedInv++;
+      Assert.assertEquals("Local deep nested passivate count: ", 1, monitor.getLocalDeepNestedPassivations());
+      parentInv++;
+      Assert.assertEquals("Local deep nested activate count: ", 1, monitor.getLocalDeepNestedActivations());
+      parentInv++;
+      
+      Assert.assertEquals("Remote counter: ", 3, parent.increment());
+      parentInv++;
+      nestedInv++;
+      Assert.assertEquals("Remote counter: ", 4, parent.increment());
+      parentInv++;
+      nestedInv++;
+      Assert.assertEquals("Local counter: ", 3, parent.incrementLocal());
+      parentInv++;
+      Assert.assertEquals("Local counter: ", 4, parent.incrementLocal());  
+      parentInv++;    
+      
+      sleep(getSleepTime());  // should passivate
+
+      Assert.assertEquals("Parent passivate count: ",
+                          getExpectedPassivations(2, parentInv), 
+                          parent.getPrePassivate());
+      parentInv++;
+      Assert.assertEquals("Parent activate count: ",
+                          getExpectedPassivations(2, parentInv), 
+                          parent.getPostActivate());
+      parentInv++;
+      Assert.assertEquals("Remote nested passivate count: ",
+                          getExpectedPassivations(2, nestedInv), 
+                          nested.getPrePassivate());
+      Assert.assertEquals("Remote nested activate count: ",
+                          getExpectedPassivations(2, nestedInv), 
+                          nested.getPostActivate());
+      Assert.assertEquals("Local nested passivate count: ",
+                          getExpectedPassivations(2, parentInv), 
+                          parent.getLocalNestedPrePassivate());
+      parentInv++;
+      Assert.assertEquals("Local nested activate count: ",
+                          getExpectedPassivations(2, parentInv), 
+                          parent.getLocalNestedPostActivate());
+      parentInv++;
+      
+      // Use the monitor to check the deep nested beans.
+      Assert.assertEquals("Deep nested passivate count: ", 2, monitor.getDeepNestedPassivations());
+      nestedInv++;
+      Assert.assertEquals("Deep nested activate count: ", 2, monitor.getDeepNestedActivations());
+      nestedInv++;
+      Assert.assertEquals("Local deep nested passivate count: ", 2, monitor.getLocalDeepNestedPassivations());
+      parentInv++;
+      Assert.assertEquals("Local deep nested activate count: ", 2, monitor.getLocalDeepNestedActivations());
+      parentInv++;
+      
+      Assert.assertEquals("Remote counter: ", 5, parent.increment());
+      parentInv++;
+      nestedInv++;
+      Assert.assertEquals("Remote counter: ", 6, parent.increment());
+      parentInv++;
+      nestedInv++;
+      Assert.assertEquals("Local counter: ", 5, parent.incrementLocal());
+      parentInv++;
+      Assert.assertEquals("Local counter: ", 6, parent.incrementLocal());
+      parentInv++;
+      
+      removeBean(parent);
+      
+      // Force the nested bean to go through another passivation
+      // to check the activation process can survive the removal 
+      // of its parent
+      sleep(getSleepTime());
+      
+      // Confirm nested still works following parent remove
+      Assert.assertEquals("Remote counter (direct): ", 7, nested.increment());
+      nestedInv++;
+      Assert.assertEquals("Remote nested passivate count: ",
+                          getExpectedPassivations(3, nestedInv), 
+                          nested.getPrePassivate());
+      Assert.assertEquals("Remote nested activate count: ",
+                          getExpectedPassivations(3, nestedInv), 
+                          nested.getPostActivate());
+      
+      removeBean(nested);
+      
+      getLog().debug("ok");
+   }
+   
+   public NestedBeanSet getNestedBeanSet()
+   throws Exception
+   {
+      // We want a colocated monitor and SFSB to test passivation/destruction
+      // StatelessRemoteBean is not clustered, so once we have it's VMID
+      // we can keep creating SFSBs until we get one we want
+      getLog().debug("Looking up NestedBeanMonitorBean...");
+      NestedBeanMonitor monitor = (NestedBeanMonitor) getInitialContext().lookup("NestedBeanMonitorBean/remote");
+      VMID monitorVM = monitor.getVMID();
+      addRemovable(monitor);
+      
+      int parentInv = 0;
+      int nestedInv = 0;
+      
+      ParentStatefulRemote parent = null;      
+      boolean vmMatch = false;
+      for (int i = 0; i < 20 && !vmMatch; i++)
+      {
+         getLog().debug("Looking up testParentStateful... Attempt " + (i + 1));
+         parent = (ParentStatefulRemote) initialContext.lookup("testParentStateful/remote");
+         
+         vmMatch = monitorVM.equals(parent.getVMID());
+         addRemovable(parent);
+         if (!vmMatch)
+         {
+            removeBean(parent);
+         }
+      }
+      
+      Assert.assertTrue("Monitor and SFSB in same VM", vmMatch);
+      
+      // Reset the parent to initialize all the beans
+      parent.reset();
+      
+      // Monitor the parent
+      monitor.monitor(parent);
+      
+      // Reset the parent to clean things up
+      parent.reset();
+      parentInv++;
+      nestedInv++;
+      
+      NestedStateful nested = (NestedStateful) parent.getNested();
+      parentInv++;
+      addRemovable(nested);
+      
+      NestedBeanSet result = new NestedBeanSet();
+      result.monitor = monitor;
+      result.parent = parent;
+      result.nested = nested;
+      result.parentInvocations = parentInv;
+      result.nestedInvocations = nestedInv;
+      
+      return result;
+   }
+   
+   
+
+   public static class NestedBeanSet
+   {
+      public NestedBeanMonitor monitor;
+      public ParentStatefulRemote parent;
+      public NestedStateful nested;
+      public int parentInvocations = 0;
+      public int nestedInvocations = 0;
+   }
+   
+}

Modified: branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/stateful/unit/NestedBeanUnitTestCase.java
===================================================================
--- branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/stateful/unit/NestedBeanUnitTestCase.java	2007-02-19 09:08:42 UTC (rev 60657)
+++ branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/stateful/unit/NestedBeanUnitTestCase.java	2007-02-19 09:12:25 UTC (rev 60658)
@@ -7,19 +7,11 @@
 
 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;
 
+import org.jboss.logging.Logger;
+import org.jboss.test.JBossTestCase;
+
 /**
  * Test nested SFSB for repeated passivation
  *
@@ -28,17 +20,8 @@
  */
 public class NestedBeanUnitTestCase extends JBossTestCase
 {
-   static boolean deployed = false;
-   public static int test = 0;
-   static Date startDate = new Date();
-
-   protected final String namingFactory =
-   System.getProperty(Context.INITIAL_CONTEXT_FACTORY);
-
-   protected final String providerURL =
-   System.getProperty(Context.PROVIDER_URL);
-
-   private Set<Removable> removables = new HashSet<Removable>();
+   private static final Logger log = Logger.getLogger(NestedBeanUnitTestCase.class);
+   private NestedBeanTestRunner runner;
    
    public NestedBeanUnitTestCase (String name)
    {
@@ -52,207 +35,40 @@
    
    
    @Override
+   protected void setUp() throws Exception
+   {
+      super.setUp();
+      
+      runner = new NestedBeanTestRunner(getInitialContext(), log);
+      runner.setUp();
+      // Use a sleep time just a bit longer than twice the bean timeout
+      runner.setSleepTime(2100L);
+   }
+
+   @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();
+      if (runner != null)
+         runner.tearDown();
    }
 
    public void testBasic()
    throws Exception
    {
-      getLog().debug("Running testBasic()");
-      getLog().debug("==================================");
-      
-      NestedBeanSet beanSet = getNestedBeanSet();
-      ParentStatefulRemote stateful = beanSet.parent;
-      
-      assertEquals("Counter: ", 1, stateful.increment());
-      assertEquals("Counter: ", 2, stateful.increment());
-      assertEquals("Counter: ", 1, stateful.incrementLocal());
-      assertEquals("Counter: ", 2, stateful.incrementLocal());
-      
-      removeBean(stateful);
-      
-      getLog().debug("ok");
+      runner.testBasic();
    }
    
    public void testDependentLifecycle()
    throws Exception
    {
-      getLog().debug("Running testDependentLifecycle()");
-      getLog().debug("==================================");
-      
-      NestedBeanSet beanSet = getNestedBeanSet();
-      ParentStatefulRemote stateful = beanSet.parent;
-      
-      assertEquals("Counter: ", 1, stateful.increment());
-       
-      NestedStateful nested = beanSet.nested;
-       
-      removeBean(stateful);
-       
-      // Confirm nested still works following parent remove
-      assertEquals("Counter: :", 2 ,nested.increment());
-       
-      removeBean(nested);
-       
-      getLog().debug("ok");
-      
+      runner.testDependentLifecycle();      
    }
 
    public void testStatefulPassivation()
    throws Exception
    {
-      getLog().debug("Running testStatefulPassivation()");
-      getLog().debug("==================================");
-      
-      NestedBeanSet beanSet = getNestedBeanSet();
-      ParentStatefulRemote stateful = beanSet.parent;
-      
-      assertEquals("Counter: ", 1, stateful.increment());
-      assertEquals("Counter: ", 2, stateful.increment());
-      assertEquals("Counter: ", 1, stateful.incrementLocal());
-      assertEquals("Counter: ", 2, stateful.incrementLocal());
-      
-      NestedStateful nested = beanSet.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("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");
+      runner.testStatefulPassivation();
    }
-
-   public void testStatefulRepeatedPassivation()
-   throws Exception
-   {
-      getLog().debug("Running testStatefulRepeatedPassivation()");
-      getLog().debug("=========================================");
-      
-      NestedBeanSet beanSet = getNestedBeanSet();
-      ParentStatefulRemote stateful = beanSet.parent;
-      NestedStateful nested = beanSet.nested;
-
-      assertEquals("Counter: ", 1, stateful.increment());
-      assertEquals("Counter: ", 2, stateful.increment());
-      assertEquals("Counter: ", 1, stateful.incrementLocal());
-      assertEquals("Counter: ", 2, stateful.incrementLocal());
-      
-      _sleep(10000);  // 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("Counter: ", 3, stateful.incrementLocal());
-      assertEquals("Counter: ", 4, stateful.incrementLocal());      
-      
-      _sleep(10000);  // should passivate
-
-      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("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");
-   }
-   
-   protected NestedBeanSet getNestedBeanSet()
-   throws Exception
-   {
-      getLog().debug(++NestedBeanUnitTestCase.test +"- "+"Trying the context...");
-
-      InitialContext ctx = getInitialContext();
-
-      getLog().debug(++NestedBeanUnitTestCase.test +"- "
-              +"Looking up testParentStateful...");
-      ParentStatefulRemote parent = (ParentStatefulRemote) ctx.lookup("testParentStateful/remote");
-      removables.add(parent); 
-      
-      // Reset the parent to clean things up
-      parent.reset();     
-      
-      NestedStateful nested = parent.getNested(); 
-      removables.add(nested);
-      
-      NestedBeanSet result = new NestedBeanSet();
-      result.parent = parent;
-      result.nested = nested;
-      
-      return result;
-   }
-
-   protected void _sleep(long time)
-   {
-      try {
-         Thread.sleep(time);
-      } catch (InterruptedException e) {
-         e.printStackTrace();
-      }
-   }
-   
-   private void removeBean(Removable bean)
-   {
-      bean.remove();
-      removables.remove(bean);
-   }
-   
-   protected static class NestedBeanSet
-   {
-      ParentStatefulRemote parent;
-      NestedStateful nested;
-   }
 }

Copied: branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/stateful/unit/XPCTestRunner.java (from rev 60635, trunk/ejb3/src/test/org/jboss/ejb3/test/stateful/unit/XPCTestRunner.java)
===================================================================
--- branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/stateful/unit/XPCTestRunner.java	                        (rev 0)
+++ branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/stateful/unit/XPCTestRunner.java	2007-02-19 09:12:25 UTC (rev 60658)
@@ -0,0 +1,385 @@
+/*
+ * 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.unit;
+
+import java.rmi.dgc.VMID;
+
+import javax.naming.InitialContext;
+
+import junit.framework.Assert;
+
+import org.jboss.ejb3.test.stateful.nested.base.xpc.Customer;
+import org.jboss.ejb3.test.stateful.nested.base.xpc.NestedXPCMonitor;
+import org.jboss.ejb3.test.stateful.nested.base.xpc.ShoppingCart;
+import org.jboss.logging.Logger;
+
+/**
+ * Encapsulates the functions needed for tests of ExtendedPersistenceContext
+ * management by nested SFSBs in a class that can be used either by a 
+ * JBossTestCase subclass or a JBossClusteredTestCase subclass.
+ * 
+ * @author <a href="brian.stansberry at jboss.com">Brian Stansberry</a>
+ * @version $Revision: 1.1 $
+ */
+public class XPCTestRunner extends BaseTestRunner
+{
+   public XPCTestRunner(InitialContext context, Logger log)
+   {
+      super(context, log);
+   }
+
+   public void testBasic() throws Exception
+   {
+      BeanSet beanSet = getBeanSet();
+      ShoppingCart cart = beanSet.cart;
+      NestedXPCMonitor monitor = beanSet.monitor;
+      
+      Customer customer;
+
+      long id = cart.createCustomer();    
+      customer = monitor.find(id);
+      Assert.assertEquals("Stateless has proper initial name",
+                          "William", customer.getName());
+      customer = cart.find(id);
+      Assert.assertEquals("ShoppingCart has proper initial name",
+                          "William", customer.getName());
+      
+      cart.update();
+      customer = monitor.find(id);
+      Assert.assertEquals("Stateless has proper updated name",
+                           "Bill", customer.getName());
+      customer = cart.find(id);
+      Assert.assertEquals("ShoppingCart has proper updated name",
+                          "Bill", customer.getName());
+      
+      cart.update2();
+      customer = monitor.find(id);
+      Assert.assertEquals("Stateless has proper update2() name",
+                          "Billy", customer.getName());
+      customer = cart.find(id);
+      Assert.assertEquals("ShoppingCart has proper update2() name",
+                          "Billy", customer.getName());
+      
+      cart.update3();
+      customer = monitor.find(id);
+      Assert.assertEquals("Stateless has proper update3() name",
+                          "Bill Jr.", customer.getName());
+      customer = cart.find(id);
+      Assert.assertEquals("ShoppingCart has proper update3() name",
+                          "Bill Jr.", customer.getName());
+      
+      removeBean(cart);
+      removeBean(monitor);
+   }
+   
+   public void testXPCSharing() throws Exception
+   {
+      getLog().debug("Running testXPCSharing()");
+      getLog().debug("==================================");
+      
+      BeanSet beanSet = getBeanSet();
+      ShoppingCart parent = beanSet.cart;
+      NestedXPCMonitor monitor = beanSet.monitor;
+      
+      // Confirm the nested beans are there
+      String deepId = monitor.getDeepNestedId();
+      Assert.assertNotNull("Got a deepId", deepId);
+      Assert.assertFalse("Got a non-ERROR deepId", "ERROR".equals(deepId));
+      String localDeepId = monitor.getLocalDeepNestedId();
+      Assert.assertNotNull("Got a localDeepId", localDeepId);
+      Assert.assertFalse("Got a non-ERROR localDeepId", "ERROR".equals(localDeepId));
+      
+      long id = parent.createCustomer();  
+      Customer customer = parent.find(id);
+      Assert.assertNotNull("Customer created and found on parent", customer);
+      
+      parent.setContainedCustomer();
+      Assert.assertTrue("Parent and local contained share customer", parent.checkContainedCustomer());
+      
+      Assert.assertTrue("Parent and remote nested do not share ref", 
+                        monitor.compareTopToNested(id));
+      Assert.assertTrue("Parent and local nested do share ref", 
+                         monitor.compareTopToLocalNested(id));
+      Assert.assertTrue("Remote nested and local nested do not share a ref",
+                        monitor.compareNestedToLocalNested(id));
+      Assert.assertTrue("Remote nested and deepNested share a ref", 
+                        monitor.compareNestedToDeepNested(id));
+      Assert.assertTrue("Local nested and localDeepNested share a ref", 
+                        monitor.compareLocalNestedToLocalDeepNested(id));
+      
+      // Confirm this survives passivation/activation
+      
+      parent.reset();
+      
+      sleep(getSleepTime());
+      
+      // DeepContained beans ignore replication in their 
+      // activation/passivation counters, so we can test them
+      // to confirm activation/passivation
+      Assert.assertEquals("Local deep contained passivated once", 1,
+                          monitor.getLocalDeepNestedPassivations());
+      Assert.assertEquals("Local deep contained activated once", 1,
+                          monitor.getLocalDeepNestedActivations());
+      Assert.assertEquals("Deep contained passivated once", 1,
+                          monitor.getDeepNestedPassivations());
+      Assert.assertEquals("Deep contained activated once", 1,
+                          monitor.getDeepNestedActivations());
+      
+      Assert.assertTrue("Parent and remote nested do not share ref", 
+                        monitor.compareTopToNested(id));
+      Assert.assertTrue("Parent and local nested do share ref", 
+                         monitor.compareTopToLocalNested(id));
+      Assert.assertTrue("Remote nested and local nested do not share a ref",
+                        monitor.compareNestedToLocalNested(id));
+      Assert.assertTrue("Remote nested and deepNested share a ref", 
+                        monitor.compareNestedToDeepNested(id));
+      Assert.assertTrue("Local nested and localDeepNested share a ref", 
+                        monitor.compareLocalNestedToLocalDeepNested(id));      
+      
+      removeBean(parent);
+      removeBean(monitor);      
+   }
+   
+   public void testDependentLifecycle()
+   throws Exception
+   {
+      getLog().debug("Running testDependentLifecycle()");
+      getLog().debug("==================================");
+      
+      BeanSet beanSet = getBeanSet();
+      ShoppingCart parent = beanSet.cart;
+      NestedXPCMonitor monitor = beanSet.monitor;
+      
+      // Confirm the nested beans are there
+      String deepId = monitor.getDeepNestedId();
+      Assert.assertNotNull("Got a deepId", deepId);
+      Assert.assertFalse("Got a non-ERROR deepId", "ERROR".equals(deepId));
+      String localDeepId = monitor.getLocalDeepNestedId();
+      Assert.assertNotNull("Got a localDeepId", localDeepId);
+      Assert.assertFalse("Got a non-ERROR localDeepId", "ERROR".equals(localDeepId));
+      
+      long id = parent.createCustomer();  
+      Customer customer = parent.find(id);
+      Assert.assertNotNull("Customer created and found on parent", customer);
+      
+      Assert.assertTrue("Parent and remote nested do not share ref", 
+                        monitor.compareTopToNested(id));
+      Assert.assertTrue("Parent and local nested do share ref", 
+                         monitor.compareTopToLocalNested(id));
+      Assert.assertTrue("Remote nested and local nested do not share a ref",
+                        monitor.compareNestedToLocalNested(id));
+      Assert.assertTrue("Remote nested and deepNested share a ref", 
+                        monitor.compareNestedToDeepNested(id));
+      Assert.assertTrue("Local nested and localDeepNested share a ref", 
+                        monitor.compareLocalNestedToLocalDeepNested(id));
+      
+      // Remove the parent and see that things still work
+      Assert.assertTrue("Parent removed", monitor.removeParent());
+       
+      // Confirm parent is dead
+      Assert.assertFalse("parent.remove() fails", monitor.removeParent());
+      
+      Assert.assertTrue("Remote nested and local nested do not share a ref",
+            monitor.compareNestedToLocalNested(id));
+      Assert.assertTrue("Remote nested and deepNested share a ref", 
+            monitor.compareNestedToDeepNested(id));
+      Assert.assertTrue("Local nested and localDeepNested share a ref", 
+            monitor.compareLocalNestedToLocalDeepNested(id));
+      
+      // Remove the bottom tier
+      Assert.assertTrue("Local deep nested removed", monitor.removeLocalDeepNested());
+      
+      // Confirm it is dead
+      Assert.assertFalse("localDeepNested.remove() fails", monitor.removeLocalDeepNested());
+      
+      // Confirm other beans still work following remove
+      Assert.assertNotNull("Local nested still works", monitor.findLocalNested(id));
+      Assert.assertTrue("Remote nested and local nested do not share a ref",
+            monitor.compareNestedToLocalNested(id));
+      Assert.assertTrue("Remote nested and deepNested share a ref", 
+            monitor.compareNestedToDeepNested(id));
+      
+      // Remove the nested bean
+      Assert.assertTrue("Remote nested removed", monitor.removeNested());
+      
+      // Confirm it is dead
+      Assert.assertFalse("nested.remove() fails", monitor.removeNested());
+      
+      // Confirm other beans still work
+      Assert.assertNotNull("Local nested still works", monitor.findLocalNested(id));
+      Assert.assertNotNull("Remote deep nested still works", monitor.findDeepNested(id));
+      
+      // Remove the local nested bean
+      Assert.assertTrue("Local nested removed", monitor.removeLocalNested());
+      
+      // Confirm it is dead
+      Assert.assertFalse("localNested.remove() fails", monitor.removeLocalNested());
+      
+      // Confirm other beans still work following parent remove
+      Assert.assertNotNull("Deep nested not null", monitor.findDeepNested(id));
+      
+      // Remove the deep nested bean
+      Assert.assertTrue("Deep removed", monitor.removeDeepNested());
+      
+      // Confirm it is dead
+      Assert.assertEquals("Local nested removed", "ERROR", monitor.getDeepNestedId());
+      Assert.assertFalse("deepNested.remove() fails", monitor.removeDeepNested());
+      
+      removeBean(monitor);
+      
+      getLog().debug("ok");
+      
+   }
+
+   public void testPassivation() throws Exception
+   {
+      BeanSet beanSet = getBeanSet();
+      ShoppingCart cart = beanSet.cart;
+      NestedXPCMonitor monitor = beanSet.monitor;
+      
+      Customer customer;
+      
+      long id = cart.createCustomer();      
+      customer = monitor.find(id);
+      Assert.assertEquals("Stateless has proper initial name",
+                          "William", customer.getName());
+      customer = cart.find(id);
+      Assert.assertEquals("ShoppingCart has proper initial name",
+                          "William", customer.getName());
+      
+      cart.update();
+      customer = monitor.find(id);
+      Assert.assertEquals("Stateless has proper updated name",
+                           "Bill", customer.getName());
+      customer = cart.find(id);
+      Assert.assertEquals("ShoppingCart has proper updated name",
+                          "Bill", customer.getName());
+      
+      cart.update2();
+      customer = monitor.find(id);
+      Assert.assertEquals("Stateless has proper update2() name",
+                          "Billy", customer.getName());
+      customer = cart.find(id);
+      Assert.assertEquals("ShoppingCart has proper update2() name",
+                          "Billy", customer.getName());
+      
+      cart.update3();
+      customer = monitor.find(id);
+      Assert.assertEquals("Stateless has proper update3() name",
+                          "Bill Jr.", customer.getName());
+      customer = cart.find(id);
+      Assert.assertEquals("ShoppingCart has proper update3() name",
+                          "Bill Jr.", customer.getName());
+      
+      // Tell the contained bean to get the customer
+      cart.setContainedCustomer();
+      
+      // Clear the passivation counts
+      cart.reset();
+      
+      sleep(getSleepTime()); // passivation   
+      
+      Assert.assertEquals("Contained bean was passivated", 1, monitor.getLocalNestedPassivations());
+      
+      Assert.assertTrue("Parent and local contained share customer", cart.checkContainedCustomer());
+      
+      Assert.assertTrue("Contained bean was activated", monitor.getLocalNestedActivations() > 0);  
+      
+      cart.findAndUpdateStateless();
+      cart.updateContained();
+      
+      customer = monitor.find(id);
+      Assert.assertEquals("contained modified", customer.getName());
+      customer = cart.find(id);
+      Assert.assertEquals("contained modified", customer.getName());
+          
+      removeBean(monitor);
+      removeBean(cart);
+   }
+
+   public BeanSet getBeanSet() throws Exception
+   {
+      // We want a colocated monitor and SFSB to test passivation/destruction
+      // NestedXPCMonitorBean is not clustered, so once we have it's VMID
+      // we can keep creating SFSBs until we get one we want
+      NestedXPCMonitor monitor = (NestedXPCMonitor) getInitialContext().lookup("NestedXPCMonitorBean/remote");
+      VMID statelessVM = monitor.getVMID();
+      addRemovable(monitor);
+
+      ShoppingCart cart = null;      
+      boolean vmMatch = false;
+      for (int i = 0; i < 10 && !vmMatch; i++)
+      {
+         cart = (ShoppingCart) getInitialContext().lookup("testShoppingCart/remote");
+         
+         vmMatch = statelessVM.equals(cart.getVMID());
+         addRemovable(cart);
+         if (!vmMatch)
+            removeBean(cart);
+      }
+      
+      Assert.assertTrue("Monitor and SFSB in same VM", vmMatch);
+      
+      // Reset the parent to initialize all the beans
+      cart.reset();
+      
+      // Monitor the parent
+      monitor.monitor(cart);
+      
+      // Reset the parent to clean things up
+      cart.reset();
+      
+      BeanSet result = new BeanSet();
+      result.cart = cart;
+      result.monitor = monitor;
+      
+      return result;
+   }
+   
+   public NestedXPCMonitor getXPCMonitor(InitialContext[] ctxs, VMID vmid)
+   throws Exception
+   {
+      NestedXPCMonitor monitor = null;      
+      boolean vmMatch = false;
+      for (int i = 0; i < 10 && !vmMatch; i++)
+      {
+         InitialContext ctx = ctxs[i % ctxs.length];
+         monitor = (NestedXPCMonitor) ctx.lookup("NestedXPCMonitorBean/remote");
+         
+         vmMatch = vmid.equals(monitor.getVMID());
+         addRemovable(monitor);
+         if (!vmMatch)
+            removeBean(monitor);
+      }
+      
+      Assert.assertTrue("SLSB and SFSB in same VM", vmMatch);
+      
+      return monitor;
+   }
+   
+   public static class BeanSet
+   {
+      public ShoppingCart cart;
+      public NestedXPCMonitor monitor;
+   }
+}




More information about the jboss-cvs-commits mailing list