[jboss-cvs] JBossAS SVN: r57744 - in trunk/ejb3/src: main/org/jboss/ejb3/stateful test/org/jboss/ejb3/test/stateful test/org/jboss/ejb3/test/stateful/unit

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Oct 19 18:43:48 EDT 2006


Author: bdecoste
Date: 2006-10-19 18:43:42 -0400 (Thu, 19 Oct 2006)
New Revision: 57744

Added:
   trunk/ejb3/src/test/org/jboss/ejb3/test/stateful/ClusteredStateful.java
   trunk/ejb3/src/test/org/jboss/ejb3/test/stateful/ClusteredStatefulBean.java
   trunk/ejb3/src/test/org/jboss/ejb3/test/stateful/ServiceBean.java
   trunk/ejb3/src/test/org/jboss/ejb3/test/stateful/ServiceRemote.java
   trunk/ejb3/src/test/org/jboss/ejb3/test/stateful/Stateless.java
   trunk/ejb3/src/test/org/jboss/ejb3/test/stateful/StatelessBean.java
Modified:
   trunk/ejb3/src/main/org/jboss/ejb3/stateful/StatefulLocalProxyFactory.java
   trunk/ejb3/src/test/org/jboss/ejb3/test/stateful/Stateful.java
   trunk/ejb3/src/test/org/jboss/ejb3/test/stateful/StatefulBean.java
   trunk/ejb3/src/test/org/jboss/ejb3/test/stateful/unit/RemoteUnitTestCase.java
Log:
fix and test for passivation of local SFSB before 1st invocation. Bean is not in use at creation.

Modified: trunk/ejb3/src/main/org/jboss/ejb3/stateful/StatefulLocalProxyFactory.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/stateful/StatefulLocalProxyFactory.java	2006-10-19 22:42:31 UTC (rev 57743)
+++ trunk/ejb3/src/main/org/jboss/ejb3/stateful/StatefulLocalProxyFactory.java	2006-10-19 22:43:42 UTC (rev 57744)
@@ -97,7 +97,9 @@
       try
       {
          StatefulContainer sfsb = (StatefulContainer) container;
-         Object id = sfsb.createSession();
+         StatefulBeanContext ctx = sfsb.getCache().create();
+         ctx.inUse = false;
+         Object id = ctx.getId();
          Object[] args = {new StatefulLocalProxy(container, id)};
          return proxyConstructor.newInstance(args);
       }

Added: trunk/ejb3/src/test/org/jboss/ejb3/test/stateful/ClusteredStateful.java
===================================================================
--- trunk/ejb3/src/test/org/jboss/ejb3/test/stateful/ClusteredStateful.java	2006-10-19 22:42:31 UTC (rev 57743)
+++ trunk/ejb3/src/test/org/jboss/ejb3/test/stateful/ClusteredStateful.java	2006-10-19 22:43:42 UTC (rev 57744)
@@ -0,0 +1,45 @@
+/*
+  * 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;
+
+/**
+ * @author <a href="mailto:bdecoste at jboss.com">William DeCoste</a>
+ */
+public interface ClusteredStateful extends ConcurrentStateful
+{
+   boolean interceptorAccessed();
+
+   boolean testSessionContext();
+   
+   boolean wasPassivated();
+   String getInterceptorState();
+   void setInterceptorState(String param);
+   
+   void testThrownException() throws Exception;
+   
+   void testExceptionCause() throws Exception;
+   void testSerializedState(String state);
+   
+   void removeBean();
+   
+   void testResources() throws Exception;
+}

