[jboss-cvs] JBossAS SVN: r64869 - in branches/JBPAPP_4_2/ejb3/src: resources/test-configs/statelesscreation/deploy and 5 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri Aug 24 18:22:49 EDT 2007


Author: bdecoste
Date: 2007-08-24 18:22:49 -0400 (Fri, 24 Aug 2007)
New Revision: 64869

Added:
   branches/JBPAPP_4_2/ejb3/src/resources/test-configs/statelesscreation/deploy/ejb3-interceptors-aop.xml
   branches/JBPAPP_4_2/ejb3/src/test/org/jboss/ejb3/test/statelesscreation/StatelessRemote.java
   branches/JBPAPP_4_2/ejb3/src/test/org/jboss/ejb3/test/statelesscreation/ThreadLocalPoolStatelessBean.java
Modified:
   branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/StrictMaxPool.java
   branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/ThreadlocalPool.java
   branches/JBPAPP_4_2/ejb3/src/resources/test-configs/statelesscreation/deploy/ejb3.deployer/META-INF/jboss-service.xml
   branches/JBPAPP_4_2/ejb3/src/test/org/jboss/ejb3/test/stateless/DefaultPoolStatelessBean.java
   branches/JBPAPP_4_2/ejb3/src/test/org/jboss/ejb3/test/stateless/StatelessRemote.java
   branches/JBPAPP_4_2/ejb3/src/test/org/jboss/ejb3/test/stateless/StrictMaxPoolStatelessBean.java
   branches/JBPAPP_4_2/ejb3/src/test/org/jboss/ejb3/test/stateless/unit/MetricsUnitTestCase.java
   branches/JBPAPP_4_2/ejb3/src/test/org/jboss/ejb3/test/statelesscreation/unit/MetricsUnitTestCase.java
Log:
[EJBTHREE-1032] more consistent metrics and improved tests

