[jboss-cvs] JBossAS SVN: r58030 - in branches/JEE5_TCK/ejb3: . src/main/org/jboss/ejb3/cache/tree src/resources/test/stateful/META-INF src/test/org/jboss/ejb3/test/stateful src/test/org/jboss/ejb3/test/stateful/unit

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Nov 2 18:12:06 EST 2006


Author: bdecoste
Date: 2006-11-02 18:12:02 -0500 (Thu, 02 Nov 2006)
New Revision: 58030

Added:
   branches/JEE5_TCK/ejb3/src/resources/test/stateful/META-INF/persistence.xml
   branches/JEE5_TCK/ejb3/src/test/org/jboss/ejb3/test/stateful/Entity.java
   branches/JEE5_TCK/ejb3/src/test/org/jboss/ejb3/test/stateful/EntityFacade.java
   branches/JEE5_TCK/ejb3/src/test/org/jboss/ejb3/test/stateful/EntityFacadeBean.java
Modified:
   branches/JEE5_TCK/ejb3/build-test.xml
   branches/JEE5_TCK/ejb3/src/main/org/jboss/ejb3/cache/tree/StatefulTreeCache.java
   branches/JEE5_TCK/ejb3/src/test/org/jboss/ejb3/test/stateful/unit/RemoteUnitTestCase.java
Log:
fix and test for eviction of already passivated SFSB

Modified: branches/JEE5_TCK/ejb3/build-test.xml
===================================================================
--- branches/JEE5_TCK/ejb3/build-test.xml	2006-11-02 22:37:59 UTC (rev 58029)
+++ branches/JEE5_TCK/ejb3/build-test.xml	2006-11-02 23:12:02 UTC (rev 58030)
@@ -2324,8 +2324,7 @@
             <include name="org/jboss/ejb3/test/stateful/unit/*.class"/>
          </fileset>
          <fileset dir="${resources}/test/stateful">
-            <include name="META-INF/ejb-jar.xml"/>
-            <include name="META-INF/jboss.xml"/>
+            <include name="META-INF/*.xml"/>
          </fileset>
          <fileset dir="${resources}/test/stateful">
             <include name="*.xml"/>

Modified: branches/JEE5_TCK/ejb3/src/main/org/jboss/ejb3/cache/tree/StatefulTreeCache.java
===================================================================
--- branches/JEE5_TCK/ejb3/src/main/org/jboss/ejb3/cache/tree/StatefulTreeCache.java	2006-11-02 22:37:59 UTC (rev 58029)
+++ branches/JEE5_TCK/ejb3/src/main/org/jboss/ejb3/cache/tree/StatefulTreeCache.java	2006-11-02 23:12:02 UTC (rev 58030)
@@ -266,7 +266,6 @@
             throw new IllegalStateException("StatefuleTreeCache.nodeActivate(): null bean instance.");
          }
 
-//         log.debug("nodeActivate(): send postActivate event on fqn: " +fqn);
          if(log.isTraceEnabled())
          {
             log.trace("nodeActivate(): send postActivate event on fqn: " +fqn);
@@ -275,24 +274,18 @@
          bean.postActivate();
       }
 