Added: trunk/ejb3/src/test/org/jboss/ejb3/test/stateful/ClusteredStatefulBean.java
===================================================================
--- trunk/ejb3/src/test/org/jboss/ejb3/test/stateful/ClusteredStatefulBean.java	2006-10-19 22:42:31 UTC (rev 57743)
+++ trunk/ejb3/src/test/org/jboss/ejb3/test/stateful/ClusteredStatefulBean.java	2006-10-19 22:43:42 UTC (rev 57744)
@@ -0,0 +1,209 @@
+/*
+  * 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;
+
+import java.io.ObjectOutputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+
+import javax.annotation.Resource;
+import javax.annotation.Resources;
+import javax.ejb.Init;
+import javax.ejb.Local;
+import javax.ejb.Remote;
+import javax.ejb.SessionContext;
+import javax.ejb.Stateful;
+import javax.ejb.PrePassivate;
+import javax.ejb.PostActivate;
+import javax.interceptor.Interceptors;
+import javax.naming.InitialContext;
+
+import org.jboss.ejb3.Container;
+
+import org.jboss.annotation.ejb.Clustered;
+import org.jboss.annotation.ejb.RemoteBinding;
+import org.jboss.annotation.ejb.cache.tree.CacheConfig;
+import org.jboss.annotation.security.SecurityDomain;
+import org.jboss.logging.Logger;
+import org.jboss.serial.io.JBossObjectOutputStream;
+import org.jboss.serial.io.JBossObjectInputStream;
+
+/**
+ * @author <a href="mailto:bdecoste at jboss.com">William DeCoste</a>
+ */
+ at Stateful(name="ClusteredStatefulBean")
+ at Remote(org.jboss.ejb3.test.stateful.ClusteredStateful.class)
+ at Local(org.jboss.ejb3.test.stateful.StatefulLocal.class)
+ at RemoteBinding(jndiBinding = "ClusteredStateful",
+               interceptorStack="RemoteBindingStatefulSessionClientInterceptors",
+               factory = org.jboss.ejb3.test.stateful.StatefulRemoteProxyFactory.class)
+ at CacheConfig(maxSize = 1000, idleTimeoutSeconds = 1, name="jboss.cache:service=EJB3SFSBClusteredCache")
+ at SecurityDomain("test")
+ at Resources({@Resource(name="jdbc/ds", mappedName="java:/DefaultDS")})
+ at Clustered
+public class ClusteredStatefulBean implements ClusteredStateful
+{
+   private static final Logger log = Logger.getLogger(ClusteredStatefulBean.class);
+   
+   @Resource
+   private SessionContext sessionContext;
+   
+//   @Resource(mappedName="java:/DefaultDS")
+//   private transient javax.sql.DataSource datasource;
+   
+//   @Resource(mappedName="java:/ConnectionFactory")
+//   public transient javax.jms.QueueConnectionFactory connectionFactory; 
+
+   private String state;
+   private int stuff;
+   private boolean wasPassivated = false;
+
+   @Interceptors(MyInterceptor.class)
+   public String getInterceptorState()
+   {
+      throw new RuntimeException("NOT REACHABLE");
+   }
+
+   @Interceptors(MyInterceptor.class)
+   public void setInterceptorState(String param)
+   {
+      throw new RuntimeException("NOT REACHABLE");
+   }
+   
+   public boolean testSessionContext()
+   {
+      return sessionContext.isCallerInRole("role");
+   }
+   
+   public void testResources() throws Exception
+   {
+//      datasource.toString();
+//      connectionFactory.toString();
+      
+      javax.sql.DataSource ds = (javax.sql.DataSource)new InitialContext().lookup(Container.ENC_CTX_NAME + "/env/jdbc/ds");
+      ds.toString();
+   }
+
+   public String getState() throws Exception
+   {
+      Thread.sleep(1000);
+      return state;
+   }
+
+   public void setState(String state) throws Exception
+   {
+	  log.info("!!! setState " + this);
+      Thread.sleep(1000);
+      this.state = state;
+   }
+
+   public boolean interceptorAccessed()
+   {
+      return RemoteBindingInterceptor.accessed;
+   }
+
+   public void testThrownException() throws Exception
+   {
+      throw new Exception();
+   }
+
+   public void testExceptionCause() throws Exception
+   {
+      Object o = null;
+      o.toString();
+   }
+
+   @PrePassivate
+   public void passivate()
+   {
+      log.info("************ passivating " + this);  
+      wasPassivated = true;
+   }
+   
+   @PostActivate
+   public void activate()
+   {
+      log.info("************ activating");
+   }
+
+   public void testSerializedState(String state)
+   {
+      this.state = state;
+
+      ClusteredStatefulBean bean = null;
+      try
+      {
+         ObjectOutputStream out;
+
+         ByteArrayOutputStream baos = new ByteArrayOutputStream();
+
+         out = new JBossObjectOutputStream(baos, false);
+         out.writeObject(this);
+         out.flush();
+
+         ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
+
+         JBossObjectInputStream is = new JBossObjectInputStream(bais);
+         bean = (ClusteredStatefulBean)is.readObject();
+      }
+      catch (IOException e)
+      {
+         throw new RuntimeException(e);
+      }
+      catch (ClassNotFoundException e)
+      {
+         throw new RuntimeException(e);
+      }
+
+      if (!state.equals(bean.state)) throw new RuntimeException("failed to serialize: " + bean.state);
+   }
+
+   public boolean wasPassivated()
+   {
+	  log.info("************ wasPassivated " + wasPassivated + " " + this);  
+      return wasPassivated;
+   }
+
+   @Init
+   public void ejbCreate(Integer state)
+   {
+      this.state=state.toString();
+   }
+
+   @Init
+   public void ejbCreate(State state)
+   {
+      this.state=state.getState();
+   }
+
+   @Init
+   public void ejbCreate(String state)
+   {
+      this.state=state;
+   }
+   
+   public void removeBean()
+   {
+      
+   }
+}