Modified: branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/StrictMaxPool.java
===================================================================
--- branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/StrictMaxPool.java	2007-08-24 21:19:08 UTC (rev 64868)
+++ branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/StrictMaxPool.java	2007-08-24 22:22:49 UTC (rev 64869)
@@ -33,7 +33,7 @@
 public class StrictMaxPool
         extends AbstractPool
 {
-   // Constants -----------------------------------------------------
+// Constants -----------------------------------------------------
    public static final int DEFAULT_MAX_SIZE = 30;
    public static final long DEFAULT_TIMEOUT = Long.MAX_VALUE;
 
@@ -81,17 +81,17 @@
    
    public int getCurrentSize()
    {
-	   return pool.size();
+      return getCreateCount() - getRemoveCount();
    }
    
    public int getAvailableCount()
    {
-	   return maxSize - inUse;
+      return maxSize - inUse;
    }
    
    public int getMaxSize()
    {
-	   return maxSize;
+      return maxSize;
    }
    
    public void setMaxSize(int maxSize)

Modified: branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/ThreadlocalPool.java
===================================================================
--- branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/ThreadlocalPool.java	2007-08-24 21:19:08 UTC (rev 64868)
+++ branches/JBPAPP_4_2/ejb3/src/main/org/jboss/ejb3/ThreadlocalPool.java	2007-08-24 22:22:49 UTC (rev 64869)
@@ -36,115 +36,149 @@
 {
 private static final Logger log = Logger.getLogger(ThreadlocalPool.class);
    
-   protected Pool delegate = new InfinitePool();
+   protected Pool pool = new InfinitePool();
    protected WeakThreadLocal<BeanContext> currentBeanContext = new WeakThreadLocal<BeanContext>();
+   private int inUse = 0;
+   private int maxSize = 30;
    
-   private int count = 0;
-
    public ThreadlocalPool()
    {
    }
 
    protected BeanContext create()
    {
-      return delegate.get();
+      return pool.get();
    }
    
    protected BeanContext create(Class[] initTypes, Object[] initValues)
    {
-      return delegate.get(initTypes, initValues);
+      return pool.get(initTypes, initValues);
    }
 
    public void discard(BeanContext obj)
    {
-      delegate.discard(obj);
+      pool.discard(obj);
+      --inUse;
    }
    
    public void destroy()
    {
       log.trace("destroying pool");
       
-      delegate.destroy();
+      pool.destroy();
       
       // This really serves little purpose, because we want the whole thread local map to die
       currentBeanContext.remove();
+      
+      inUse = 0;
    }
    
    public BeanContext get()
    {
-      BeanContext ctx = currentBeanContext.get();
-      if (ctx != null)
+      BeanContext ctx = null;
+      
+      synchronized(pool)
       {
-         currentBeanContext.set(null);
-         return ctx;
+         ctx = currentBeanContext.get();
+         if (ctx != null)
+         {
+            currentBeanContext.set(null);
+            ++inUse;
+            return ctx;
+         }
+   
+         ctx = create();
+         ++inUse;
       }
-
-      ctx = create();
+      
       return ctx;
    }
 
    public BeanContext get(Class[] initTypes, Object[] initValues)
    {
-      BeanContext ctx = currentBeanContext.get();
-      if (ctx != null)
+      BeanContext ctx = null;
+      synchronized(pool)
       {
-         currentBeanContext.set(null);
-         return ctx;
+         ctx = currentBeanContext.get();
+         if (ctx != null)
+         {
+            currentBeanContext.set(null);
+            ++inUse;
+            return ctx;
+         }
+   
+         ctx = create(initTypes, initValues);
+         ++inUse;
       }
-
-      ctx = create(initTypes, initValues);
+      
       return ctx;
    }
 
    public void initialize(Container container, Class contextClass, Class beanClass, int maxSize, long timeout)
    {
-      delegate.initialize(container, contextClass, beanClass, maxSize, timeout);
+      pool.initialize(container, contextClass, beanClass, maxSize, timeout);
+      this.maxSize = maxSize;
    }
    
    public void release(BeanContext ctx)
    {
-      if (currentBeanContext.get() != null)
-         remove(ctx);
-      else
-         currentBeanContext.set(ctx);
+      synchronized(pool)
+      {
+         if (currentBeanContext.get() != null)
+         {
+            remove(ctx);
+         }
+         else
+         {
+            currentBeanContext.set(ctx);
+         }
+         
+         --inUse;
+      }
    }
    
    public void remove(BeanContext ctx)
    {
-      delegate.remove(ctx);
+      pool.remove(ctx);
    }
    
    public int getCurrentSize()
    {
-      return -1;
+      int size;
+      synchronized (pool)
+      {
+         size = pool.getCreateCount() - pool.getRemoveCount();
+      }
+      return size;
    }
    
    public int getAvailableCount()
    {
-      return -1;
+      return maxSize - inUse;
    }
    
    public int getCreateCount()
    {
-      return delegate.getCreateCount();
+      return pool.getCreateCount();
    }
    
    public int getMaxSize()
    {
-      return -1;
+      return maxSize;
    }
 
    public int getRemoveCount()
    {
-      return delegate.getRemoveCount();
+      return pool.getRemoveCount();
    }
    
    public void setInjectors(Injector[] injectors)
    {
-      delegate.setInjectors(injectors);
+      pool.setInjectors(injectors);
    }
    
    public void setMaxSize(int maxSize)
    {
+      this.maxSize = maxSize;
    }
 }

Added: branches/JBPAPP_4_2/ejb3/src/resources/test-configs/statelesscreation/deploy/ejb3-interceptors-aop.xml
===================================================================
--- branches/JBPAPP_4_2/ejb3/src/resources/test-configs/statelesscreation/deploy/ejb3-interceptors-aop.xml	                        (rev 0)
+++ branches/JBPAPP_4_2/ejb3/src/resources/test-configs/statelesscreation/deploy/ejb3-interceptors-aop.xml	2007-08-24 22:22:49 UTC (rev 64869)
@@ -0,0 +1,365 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE aop PUBLIC
+   "-//JBoss//DTD JBOSS AOP 1.0//EN"
+   "http://labs.jboss.com/portal/jbossaop/dtd/jboss-aop_1_0.dtd">
+
+<aop>
+   <interceptor class="org.jboss.aspects.remoting.InvokeRemoteInterceptor" scope="PER_VM"/>
+   <interceptor class="org.jboss.aspects.security.SecurityClientInterceptor" scope="PER_VM"/>
+   <interceptor class="org.jboss.aspects.tx.ClientTxPropagationInterceptor" scope="PER_VM"/>
+   <interceptor class="org.jboss.ejb3.remoting.IsLocalInterceptor" scope="PER_VM"/>
+   <interceptor class="org.jboss.ejb3.remoting.ClusteredIsLocalInterceptor" scope="PER_VM"/>
+   <interceptor class="org.jboss.aspects.remoting.ClusterChooserInterceptor" scope="PER_VM"/>
+
+   <interceptor class="org.jboss.aspects.tx.TxPropagationInterceptor" scope="PER_VM"/>
+
+   <stack name="ServiceClientInterceptors">
+      <interceptor-ref name="org.jboss.ejb3.remoting.IsLocalInterceptor"/>
+      <interceptor-ref name="org.jboss.aspects.security.SecurityClientInterceptor"/>
+      <interceptor-ref name="org.jboss.aspects.tx.ClientTxPropagationInterceptor"/>
+      <interceptor-ref name="org.jboss.aspects.remoting.InvokeRemoteInterceptor"/>
+   </stack>
+
+   <stack name="AsynchronousStatelessSessionClientInterceptors">
+      <interceptor-ref name="org.jboss.ejb3.remoting.IsLocalInterceptor"/>
+      <interceptor-ref name="org.jboss.aspects.security.SecurityClientInterceptor"/>
+      <interceptor-ref name="org.jboss.aspects.tx.ClientTxPropagationInterceptor"/>
+      <interceptor-ref name="org.jboss.aspects.remoting.InvokeRemoteInterceptor"/>
+   </stack>
+
+   <stack name="AsynchronousStatefulSessionClientInterceptors">
+      <interceptor-ref name="org.jboss.ejb3.remoting.IsLocalInterceptor"/>
+      <interceptor-ref name="org.jboss.aspects.security.SecurityClientInterceptor"/>
+      <interceptor-ref name="org.jboss.aspects.tx.ClientTxPropagationInterceptor"/>
+      <interceptor-ref name="org.jboss.aspects.remoting.InvokeRemoteInterceptor"/>
+   </stack>
+
+   <stack name="StatelessSessionClientInterceptors">
+      <interceptor-ref name="org.jboss.ejb3.remoting.IsLocalInterceptor"/>
+      <interceptor-ref name="org.jboss.aspects.security.SecurityClientInterceptor"/>
+      <interceptor-ref name="org.jboss.aspects.tx.ClientTxPropagationInterceptor"/>
+      <interceptor-ref name="org.jboss.aspects.remoting.InvokeRemoteInterceptor"/>
+   </stack>
+
+   <stack name="StatefulSessionClientInterceptors">
+      <interceptor-ref name="org.jboss.ejb3.remoting.IsLocalInterceptor"/>
+      <interceptor-ref name="org.jboss.aspects.security.SecurityClientInterceptor"/>
+      <interceptor-ref name="org.jboss.aspects.tx.ClientTxPropagationInterceptor"/>
+      <interceptor-ref name="org.jboss.aspects.remoting.InvokeRemoteInterceptor"/>
+   </stack>
+
+   <stack name="ClusteredStatelessSessionClientInterceptors">
+      <interceptor-ref name="org.jboss.ejb3.remoting.ClusteredIsLocalInterceptor"/>
+      <interceptor-ref name="org.jboss.aspects.security.SecurityClientInterceptor"/>
+      <interceptor-ref name="org.jboss.aspects.tx.ClientTxPropagationInterceptor"/>
+      <interceptor-ref name="org.jboss.aspects.remoting.ClusterChooserInterceptor"/>
+      <interceptor-ref name="org.jboss.aspects.remoting.InvokeRemoteInterceptor"/>
+   </stack>
+
+   <stack name="ClusteredStatefulSessionClientInterceptors">
+      <interceptor-ref name="org.jboss.ejb3.remoting.ClusteredIsLocalInterceptor"/>
+      <interceptor-ref name="org.jboss.aspects.security.SecurityClientInterceptor"/>
+      <interceptor-ref name="org.jboss.aspects.tx.ClientTxPropagationInterceptor"/>
+      <interceptor-ref name="org.jboss.aspects.remoting.ClusterChooserInterceptor"/>
+      <interceptor-ref name="org.jboss.aspects.remoting.InvokeRemoteInterceptor"/>
+   </stack>
+
+   <interceptor class="org.jboss.ejb3.asynchronous.AsynchronousInterceptor" scope="PER_CLASS"/>
+   <interceptor class="org.jboss.ejb3.ENCPropagationInterceptor" scope="PER_VM"/>
+   <interceptor name="Basic Authorization" factory="org.jboss.ejb3.security.RoleBasedAuthorizationInterceptorFactory" scope="PER_CLASS"/>
+   <interceptor name="JACC Authorization" factory="org.jboss.ejb3.security.JaccAuthorizationInterceptorFactory" scope="PER_CLASS"/>
+   <interceptor factory="org.jboss.ejb3.security.AuthenticationInterceptorFactory" scope="PER_CLASS"/>
+   <interceptor factory="org.jboss.ejb3.security.RunAsSecurityInterceptorFactory" scope="PER_CLASS"/>
+   <interceptor class="org.jboss.ejb3.entity.ExtendedPersistenceContextPropagationInterceptor" scope="PER_VM"/>
+   <interceptor class="org.jboss.ejb3.stateless.StatelessInstanceInterceptor" scope="PER_VM"/>
+   <interceptor class="org.jboss.ejb3.stateful.StatefulInstanceInterceptor" scope="PER_VM"/>
+   <interceptor class="org.jboss.ejb3.stateful.SessionSynchronizationInterceptor" scope="PER_VM"/>
+   <interceptor class="org.jboss.ejb3.service.ServiceSingletonInterceptor" scope="PER_VM"/>
+   <interceptor class="org.jboss.ejb3.cache.StatefulReplicationInterceptor" scope="PER_VM"/>
+   <interceptor factory="org.jboss.ejb3.stateful.StatefulRemoveFactory" scope="PER_CLASS_JOINPOINT"/>
+   <interceptor factory="org.jboss.ejb3.tx.TxInterceptorFactory" scope="PER_CLASS_JOINPOINT"/>
+   <interceptor factory="org.jboss.ejb3.interceptor.EJB3InterceptorsFactory" scope="PER_CLASS_JOINPOINT"/>
+   <interceptor factory="org.jboss.ejb3.remoting.ReplicantsManagerInterceptorFactory" scope="PER_CLASS"/>
+   <interceptor class="org.jboss.ejb3.AllowedOperationsInterceptor" scope="PER_VM"/>
+   <interceptor factory="org.jboss.ejb3.mdb.CurrentMessageInjectorInterceptorFactory" scope="PER_CLASS"/>
+   <interceptor class="org.jboss.ejb3.entity.TransactionScopedEntityManagerInterceptor" scope="PER_VM"/>
+
+   <domain name="Stateless Bean">
+      <bind pointcut="execution(public * *->*(..))">
+         <interceptor-ref name="org.jboss.ejb3.asynchronous.AsynchronousInterceptor"/>
+         <interceptor-ref name="org.jboss.ejb3.ENCPropagationInterceptor"/>
+         <interceptor-ref name="org.jboss.ejb3.security.AuthenticationInterceptorFactory"/>
+      </bind>
+      <bind pointcut="execution(public * @org.jboss.annotation.security.SecurityDomain->*(..))">
+         <interceptor-ref name="Basic Authorization"/>
+      </bind>
+      <bind pointcut="execution(public * @javax.annotation.security.RunAs->*(..))">
+         <interceptor-ref name="org.jboss.ejb3.security.RunAsSecurityInterceptorFactory"/>
+      </bind>
+      <bind pointcut="execution(public * @org.jboss.annotation.ejb.Clustered->*(..))">
+         <interceptor-ref name="org.jboss.ejb3.remoting.ReplicantsManagerInterceptorFactory"/>
+      </bind>
+      <bind pointcut="execution(public * *->*(..))">
+         <interceptor-ref name="org.jboss.ejb3.stateless.StatelessInstanceInterceptor"/>
+         <interceptor-ref name="org.jboss.aspects.tx.TxPropagationInterceptor"/>
+         <interceptor-ref name="org.jboss.ejb3.tx.TxInterceptorFactory"/>
+         <interceptor-ref name="org.jboss.ejb3.AllowedOperationsInterceptor"/>
+         <interceptor-ref name="org.jboss.ejb3.entity.TransactionScopedEntityManagerInterceptor"/>
+         <interceptor-ref name="org.jboss.ejb3.interceptor.EJB3InterceptorsFactory"/>
+      </bind>
+      <annotation expr="!class(@org.jboss.annotation.ejb.PoolClass)">
+         @org.jboss.annotation.ejb.PoolClass (value=org.jboss.ejb3.ThreadlocalPool.class, maxSize=20, timeout=10000)
+      </annotation>
+   </domain>
+
+   <domain name="JACC Stateless Bean">
+      <bind pointcut="execution(public * *->*(..))">
+         <interceptor-ref name="org.jboss.ejb3.asynchronous.AsynchronousInterceptor"/>
+         <interceptor-ref name="org.jboss.ejb3.ENCPropagationInterceptor"/>
+         <interceptor-ref name="org.jboss.ejb3.security.AuthenticationInterceptorFactory"/>
+      </bind>
+      <bind pointcut="execution(public * @org.jboss.annotation.security.SecurityDomain->*(..))">
+         <interceptor-ref name="JACC Authorization"/>
+      </bind>
+      <bind pointcut="execution(public * @javax.annotation.security.RunAs->*(..))">
+         <interceptor-ref name="org.jboss.ejb3.security.RunAsSecurityInterceptorFactory"/>
+      </bind>
+      <bind pointcut="execution(public * @org.jboss.annotation.ejb.Clustered->*(..))">
+         <interceptor-ref name="org.jboss.ejb3.remoting.ReplicantsManagerInterceptorFactory"/>
+      </bind>
+      <bind pointcut="execution(public * *->*(..))">
+         <interceptor-ref name="org.jboss.ejb3.stateless.StatelessInstanceInterceptor"/>
+         <interceptor-ref name="org.jboss.aspects.tx.TxPropagationInterceptor"/>
+         <interceptor-ref name="org.jboss.ejb3.tx.TxInterceptorFactory"/>
+         <interceptor-ref name="org.jboss.ejb3.AllowedOperationsInterceptor"/>
+         <interceptor-ref name="org.jboss.ejb3.entity.TransactionScopedEntityManagerInterceptor"/>
+         <interceptor-ref name="org.jboss.ejb3.interceptor.EJB3InterceptorsFactory"/>
+      </bind>
+      <annotation expr="!class(@org.jboss.annotation.ejb.PoolClass)">
+         @org.jboss.annotation.ejb.PoolClass (value=org.jboss.ejb3.ThreadlocalPool.class, maxSize=30, timeout=10000)
+      </annotation>
+   </domain>
+
+   <domain name="Base Stateful Bean">
+      <bind pointcut="execution(public * *->*(..))">
+         <interceptor-ref name="org.jboss.ejb3.asynchronous.AsynchronousInterceptor"/>
+         <interceptor-ref name="org.jboss.ejb3.ENCPropagationInterceptor"/>
+         <interceptor-ref name="org.jboss.ejb3.security.AuthenticationInterceptorFactory"/>
+      </bind>
+      <bind pointcut="execution(public * @org.jboss.annotation.security.SecurityDomain->*(..))">
+         <interceptor-ref name="Basic Authorization"/>
+      </bind>
+      <bind pointcut="execution(public * @javax.annotation.security.RunAs->*(..))">
+         <interceptor-ref name="org.jboss.ejb3.security.RunAsSecurityInterceptorFactory"/>
+      </bind>
+      <bind pointcut="execution(public * @org.jboss.annotation.ejb.Clustered->*(..))">
+         <interceptor-ref name="org.jboss.ejb3.remoting.ReplicantsManagerInterceptorFactory"/>
+      </bind>
+      <bind pointcut="execution(public * *->@javax.ejb.Remove(..))">
+         <interceptor-ref name="org.jboss.ejb3.stateful.StatefulRemoveFactory"/>
+      </bind>
+      <bind pointcut="execution(public * *->*(..))">
+         <interceptor-ref name="org.jboss.ejb3.stateful.StatefulInstanceInterceptor"/>
+         <interceptor-ref name="org.jboss.aspects.tx.TxPropagationInterceptor"/>
+         <interceptor-ref name="org.jboss.ejb3.tx.TxInterceptorFactory"/>
+         <interceptor-ref name="org.jboss.ejb3.AllowedOperationsInterceptor"/>
+      </bind>
+      <bind pointcut="execution(public * $instanceof{javax.ejb.SessionSynchronization}->*(..))">
+         <interceptor-ref name="org.jboss.ejb3.stateful.SessionSynchronizationInterceptor"/>
+      </bind>
+      <bind pointcut="execution(public * *->*(..))">
+         <interceptor-ref name="org.jboss.ejb3.entity.TransactionScopedEntityManagerInterceptor"/>
+         <interceptor-ref name="org.jboss.ejb3.entity.ExtendedPersistenceContextPropagationInterceptor"/>
+      </bind>
+
+      <bind pointcut="execution(public * @org.jboss.annotation.ejb.Clustered->*(..)) AND !execution(public * *->@javax.ejb.Remove(..))">
+         <interceptor-ref name="org.jboss.ejb3.cache.StatefulReplicationInterceptor"/>
+      </bind>
+
+      <bind pointcut="execution(public * *->*(..))">
+         <interceptor-ref name="org.jboss.ejb3.interceptor.EJB3InterceptorsFactory"/>
+      </bind>
+
+      <annotation expr="!class(@org.jboss.annotation.ejb.PoolClass)">
+         @org.jboss.annotation.ejb.PoolClass (value=org.jboss.ejb3.ThreadlocalPool.class, maxSize=30, timeout=10000)
+      </annotation>
+   </domain>
+
+   <domain name="Stateful Bean" extends="Base Stateful Bean" inheritBindings="true">
+      <!-- NON Clustered cache configuration -->
+      <annotation expr="!class(@org.jboss.annotation.ejb.cache.Cache) AND !class(@org.jboss.annotation.ejb.Clustered)">
+         @org.jboss.annotation.ejb.cache.Cache (org.jboss.ejb3.cache.simple.SimpleStatefulCache.class)
+      </annotation>
+      <annotation expr="!class(@org.jboss.annotation.ejb.cache.simple.PersistenceManager) AND !class(@org.jboss.annotation.ejb.Clustered)">
+         @org.jboss.annotation.ejb.cache.simple.PersistenceManager (org.jboss.ejb3.cache.simple.StatefulSessionFilePersistenceManager.class)
+      </annotation>
+      <annotation expr="!class(@org.jboss.annotation.ejb.cache.simple.CacheConfig) AND !class(@org.jboss.annotation.ejb.Clustered)">
+         @org.jboss.annotation.ejb.cache.simple.CacheConfig (maxSize=100000, idleTimeoutSeconds=300, removalTimeoutSeconds=0)
+      </annotation>
+
+      <!-- Clustered cache configuration -->
+      <annotation expr="!class(@org.jboss.annotation.ejb.cache.Cache) AND class(@org.jboss.annotation.ejb.Clustered)">
+         @org.jboss.annotation.ejb.cache.Cache (org.jboss.ejb3.cache.tree.StatefulTreeCache.class)
+      </annotation>
+      <annotation expr="!class(@org.jboss.annotation.ejb.cache.tree.CacheConfig) AND class(@org.jboss.annotation.ejb.Clustered)">
+         @org.jboss.annotation.ejb.cache.tree.CacheConfig (name="jboss.cache:service=EJB3SFSBClusteredCache", maxSize=100000, idleTimeoutSeconds=300, removalTimeoutSeconds=0)
+      </annotation>
+   </domain>
+
+   <domain name="JACC Stateful Bean">
+      <bind pointcut="execution(public * *->*(..))">
+         <interceptor-ref name="org.jboss.ejb3.asynchronous.AsynchronousInterceptor"/>
+         <interceptor-ref name="org.jboss.ejb3.ENCPropagationInterceptor"/>
+         <interceptor-ref name="org.jboss.ejb3.security.AuthenticationInterceptorFactory"/>
+      </bind>
+      <bind pointcut="execution(public * @org.jboss.annotation.security.SecurityDomain->*(..))">
+         <interceptor-ref name="JACC Authorization"/>
+      </bind>
+      <bind pointcut="execution(public * @javax.annotation.security.RunAs->*(..))">
+         <interceptor-ref name="org.jboss.ejb3.security.RunAsSecurityInterceptorFactory"/>
+      </bind>
+      <bind pointcut="execution(public * @org.jboss.annotation.ejb.Clustered->*(..))">
+         <interceptor-ref name="org.jboss.ejb3.remoting.ReplicantsManagerInterceptorFactory"/>
+      </bind>
+      <bind pointcut="execution(public * *->@javax.ejb.Remove(..))">
+         <interceptor-ref name="org.jboss.ejb3.stateful.StatefulRemoveFactory"/>
+      </bind>
+      <bind pointcut="execution(public * *->*(..))">
+         <interceptor-ref name="org.jboss.ejb3.stateful.StatefulInstanceInterceptor"/>
+         <interceptor-ref name="org.jboss.aspects.tx.TxPropagationInterceptor"/>
+         <interceptor-ref name="org.jboss.ejb3.tx.TxInterceptorFactory"/>
+         <interceptor-ref name="org.jboss.ejb3.AllowedOperationsInterceptor"/>
+      </bind>
+      <bind pointcut="execution(public * $instanceof{javax.ejb.SessionSynchronization}->*(..))">
+         <interceptor-ref name="org.jboss.ejb3.stateful.SessionSynchronizationInterceptor"/>
+      </bind>
+      <bind pointcut="execution(public * *->*(..))">
+         <interceptor-ref name="org.jboss.ejb3.entity.TransactionScopedEntityManagerInterceptor"/>
+         <interceptor-ref name="org.jboss.ejb3.entity.ExtendedPersistenceContextPropagationInterceptor"/>
+         <interceptor-ref name="org.jboss.ejb3.interceptor.EJB3InterceptorsFactory"/>
+      </bind>
+
+      <bind pointcut="execution(public * @org.jboss.annotation.ejb.Clustered->*(..)) AND !execution(public * *->@javax.ejb.Remove(..))">
+         <interceptor-ref name="org.jboss.ejb3.cache.StatefulReplicationInterceptor"/>
+      </bind>
+      <annotation expr="!class(@org.jboss.annotation.ejb.PoolClass)">
+         @org.jboss.annotation.ejb.PoolClass (value=org.jboss.ejb3.ThreadlocalPool.class, maxSize=30, timeout=10000)
+      </annotation>
+
+      <!-- NON Clustered cache configuration -->
+      <annotation expr="!class(@org.jboss.annotation.ejb.cache.Cache) AND !class(@org.jboss.annotation.ejb.Clustered)">
+         @org.jboss.annotation.ejb.cache.Cache (org.jboss.ejb3.cache.simple.SimpleStatefulCache.class)
+      </annotation>
+      <annotation expr="!class(@org.jboss.annotation.ejb.cache.simple.PersistenceManager) AND !class(@org.jboss.annotation.ejb.Clustered)">
+         @org.jboss.annotation.ejb.cache.simple.PersistenceManager (org.jboss.ejb3.cache.simple.StatefulSessionFilePersistenceManager.class)
+      </annotation>
+      <annotation expr="!class(@org.jboss.annotation.ejb.cache.simple.CacheConfig) AND !class(@org.jboss.annotation.ejb.Clustered)">
+         @org.jboss.annotation.ejb.cache.simple.CacheConfig (maxSize=100000, idleTimeoutSeconds=300, removalTimeoutSeconds=0)
+      </annotation>
+
+      <!-- Clustered cache configuration -->
+      <annotation expr="!class(@org.jboss.annotation.ejb.cache.Cache) AND class(@org.jboss.annotation.ejb.Clustered)">
+         @org.jboss.annotation.ejb.cache.Cache (org.jboss.ejb3.cache.tree.StatefulTreeCache.class)
+      </annotation>
+      <annotation expr="!class(@org.jboss.annotation.ejb.cache.tree.CacheConfig) AND class(@org.jboss.annotation.ejb.Clustered)">
+         @org.jboss.annotation.ejb.cache.tree.CacheConfig (name="jboss.cache:service=EJB3SFSBClusteredCache", maxSize=100000, idleTimeoutSeconds=300, removalTimeoutSeconds=0)
+      </annotation>
+   </domain>
+
+   <domain name="Embedded Stateful Bean" extends="Base Stateful Bean" inheritBindings="true">
+      <!-- NON Clustered cache configuration -->
+      <annotation expr="!class(@org.jboss.annotation.ejb.cache.Cache)">
+         @org.jboss.annotation.ejb.cache.Cache (org.jboss.ejb3.cache.NoPassivationCache.class)
+      </annotation>
+
+   </domain>
+
+   <domain name="Message Driven Bean">
+      <bind pointcut="execution(public * @javax.annotation.security.RunAs->*(..))">
+         <interceptor-ref name="org.jboss.ejb3.security.RunAsSecurityInterceptorFactory"/>
+      </bind>
+      <bind pointcut="execution(public * *->*(..))">
+         <interceptor-ref name="org.jboss.ejb3.stateless.StatelessInstanceInterceptor"/>
+         <interceptor-ref name="org.jboss.ejb3.tx.TxInterceptorFactory"/>
+         <interceptor-ref name="org.jboss.ejb3.AllowedOperationsInterceptor"/>
+         <interceptor-ref name="org.jboss.ejb3.entity.TransactionScopedEntityManagerInterceptor"/>
+         <interceptor-ref name="org.jboss.ejb3.interceptor.EJB3InterceptorsFactory"/>
+      </bind>
+      <annotation expr="!class(@org.jboss.annotation.ejb.PoolClass)">
+         @org.jboss.annotation.ejb.PoolClass (value=org.jboss.ejb3.StrictMaxPool.class, maxSize=15, timeout=10000)
+      </annotation>
+   </domain>
+
+   <domain name="Consumer Bean">
+      <bind pointcut="execution(public * @javax.annotation.security.RunAs->*(..))">
+         <interceptor-ref name="org.jboss.ejb3.security.RunAsSecurityInterceptorFactory"/>
+      </bind>
+      <bind pointcut="execution(public * *->*(..))">
+         <interceptor-ref name="org.jboss.ejb3.stateless.StatelessInstanceInterceptor"/>
+         <interceptor-ref name="org.jboss.ejb3.tx.TxInterceptorFactory"/>
+         <interceptor-ref name="org.jboss.ejb3.AllowedOperationsInterceptor"/>
+         <interceptor-ref name="org.jboss.ejb3.entity.TransactionScopedEntityManagerInterceptor"/>
+      </bind>
+      <bind pointcut="execution(public * *->*(..)) AND (has(* *->@org.jboss.annotation.ejb.CurrentMessage(..)) OR hasfield(* *->@org.jboss.annotation.ejb.CurrentMessage))">
+         <interceptor-ref name="org.jboss.ejb3.mdb.CurrentMessageInjectorInterceptorFactory"/>
+      </bind>
+      <bind pointcut="execution(public * *->*(..))">
+         <interceptor-ref name="org.jboss.ejb3.interceptor.EJB3InterceptorsFactory"/>
+      </bind>
+      <annotation expr="!class(@org.jboss.annotation.ejb.PoolClass)">
+         @org.jboss.annotation.ejb.PoolClass (value=org.jboss.ejb3.StrictMaxPool.class, maxSize=15, timeout=10000)
+      </annotation>
+   </domain>
+
+   <domain name="Service Bean">
+      <bind pointcut="execution(public * *->*(..))">
+         <interceptor-ref name="org.jboss.ejb3.asynchronous.AsynchronousInterceptor"/>
+         <interceptor-ref name="org.jboss.ejb3.ENCPropagationInterceptor"/>
+      </bind>
+      <bind pointcut="!execution(* *->create()) AND !execution(* *->start()) AND !execution(*->new(..))">
+         <interceptor-ref name="org.jboss.ejb3.security.AuthenticationInterceptorFactory"/>
+      </bind>
+      <bind pointcut="execution(public * @org.jboss.annotation.security.SecurityDomain->*(..))">
+         <interceptor-ref name="Basic Authorization"/>
+      </bind>
+      <bind pointcut="execution(public * @javax.annotation.security.RunAs->*(..))">
+         <interceptor-ref name="org.jboss.ejb3.security.RunAsSecurityInterceptorFactory"/>
+      </bind>
+      <bind pointcut="execution(public * *->*(..))">
+         <interceptor-ref name="org.jboss.aspects.tx.TxPropagationInterceptor"/>
+         <interceptor-ref name="org.jboss.ejb3.tx.TxInterceptorFactory"/>
+         <interceptor-ref name="org.jboss.ejb3.AllowedOperationsInterceptor"/>
+         <interceptor-ref name="org.jboss.ejb3.entity.TransactionScopedEntityManagerInterceptor"/>
+      </bind>
+      <bind pointcut="execution(public * *->*(..)) AND !execution(* *->create()) AND !execution(* *->start())">
+         <interceptor-ref name="org.jboss.ejb3.interceptor.EJB3InterceptorsFactory"/>
+      </bind>
+   </domain>
+
+   <domain name="JACC Service Bean">
+      <bind pointcut="execution(public * *->*(..))">
+         <interceptor-ref name="org.jboss.ejb3.asynchronous.AsynchronousInterceptor"/>
+         <interceptor-ref name="org.jboss.ejb3.ENCPropagationInterceptor"/>
+      </bind>
+      <bind pointcut="!execution(* *->create()) AND !execution(* *->start()) AND !execution(*->new(..))">
+         <interceptor-ref name="org.jboss.ejb3.security.AuthenticationInterceptorFactory"/>
+      </bind>
+      <bind pointcut="execution(public * @org.jboss.annotation.security.SecurityDomain->*(..))">
+         <interceptor-ref name="Basic Authorization"/>
+      </bind>
+      <bind pointcut="execution(public * @javax.annotation.security.RunAs->*(..))">
+         <interceptor-ref name="org.jboss.ejb3.security.RunAsSecurityInterceptorFactory"/>
+      </bind>
+      <bind pointcut="execution(public * *->*(..))">
+         <interceptor-ref name="org.jboss.aspects.tx.TxPropagationInterceptor"/>
+         <interceptor-ref name="org.jboss.ejb3.tx.TxInterceptorFactory"/>
+         <interceptor-ref name="org.jboss.ejb3.AllowedOperationsInterceptor"/>
+         <interceptor-ref name="org.jboss.ejb3.entity.TransactionScopedEntityManagerInterceptor"/>
+      </bind>
+      <bind pointcut="execution(public * *->*(..)) AND !execution(* *->create()) AND !execution(* *->start())">
+         <interceptor-ref name="org.jboss.ejb3.interceptor.EJB3InterceptorsFactory"/>
+      </bind>
+   </domain>
+
+
+</aop>

Modified: branches/JBPAPP_4_2/ejb3/src/resources/test-configs/statelesscreation/deploy/ejb3.deployer/META-INF/jboss-service.xml
===================================================================
--- branches/JBPAPP_4_2/ejb3/src/resources/test-configs/statelesscreation/deploy/ejb3.deployer/META-INF/jboss-service.xml	2007-08-24 21:19:08 UTC (rev 64868)
+++ branches/JBPAPP_4_2/ejb3/src/resources/test-configs/statelesscreation/deploy/ejb3.deployer/META-INF/jboss-service.xml	2007-08-24 22:22:49 UTC (rev 64869)
@@ -25,7 +25,7 @@
          <config>
             <invoker transport="socket">
                <attribute name="numAcceptThreads">1</attribute>
-               <attribute name="maxPoolSize">30</attribute>
+               <attribute name="maxPoolSize">20</attribute>
                <attribute name="clientMaxPoolSize" isParam="true">50</attribute>
                <attribute name="timeout" isParam="true">60000</attribute>
                <attribute name="serverBindAddress">${jboss.bind.address}</attribute>

Modified: branches/JBPAPP_4_2/ejb3/src/test/org/jboss/ejb3/test/stateless/DefaultPoolStatelessBean.java
===================================================================
--- branches/JBPAPP_4_2/ejb3/src/test/org/jboss/ejb3/test/stateless/DefaultPoolStatelessBean.java	2007-08-24 21:19:08 UTC (rev 64868)
+++ branches/JBPAPP_4_2/ejb3/src/test/org/jboss/ejb3/test/stateless/DefaultPoolStatelessBean.java	2007-08-24 22:22:49 UTC (rev 64869)
@@ -40,4 +40,14 @@
    public void test() 
    {
    }
+   
+   public void testException() 
+   {
+      throw new RuntimeException();
+   }
+   
+   public void delay() throws Exception
+   {
+      Thread.sleep(30 * 1000);
+   }
 }