-      public void nodePassivate(Fqn fqn, boolean pre) {
+      public void nodePassivate(Fqn fqn, boolean pre)
+      {
          if(!pre) return;  // we are not interested in postPassivate event
          if(fqn.size() != FQN_SIZE) return;
          if(!fqn.isChildOrEquals(cacheNode)) return;  // don't care about fqn that doesn't belong to me.
 
-         try {
-            // TODO Can this cause deadlock in the cache level? Should be ok but need review.
-            Node node = cache.get(fqn);
-            StatefulBeanContext bean = (StatefulBeanContext) node.getData().get("bean");
-            if (bean != null)
-               bean.prePassivate();
+         // TODO Can this cause deadlock in the cache level? Should be ok but need review.
+         org.jboss.cache.DataNode node = cache.peek(fqn);
+         StatefulBeanContext bean = (StatefulBeanContext) node.getData().get("bean");
+         if (bean != null && !bean.inUse)
+            bean.prePassivate();
 
-         } catch (CacheException e) {
-            log.error("nodePassivate(): can't retrieve bean instance from: " +fqn + " with exception: " +e);
-            return;
-         }
-
-//         log.debug("nodePassivate(): send prePassivate event on fqn: " +fqn);
          if(log.isTraceEnabled())
          {
             log.trace("nodePassivate(): send prePassivate event on fqn: " +fqn);

Added: branches/JEE5_TCK/ejb3/src/resources/test/stateful/META-INF/persistence.xml
===================================================================
--- branches/JEE5_TCK/ejb3/src/resources/test/stateful/META-INF/persistence.xml	2006-11-02 22:37:59 UTC (rev 58029)
+++ branches/JEE5_TCK/ejb3/src/resources/test/stateful/META-INF/persistence.xml	2006-11-02 23:12:02 UTC (rev 58030)
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<persistence>
+   <persistence-unit name="tempdb">
+      <jta-data-source>java:/DefaultDS</jta-data-source>
+      <properties>
+          <property name="hibernate.hbm2ddl.auto" value="create-drop"/>
+      </properties>
+   </persistence-unit>
+</persistence>

Added: branches/JEE5_TCK/ejb3/src/test/org/jboss/ejb3/test/stateful/Entity.java
===================================================================
--- branches/JEE5_TCK/ejb3/src/test/org/jboss/ejb3/test/stateful/Entity.java	2006-11-02 22:37:59 UTC (rev 58029)
+++ branches/JEE5_TCK/ejb3/src/test/org/jboss/ejb3/test/stateful/Entity.java	2006-11-02 23:12:02 UTC (rev 58030)
@@ -0,0 +1,60 @@
+/*
+  * 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.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.Table;
+
+/**
+ * @author <a href="mailto:bdecoste at jboss.com">William DeCoste</a>
+ */
+ at javax.persistence.Entity
+ at Table(name = "ENTITY")
+public class Entity implements java.io.Serializable
+{
+   private Long id;
+   private String name;
+  
+
+   @Id
+   @GeneratedValue(strategy= GenerationType.IDENTITY)
+   public Long getId()
+   {
+      return id;
+   }
+
+   public void setId(Long id)
+   {
+      this.id = id;
+   }
+
+   public String getName()
+   {
+      return name;
+   }
+
+   public void setName(String name)
+   {
+      this.name = name;
+   }
+}

Added: branches/JEE5_TCK/ejb3/src/test/org/jboss/ejb3/test/stateful/EntityFacade.java
===================================================================
--- branches/JEE5_TCK/ejb3/src/test/org/jboss/ejb3/test/stateful/EntityFacade.java	2006-11-02 22:37:59 UTC (rev 58029)
+++ branches/JEE5_TCK/ejb3/src/test/org/jboss/ejb3/test/stateful/EntityFacade.java	2006-11-02 23:12:02 UTC (rev 58030)
@@ -0,0 +1,32 @@
+/*
+  * 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 EntityFacade
+{
+   Entity createEntity(String name);
+   
+   Entity loadEntity(Long id);
+}

Added: branches/JEE5_TCK/ejb3/src/test/org/jboss/ejb3/test/stateful/EntityFacadeBean.java
===================================================================
--- branches/JEE5_TCK/ejb3/src/test/org/jboss/ejb3/test/stateful/EntityFacadeBean.java	2006-11-02 22:37:59 UTC (rev 58029)
+++ branches/JEE5_TCK/ejb3/src/test/org/jboss/ejb3/test/stateful/EntityFacadeBean.java	2006-11-02 23:12:02 UTC (rev 58030)
@@ -0,0 +1,77 @@
+/*
+  * 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 org.jboss.annotation.ejb.cache.simple.CacheConfig;
+import org.jboss.logging.Logger;
+
+import javax.ejb.PostActivate;
+import javax.ejb.PrePassivate;
+import javax.ejb.Remote;
+import javax.ejb.Stateful;
+import javax.ejb.TransactionAttribute;
+import javax.ejb.TransactionAttributeType;
+import javax.persistence.EntityManager;
+import javax.persistence.PersistenceContext;
+import javax.persistence.PersistenceContextType;
+
+
+/**
+ * @author <a href="mailto:bdecoste at jboss.com">William DeCoste</a>
+ */
+ at Stateful
+ at Remote(EntityFacade.class)
+ at CacheConfig(maxSize = 1000, idleTimeoutSeconds = 1)
+ at TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
+public class EntityFacadeBean implements EntityFacade
+{
+   private @PersistenceContext(type = PersistenceContextType.EXTENDED)
+   EntityManager manager;
+   
+   private static final Logger log = Logger.getLogger(EntityFacadeBean.class);
+
+   public Entity createEntity(String name) {
+      log.info("********* createEntity " + name);
+      Entity entity = new Entity();
+      entity.setName(name);
+	   manager.persist(entity);
+	   return entity;
+   }
+   
+   public Entity loadEntity(Long id) {
+      log.info("********* loadEntity " + id);
+      Entity entity =  manager.find(Entity.class, id);
+	   return entity;
+   }
+   
+   @PrePassivate
+   public void passivate()
+   {
+      log.info("************ passivating");  
+   }
+   
+   @PostActivate
+   public void activate()
+   {
+      log.info("************ activating");
+   }
+}

Modified: branches/JEE5_TCK/ejb3/src/test/org/jboss/ejb3/test/stateful/unit/RemoteUnitTestCase.java
===================================================================
--- branches/JEE5_TCK/ejb3/src/test/org/jboss/ejb3/test/stateful/unit/RemoteUnitTestCase.java	2006-11-02 22:37:59 UTC (rev 58029)
+++ branches/JEE5_TCK/ejb3/src/test/org/jboss/ejb3/test/stateful/unit/RemoteUnitTestCase.java	2006-11-02 23:12:02 UTC (rev 58030)
@@ -21,14 +21,20 @@
   */
 package org.jboss.ejb3.test.stateful.unit;
 
+import java.util.Map;
+
 import javax.ejb.NoSuchEJBException;
+import javax.management.MBeanServerConnection;
 import javax.management.ObjectName;
 import javax.naming.InitialContext;
 
 import org.jboss.ejb3.ClientKernelAbstraction;
 import org.jboss.ejb3.KernelAbstractionFactory;
+import org.jboss.ejb3.statistics.InvocationStatistics;
 import org.jboss.ejb3.test.stateful.ClusteredStateful;
 import org.jboss.ejb3.test.stateful.ConcurrentStateful;
+import org.jboss.ejb3.test.stateful.Entity;
+import org.jboss.ejb3.test.stateful.EntityFacade;
 import org.jboss.ejb3.test.stateful.SmallCacheStateful;
 import org.jboss.ejb3.test.stateful.Stateful;
 import org.jboss.ejb3.test.stateful.StatefulInvoker;
@@ -316,6 +322,60 @@
       Thread.sleep(10 * 1000);
       stateful.testStateful();
    }
+   
+   public void testExtendedPersistencePassivation() throws Exception
+   {
+      EntityFacade stateful = (EntityFacade)getInitialContext().lookup("EntityFacadeBean/remote");
+      Entity entity = null;
+      entity = stateful.createEntity("Kalin");
+      
+      //passivate
+      Thread.sleep(10 * 1000);
+      
+      MBeanServerConnection server = getServer();
+      ObjectName objectName = new ObjectName("jboss.jca:service=CachedConnectionManager");
+      int inUseConnections = (Integer)server.getAttribute(objectName, "InUseConnections");
+      System.out.println("inUseConnections \n" + inUseConnections);
+      assertEquals(0, inUseConnections);
+      
+      //activate
+      entity = stateful.loadEntity(entity.getId());
+      
+      inUseConnections = (Integer)server.getAttribute(objectName, "InUseConnections");
+      System.out.println("inUseConnections \n" + inUseConnections);
+      if (inUseConnections != 0)
+         printStats(server);
+      assertEquals(0, inUseConnections);
+      
+      entity = stateful.createEntity("Kalin" + entity.getId());
+      
+      inUseConnections = (Integer)server.getAttribute(objectName, "InUseConnections");
+      System.out.println("inUseConnections \n" + inUseConnections);
+      
+      if (inUseConnections != 0)
+         printStats(server);
+      assertEquals(0, inUseConnections);
+   }
+   
+   protected void printStats(MBeanServerConnection server) throws Exception
+   {
+      ObjectName objectName = new ObjectName("jboss.jca:service=CachedConnectionManager");
+      Object[] params = {};
+      String[] sig = {};
+      Map result = (Map)server.invoke(objectName, "listInUseConnections", params, sig);
+      System.out.println(result);
+      
+      objectName = new ObjectName("jboss:service=TransactionManager");
+      long activeTransactions = (Long)server.getAttribute(objectName, "TransactionCount");
+      System.out.println("activeTransactions \n" + activeTransactions);
+      
+      objectName = new ObjectName("jboss.jca:service=ManagedConnectionPool,name=DefaultDS");
+      long inUseConnectionCount = (Long)server.getAttribute(objectName, "InUseConnectionCount");
+      System.out.println("inUseConnectionCount \n" + inUseConnectionCount);
+      
+      long maxConnectionsInUseCount = (Long)server.getAttribute(objectName, "MaxConnectionsInUseCount");
+      System.out.println("maxConnectionsInUseCount \n" + maxConnectionsInUseCount); 
+   }
 
    public void testPassivation() throws Exception
    {
@@ -358,7 +418,7 @@
       service.testInjection();
    }
    
-   public void atestClusteredPassivation() throws Exception
+   public void testClusteredPassivation() throws Exception
    {
       SecurityAssociation.setPrincipal(new SimplePrincipal("somebody"));
       SecurityAssociation.setCredential("password".toCharArray());




More information about the jboss-cvs-commits mailing list