Added: trunk/ejb3/src/test/org/jboss/ejb3/test/stateful/ServiceBean.java
===================================================================
--- trunk/ejb3/src/test/org/jboss/ejb3/test/stateful/ServiceBean.java	2006-10-19 22:42:31 UTC (rev 57743)
+++ trunk/ejb3/src/test/org/jboss/ejb3/test/stateful/ServiceBean.java	2006-10-19 22:43:42 UTC (rev 57744)
@@ -0,0 +1,54 @@
+/*
+  * 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;
+
+import javax.ejb.EJB;
+import javax.ejb.Remote;
+
+import org.jboss.annotation.ejb.Service;
+import org.jboss.annotation.security.SecurityDomain;
+import org.jboss.logging.Logger;
+
+/**
+ * @author <a href="mailto:bdecoste at jboss.com">William DeCoste</a>
+ */
+ at Service
+ at Remote(ServiceRemote.class)
+ at SecurityDomain("other")
+public class ServiceBean implements ServiceRemote
+{
+	private static final Logger log = Logger.getLogger(ServiceBean.class);
+	
+	@EJB
+	private Stateful stateful;
+	
+	@EJB
+	private ClusteredStateful clusteredStateful;
+	   
+	public void testInjection() throws Exception
+	{
+		log.info("!!! testInjection ... " + clusteredStateful);
+		stateful.getState();
+		
+		clusteredStateful.getState();
+	}
+}

Added: trunk/ejb3/src/test/org/jboss/ejb3/test/stateful/ServiceRemote.java
===================================================================
--- trunk/ejb3/src/test/org/jboss/ejb3/test/stateful/ServiceRemote.java	2006-10-19 22:42:31 UTC (rev 57743)
+++ trunk/ejb3/src/test/org/jboss/ejb3/test/stateful/ServiceRemote.java	2006-10-19 22:43:42 UTC (rev 57744)
@@ -0,0 +1,30 @@
+/*
+  * 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;
+
+/**
+ * @author <a href="mailto:bdecoste at jboss.com">William DeCoste</a>
+ */
+public interface ServiceRemote
+{
+   void testInjection() throws Exception;
+}

Modified: trunk/ejb3/src/test/org/jboss/ejb3/test/stateful/Stateful.java
===================================================================
--- trunk/ejb3/src/test/org/jboss/ejb3/test/stateful/Stateful.java	2006-10-19 22:42:31 UTC (rev 57743)
+++ trunk/ejb3/src/test/org/jboss/ejb3/test/stateful/Stateful.java	2006-10-19 22:43:42 UTC (rev 57744)
@@ -36,7 +36,6 @@
    boolean testSessionContext();
    
    public boolean wasPassivated();
-   public void clearPassivated();
    public String getInterceptorState();
    public void setInterceptorState(String param);
    
@@ -48,5 +47,8 @@
    public void removeBean();
    
    void testResources() throws Exception;
+   
+   void lookupStateful() throws Exception;
+   void testStateful() throws Exception;
 
 }

Modified: trunk/ejb3/src/test/org/jboss/ejb3/test/stateful/StatefulBean.java
===================================================================
--- trunk/ejb3/src/test/org/jboss/ejb3/test/stateful/StatefulBean.java	2006-10-19 22:42:31 UTC (rev 57743)
+++ trunk/ejb3/src/test/org/jboss/ejb3/test/stateful/StatefulBean.java	2006-10-19 22:43:42 UTC (rev 57744)
@@ -37,7 +37,6 @@
 import javax.ejb.PostActivate;
 import javax.interceptor.Interceptors;
 import javax.naming.InitialContext;
-import javax.naming.NamingEnumeration;
 
 import org.jboss.ejb3.Container;
 