Modified: branches/JBPAPP_4_2/ejb3/src/test/org/jboss/ejb3/test/stateless/StatelessRemote.java
===================================================================
--- branches/JBPAPP_4_2/ejb3/src/test/org/jboss/ejb3/test/stateless/StatelessRemote.java	2007-08-24 21:19:08 UTC (rev 64868)
+++ branches/JBPAPP_4_2/ejb3/src/test/org/jboss/ejb3/test/stateless/StatelessRemote.java	2007-08-24 22:22:49 UTC (rev 64869)
@@ -27,4 +27,8 @@
 public interface StatelessRemote
 {
    void test();
+   
+   void testException();
+   
+   void delay() throws Exception;
 }

Modified: branches/JBPAPP_4_2/ejb3/src/test/org/jboss/ejb3/test/stateless/StrictMaxPoolStatelessBean.java
===================================================================
--- branches/JBPAPP_4_2/ejb3/src/test/org/jboss/ejb3/test/stateless/StrictMaxPoolStatelessBean.java	2007-08-24 21:19:08 UTC (rev 64868)
+++ branches/JBPAPP_4_2/ejb3/src/test/org/jboss/ejb3/test/stateless/StrictMaxPoolStatelessBean.java	2007-08-24 22:22:49 UTC (rev 64869)
@@ -33,7 +33,7 @@
  */
 @Stateless
 @Remote(StatelessRemote.class)