@@ -75,9 +74,22 @@
    
    @Resource(mappedName="java:/ConnectionFactory")
    public transient javax.jms.QueueConnectionFactory connectionFactory; 
+   
+   private StatefulLocal localStateful;
 
    private String state;
    private int stuff;
+   private boolean wasPassivated = false;
+   
+   public void lookupStateful() throws Exception
+   {
+      localStateful = (StatefulLocal)new InitialContext().lookup("StatefulBean/local");
+   }
+   
+   public void testStateful() throws Exception
+   {
+      localStateful.getState();
+   }
 
    @Interceptors(MyInterceptor.class)
    public String getInterceptorState()
@@ -146,8 +158,6 @@
       log.info("************ activating");
    }
 
-   private static boolean wasPassivated = false;
-
    public void testSerializedState(String state)
    {
       this.state = state;
@@ -185,11 +195,6 @@
       return wasPassivated;
    }
 
-   public void clearPassivated()
-   {
-      wasPassivated = false;
-   }
-
    @Init
    public void ejbCreate(Integer state)
    {

Added: trunk/ejb3/src/test/org/jboss/ejb3/test/stateful/Stateless.java
===================================================================
--- trunk/ejb3/src/test/org/jboss/ejb3/test/stateful/Stateless.java	2006-10-19 22:42:31 UTC (rev 57743)
+++ trunk/ejb3/src/test/org/jboss/ejb3/test/stateful/Stateless.java	2006-10-19 22:43:42 UTC (rev 57744)
@@ -0,0 +1,30 @@
+/*
+  * 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;
+
+/**
+ * @author <a href="mailto:bdecoste at jboss.com">William DeCoste</a>
+ */
+public interface Stateless
+{
+   void testInjection() throws Exception;
+}

Added: trunk/ejb3/src/test/org/jboss/ejb3/test/stateful/StatelessBean.java
===================================================================
--- trunk/ejb3/src/test/org/jboss/ejb3/test/stateful/StatelessBean.java	2006-10-19 22:42:31 UTC (rev 57743)
+++ trunk/ejb3/src/test/org/jboss/ejb3/test/stateful/StatelessBean.java	2006-10-19 22:43:42 UTC (rev 57744)
@@ -0,0 +1,56 @@
+/*
+  * 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;
+
+import javax.ejb.EJB;
+import javax.ejb.Remote;
+import javax.ejb.Stateless;
+
+import javax.naming.InitialContext;
+
+import org.jboss.annotation.ejb.RemoteBinding;
+import org.jboss.logging.Logger;
+
+/**
+ * @author <a href="mailto:bdecoste at jboss.com">William DeCoste</a>
+ */
+ at Stateless(name="StatelessBean")
+ at RemoteBinding(jndiBinding = "Stateless")
+ at Remote(org.jboss.ejb3.test.stateful.Stateless.class)
+public class StatelessBean implements org.jboss.ejb3.test.stateful.Stateless
+{
+	private static final Logger log = Logger.getLogger(StatelessBean.class);
+   
+	@EJB
+	private Stateful stateful;
+	
+	@EJB
+	private ClusteredStateful clusteredStateful;
+	   
+	public void testInjection() throws Exception
+	{
+		log.info("!!! testInjection ... " + clusteredStateful);
+		stateful.getState();
+	   
+		clusteredStateful.getState();
+	}
+}

Modified: trunk/ejb3/src/test/org/jboss/ejb3/test/stateful/unit/RemoteUnitTestCase.java
===================================================================
--- trunk/ejb3/src/test/org/jboss/ejb3/test/stateful/unit/RemoteUnitTestCase.java	2006-10-19 22:42:31 UTC (rev 57743)
+++ trunk/ejb3/src/test/org/jboss/ejb3/test/stateful/unit/RemoteUnitTestCase.java	2006-10-19 22:43:42 UTC (rev 57744)
@@ -27,7 +27,9 @@
 
 import org.jboss.ejb3.ClientKernelAbstraction;
 import org.jboss.ejb3.KernelAbstractionFactory;
+import org.jboss.ejb3.test.stateful.ClusteredStateful;
 import org.jboss.ejb3.test.stateful.ConcurrentStateful;
+import org.jboss.ejb3.test.stateful.ServiceRemote;
 import org.jboss.ejb3.test.stateful.SmallCacheStateful;
 import org.jboss.ejb3.test.stateful.Stateful;
 import org.jboss.ejb3.test.stateful.StatefulInvoker;
@@ -37,6 +39,7 @@
 import org.jboss.ejb3.test.stateful.RemoteBindingInterceptor;
 import org.jboss.ejb3.test.stateful.State;
 import org.jboss.ejb3.test.stateful.StatefulHome;
+import org.jboss.ejb3.test.stateful.Stateless;
 import org.jboss.ejb3.test.stateful.ExtendedState;
 import org.jboss.ejb3.test.stateful.Tester;
 import org.jboss.logging.Logger;
@@ -297,22 +300,44 @@
       assertTrue(RemoteBindingInterceptor.accessed);
    }
 
+   public void testUninstantiatedPassivation() throws Exception
+   {
+      SecurityAssociation.setPrincipal(new SimplePrincipal("somebody"));
+      SecurityAssociation.setCredential("password".toCharArray());
+      
+      Stateful stateful = (Stateful)getInitialContext().lookup("Stateful");
+      assertNotNull(stateful);
+      stateful.lookupStateful();
+      Thread.sleep(10 * 1000);
+      stateful.testStateful();
+      
+      stateful.lookupStateful();
+      stateful.testStateful();
+      Thread.sleep(10 * 1000);
+      stateful.testStateful();
+   }
+
    public void testPassivation() throws Exception
    {
       SecurityAssociation.setPrincipal(new SimplePrincipal("somebody"));
       SecurityAssociation.setCredential("password".toCharArray());
       
       System.out.println("testPassivation");
+      Stateless stateless = (Stateless)getInitialContext().lookup("Stateless");
+      stateless.testInjection();
+      
+      ServiceRemote service = (ServiceRemote) getInitialContext().lookup("ServiceBean/remote");
+      service.testInjection();
+      
       Stateful stateful = (Stateful)getInitialContext().lookup("Stateful");
       assertNotNull(stateful);
       stateful.setState("state");
       assertEquals("state", stateful.getState());
       stateful.testSerializedState("state");
-      stateful.clearPassivated();
       assertEquals(null, stateful.getInterceptorState());
       stateful.setInterceptorState("hello world");
       assertFalse(stateful.testSessionContext());
-      Thread.sleep(5 * 1000);
+      Thread.sleep(10 * 1000);
       assertTrue(stateful.wasPassivated());
       
       assertEquals("state", stateful.getState());
@@ -327,8 +352,55 @@
       assertFalse(stateful.testSessionContext());
       
       stateful.testResources();
+      
+      stateless.testInjection();
+      
+      service.testInjection();
    }
    
+   public void atestClusteredPassivation() throws Exception
+   {
+      SecurityAssociation.setPrincipal(new SimplePrincipal("somebody"));
+      SecurityAssociation.setCredential("password".toCharArray());
+      
+      System.out.println("testPassivation");
+      Stateless stateless = (Stateless)getInitialContext().lookup("Stateless");
+      stateless.testInjection();
+      
+      ServiceRemote service = (ServiceRemote) getInitialContext().lookup("ServiceBean/remote");
+      service.testInjection();
+      
+      ClusteredStateful stateful = (ClusteredStateful)getInitialContext().lookup("ClusteredStateful");
+      assertNotNull(stateful);
+      System.out.println("!!!! clusteredStateful " + stateful);
+      stateful.setState("state");
+      assertEquals("state", stateful.getState());
+      stateful.testSerializedState("state");
+      assertEquals(null, stateful.getInterceptorState());
+      stateful.setInterceptorState("hello world");
+      assertFalse(stateful.testSessionContext());
+      Thread.sleep(10 * 1000);
+      assertTrue(stateful.wasPassivated());
+      
+      assertEquals("state", stateful.getState());
+      assertEquals("hello world", stateful.getInterceptorState());
+
+      Stateful another = (Stateful)getInitialContext().lookup("Stateful");
+      assertEquals(null, another.getInterceptorState());
+      another.setInterceptorState("foo");
+      assertEquals("foo", another.getInterceptorState());
+      assertEquals("hello world", stateful.getInterceptorState());
+      
+      assertFalse(stateful.testSessionContext());
+      
+      stateful.testResources();
+      
+      stateless.testInjection();
+      
+      service.testInjection();
+   }
+
+   
    public void testRemove() throws Exception
    {
       SecurityAssociation.setPrincipal(new SimplePrincipal("somebody"));




More information about the jboss-cvs-commits mailing list