- at PoolClass (value=StrictMaxPool.class, maxSize=123, timeout=1000)
+ at PoolClass (value=StrictMaxPool.class, maxSize=3, timeout=1000)
 public class StrictMaxPoolStatelessBean implements StatelessRemote
 {
    private static final Logger log = Logger.getLogger(StrictMaxPoolStatelessBean.class);
@@ -41,4 +41,14 @@
    public void test() 
    {
    }
+   
+   public void testException() 
+   {
+      throw new RuntimeException();
+   }
+   
+   public void delay() throws Exception
+   {
+      Thread.sleep(30 * 1000);
+   }
 }

Modified: branches/JBPAPP_4_2/ejb3/src/test/org/jboss/ejb3/test/stateless/unit/MetricsUnitTestCase.java
===================================================================
--- branches/JBPAPP_4_2/ejb3/src/test/org/jboss/ejb3/test/stateless/unit/MetricsUnitTestCase.java	2007-08-24 21:19:08 UTC (rev 64868)
+++ branches/JBPAPP_4_2/ejb3/src/test/org/jboss/ejb3/test/stateless/unit/MetricsUnitTestCase.java	2007-08-24 22:22:49 UTC (rev 64869)
@@ -53,7 +53,7 @@
       int size = 0;
       
       size = (Integer)server.getAttribute(testerName, "CurrentSize");
-      assertEquals(-1, size);
+      assertEquals(0, size);
       
       size = (Integer)server.getAttribute(testerName, "CreateCount");
       assertEquals(0, size);
@@ -63,13 +63,13 @@
       stateless.test();     
       
       size = (Integer)server.getAttribute(testerName, "CurrentSize");
-      assertEquals(-1, size);
+      assertEquals(1, size);
       
       size = (Integer)server.getAttribute(testerName, "AvailableCount");
-      assertEquals(-1, size);
+      assertEquals(30, size);
       
       size = (Integer)server.getAttribute(testerName, "MaxSize");
-      assertEquals(-1, size);
+      assertEquals(30, size);
       
       size = (Integer)server.getAttribute(testerName, "CreateCount");
       assertEquals(1, size);
@@ -99,14 +99,129 @@
       assertEquals(1, size);
       
       size = (Integer)server.getAttribute(testerName, "AvailableCount");
-      assertEquals(123, size);
+      assertEquals(3, size);
       
       size = (Integer)server.getAttribute(testerName, "MaxSize");
-      assertEquals(123, size);
+      assertEquals(3, size);
       
       size = (Integer)server.getAttribute(testerName, "CreateCount");
       assertEquals(1, size);
+      
+      runConcurrentTests(20, 1);
+      
+      checkMetrics(server, testerName, 3, 3, 3, 3, 0);
+     
+      for (int i = 1 ; i <= 10 ; ++i)
+      {
+         try
+         {
+            stateless.testException();
+            fail("should have caught EJBException");
+         }
+         catch (javax.ejb.EJBException e)
+         {
+            int removeCount = (Integer)server.getAttribute(testerName, "RemoveCount");
+            System.out.println("RemoveCount=" + removeCount);
+            assertEquals(i, removeCount);
+         }
+      }
+      
+      runConcurrentTests(20, 1);
+      
+      checkMetrics(server, testerName, 3, 3, 3, 13, 10);
+      
+      Runnable r = new Runnable()
+      {
+         public void run()
+         {
+            try
+            {
+               StatelessRemote stateless = (StatelessRemote)getInitialContext().lookup("StrictMaxPoolStatelessBean/remote");                                            
+               stateless.delay();     
+            }
+            catch (Exception e)
+            {
+               e.printStackTrace();
+            }
+         }
+      };
+      
+      new Thread(r).start();
+      
+      Thread.sleep(10 * 1000);
+      
+      int currentSize = (Integer)server.getAttribute(testerName, "CurrentSize");
+      System.out.println("CurrentSize=" + currentSize);
+      
+      int availableCount = (Integer)server.getAttribute(testerName, "AvailableCount");
+      System.out.println("AvailableCount=" + availableCount);
+      
+      assertEquals(3, currentSize);
+      assertEquals(2, availableCount);
    }
+   
+   protected void checkMetrics(MBeanServerConnection server, ObjectName testerName, int current, int available, int max, int create, int remove)
+      throws Exception
+   {
+      
+      int currentSize = (Integer)server.getAttribute(testerName, "CurrentSize");
+      System.out.println("CurrentSize=" + currentSize);
+      
+      int availableCount = (Integer)server.getAttribute(testerName, "AvailableCount");
+      System.out.println("AvailableCount=" + availableCount);
+      
+      int maxSize = (Integer)server.getAttribute(testerName, "MaxSize");
+      System.out.println("MaxSize=" + maxSize);
+      
+      int createCount = (Integer)server.getAttribute(testerName, "CreateCount");
+      System.out.println("CreateCount=" + createCount);
+      
+      int removeCount = (Integer)server.getAttribute(testerName, "RemoveCount");
+      System.out.println("RemoveCount=" + removeCount);
+      
+      if (availableCount != maxSize)
+      {
+         System.out.println("Waiting to stabilize ... " + availableCount + "<" + maxSize);
+         Thread.sleep(1 * 60 * 1000);
+         availableCount = (Integer)server.getAttribute(testerName, "AvailableCount");
+      }
+      
+      assertEquals(current, currentSize);
+      assertEquals(available, availableCount);
+      assertEquals(max, maxSize);
+      assertEquals(create, createCount);
+      assertEquals(remove, removeCount);
+      
+   }
+   
+   protected void runConcurrentTests(int numThreads, int sleepSecs) throws Exception
+   {
+      for (int i = 0 ; i < numThreads ; ++i)
+      {
+         Runnable r = new Runnable()
+         {
+            public void run()
+            {
+               try
+               {
+                  StatelessRemote stateless = (StatelessRemote)getInitialContext().lookup("StrictMaxPoolStatelessBean/remote");                              
+                  for (int i = 0 ; i < 20 ; ++i)
+                  {                  
+                     stateless.test();     
+                  }
+               }
+               catch (Exception e)
+               {
+                  e.printStackTrace();
+               }
+            }
+         };
+         
+         new Thread(r).start();
+      }
+      
+      Thread.sleep(sleepSecs * 60 * 1000);  
+   }
 
    public static Test suite() throws Exception
    {

Added: branches/JBPAPP_4_2/ejb3/src/test/org/jboss/ejb3/test/statelesscreation/StatelessRemote.java
===================================================================
--- branches/JBPAPP_4_2/ejb3/src/test/org/jboss/ejb3/test/statelesscreation/StatelessRemote.java	                        (rev 0)
+++ branches/JBPAPP_4_2/ejb3/src/test/org/jboss/ejb3/test/statelesscreation/StatelessRemote.java	2007-08-24 22:22:49 UTC (rev 64869)
@@ -0,0 +1,34 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.test.statelesscreation;
+
+/**
+ * @author <a href="mailto:bdecoste at jboss.com">William DeCoste</a>
+ */
+public interface StatelessRemote
+{
+   void test();
+   
+   void testException();
+   
+   void delay() throws Exception;
+}

Added: branches/JBPAPP_4_2/ejb3/src/test/org/jboss/ejb3/test/statelesscreation/ThreadLocalPoolStatelessBean.java
===================================================================
--- branches/JBPAPP_4_2/ejb3/src/test/org/jboss/ejb3/test/statelesscreation/ThreadLocalPoolStatelessBean.java	                        (rev 0)
+++ branches/JBPAPP_4_2/ejb3/src/test/org/jboss/ejb3/test/statelesscreation/ThreadLocalPoolStatelessBean.java	2007-08-24 22:22:49 UTC (rev 64869)
@@ -0,0 +1,51 @@
+/*
+ * 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.statelesscreation;
+
+import javax.ejb.Stateless;
+import javax.ejb.Remote;
+
+import org.jboss.logging.Logger;
+
+/**
+ * @author <a href="mailto:bdecoste at jboss.com">William DeCoste</a>
+ */
+ at Stateless
+ at Remote(StatelessRemote.class)
+public class ThreadLocalPoolStatelessBean implements StatelessRemote
+{
+   private static final Logger log = Logger.getLogger(ThreadLocalPoolStatelessBean.class);
+   
+   public void test() 
+   {
+   }
+   
+   public void testException() 
+   {
+      throw new RuntimeException();
+   }
+   
+   public void delay() throws Exception
+   {
+      Thread.sleep(30 * 1000);
+   }
+}

Modified: branches/JBPAPP_4_2/ejb3/src/test/org/jboss/ejb3/test/statelesscreation/unit/MetricsUnitTestCase.java
===================================================================
--- branches/JBPAPP_4_2/ejb3/src/test/org/jboss/ejb3/test/statelesscreation/unit/MetricsUnitTestCase.java	2007-08-24 21:19:08 UTC (rev 64868)
+++ branches/JBPAPP_4_2/ejb3/src/test/org/jboss/ejb3/test/statelesscreation/unit/MetricsUnitTestCase.java	2007-08-24 22:22:49 UTC (rev 64869)
@@ -26,6 +26,7 @@
 import javax.naming.InitialContext;
 
 import org.jboss.ejb3.test.statelesscreation.DestroyRemote;
+import org.jboss.ejb3.test.statelesscreation.StatelessRemote;
 import org.jboss.logging.Logger;
 import org.jboss.test.JBossTestCase;
 import junit.framework.Test;
@@ -50,18 +51,193 @@
       assertNotNull(slsb);
       assertEquals(1, slsb.getBeanCount());
       
-      for (int i = 0 ; i < 50 ; ++i)
+      Runnable r = new Runnable()
       {
+         public void run()
+         {
+            try
+            {
+               InitialContext jndiContext = getInitialContext();
+               for (int i = 0 ; i < 100 ; ++i)
+               {                  
+                  DestroyRemote slsb = (DestroyRemote)jndiContext.lookup("DestroyStatelessBean/remote");              
+                  slsb.getBeanCount();
+               }
+            }
+            catch (Exception e)
+            {
+               e.printStackTrace();
+            }
+         }
+      };
+      Thread threads[] = new Thread[50];
+      for (int i = 0 ; i < threads.length ; ++i)
+      {
+         threads[i] = new Thread(r);
+         threads[i].start();
+      }
+      
+      for(Thread t : threads)
+      {
+         t.join(1 * 60 * 1000);
+      }
+      
+      MBeanServerConnection server = getServer();
+      ObjectName testerName = new ObjectName("jboss.j2ee:jar=statelesscreation-test.jar,name=DestroyStatelessBean,service=EJB3");
+   
+      int currentSize = (Integer)server.getAttribute(testerName, "CurrentSize");
+      System.out.println("CurrentSize=" + currentSize);
+      
+      int availableCount = (Integer)server.getAttribute(testerName, "AvailableCount");
+      System.out.println("AvailableCount=" + availableCount);
+      
+      int maxSize = (Integer)server.getAttribute(testerName, "MaxSize");
+      System.out.println("MaxSize=" + maxSize);
+      
+      int removeCount = (Integer)server.getAttribute(testerName, "RemoveCount");
+      System.out.println("RemoveCount=" + removeCount);
+      
+      int createCount = (Integer)server.getAttribute(testerName, "CreateCount");
+      System.out.println("CreateCount=" + createCount);
+      
+      
+      assertEquals(20, currentSize);
+      assertEquals(20, availableCount);
+      assertEquals(20, maxSize);
+      assertEquals(20, createCount);
+      assertEquals(0, removeCount);
+      
+   }
+   
+   public void testThreadLocalPoolJmxMetrics() throws Exception
+   {
+      MBeanServerConnection server = getServer();
+      ObjectName testerName = new ObjectName("jboss.j2ee:jar=statelesscreation-test.jar,name=ThreadLocalPoolStatelessBean,service=EJB3");
+      int size = 0;
+      
+      size = (Integer)server.getAttribute(testerName, "CurrentSize");
+      assertEquals(0, size);
+      
+      size = (Integer)server.getAttribute(testerName, "CreateCount");
+      assertEquals(0, size);
+      
+      StatelessRemote stateless = (StatelessRemote)getInitialContext().lookup("ThreadLocalPoolStatelessBean/remote");
+      assertNotNull(stateless);
+      stateless.test();     
+      
+      size = (Integer)server.getAttribute(testerName, "CurrentSize");
+      assertEquals(1, size);
+      
+      size = (Integer)server.getAttribute(testerName, "AvailableCount");
+      assertEquals(20, size);
+      
+      size = (Integer)server.getAttribute(testerName, "MaxSize");
+      assertEquals(20, size);
+      
+      size = (Integer)server.getAttribute(testerName, "CreateCount");
+      assertEquals(1, size);
+      
+      runConcurrentTests(30, 1);
+      
+      checkMetrics(server, testerName, 20, 20, 20, 20, 0);
+     
+      for (int i = 1 ; i <= 10 ; ++i)
+      {
+         try
+         {
+            stateless.testException();
+            fail("should have caught EJBException");
+         }
+         catch (javax.ejb.EJBException e)
+         {
+            int removeCount = (Integer)server.getAttribute(testerName, "RemoveCount");
+            System.out.println("RemoveCount=" + removeCount);
+            assertEquals(i, removeCount);
+         }
+      }
+      
+      runConcurrentTests(30, 1);
+      
+      checkMetrics(server, testerName, 20, 20, 20, 30, 10);
+      
+      Runnable r = new Runnable()
+      {
+         public void run()
+         {
+            try
+            {
+               StatelessRemote stateless = (StatelessRemote)getInitialContext().lookup("ThreadLocalPoolStatelessBean/remote");                                            
+               stateless.delay();     
+            }
+            catch (Exception e)
+            {
+               e.printStackTrace();
+            }
+         }
+      };
+      
+      new Thread(r).start();
+      
+      Thread.sleep(10 * 1000);
+      
+      int currentSize = (Integer)server.getAttribute(testerName, "CurrentSize");
+      System.out.println("CurrentSize=" + currentSize);
+      
+      int availableCount = (Integer)server.getAttribute(testerName, "AvailableCount");
+      System.out.println("AvailableCount=" + availableCount);
+      
+      assertEquals(20, currentSize);
+      assertEquals(19, availableCount);
+   }
+   
+   protected void checkMetrics(MBeanServerConnection server, ObjectName testerName, int current, int available, int max, int create, int remove)
+      throws Exception
+   {
+      
+      int currentSize = (Integer)server.getAttribute(testerName, "CurrentSize");
+      System.out.println("CurrentSize=" + currentSize);
+      
+      int availableCount = (Integer)server.getAttribute(testerName, "AvailableCount");
+      System.out.println("AvailableCount=" + availableCount);
+      
+      int maxSize = (Integer)server.getAttribute(testerName, "MaxSize");
+      System.out.println("MaxSize=" + maxSize);
+      
+      int createCount = (Integer)server.getAttribute(testerName, "CreateCount");
+      System.out.println("CreateCount=" + createCount);
+      
+      int removeCount = (Integer)server.getAttribute(testerName, "RemoveCount");
+      System.out.println("RemoveCount=" + removeCount);
+      
+      if (availableCount != maxSize)
+      {
+         System.out.println("Waiting to stabilize ... " + availableCount + "<" + maxSize);
+         Thread.sleep(1 * 60 * 1000);
+         availableCount = (Integer)server.getAttribute(testerName, "AvailableCount");
+      }
+      
+      assertEquals("CurrentSize", current, currentSize);
+      assertEquals("AvailableCount", available, availableCount);
+      assertEquals("MaxSize", max, maxSize);
+      assertEquals("CreateCount", create, createCount);
+      assertEquals("RemoveCount", remove, removeCount);
+      
+   }
+   
+   protected void runConcurrentTests(int numThreads, int sleepSecs) throws Exception
+   {
+      for (int i = 0 ; i < numThreads ; ++i)
+      {
          Runnable r = new Runnable()
          {
             public void run()
             {
                try
                {
-                  DestroyRemote slsb = (DestroyRemote)getInitialContext().lookup("DestroyStatelessBean/remote");                               
-                  for (int i = 0 ; i < 100 ; ++i)
+                  StatelessRemote stateless = (StatelessRemote)getInitialContext().lookup("ThreadLocalPoolStatelessBean/remote");                              
+                  for (int i = 0 ; i < 25 ; ++i)
                   {                  
-                     slsb.getBeanCount();
+                     stateless.test();     
                   }
                }
                catch (Exception e)
@@ -74,27 +250,7 @@
          new Thread(r).start();
       }
       
-      Thread.sleep(1 * 60 * 1000);  
-      
-      MBeanServerConnection server = getServer();
-      ObjectName testerName = new ObjectName("jboss.j2ee:jar=statelesscreation-test.jar,name=DestroyStatelessBean,service=EJB3");
-   
-      int size = (Integer)server.getAttribute(testerName, "CurrentSize");
-      System.out.println("CurrentSize=" + size);
-      
-      size = (Integer)server.getAttribute(testerName, "AvailableCount");
-      System.out.println("AvailableCount=" + size);
-      
-      size = (Integer)server.getAttribute(testerName, "MaxSize");
-      System.out.println("MaxSize=" + size);
-      
-      size = (Integer)server.getAttribute(testerName, "RemoveCount");
-      System.out.println("RemoveCount=" + size);
-      
-      size = (Integer)server.getAttribute(testerName, "CreateCount");
-      System.out.println("CreateCount=" + size);
-      assertEquals(30, size);
-      
+      Thread.sleep(sleepSecs * 60 * 1000);  
    }
    
    public static Test suite() throws Exception




More information about the jboss-cvs-commits mailing list