[jboss-cvs] JBossAS SVN: r64706 - in branches/Branch_4_2/ejb3: src/main/org/jboss/ejb3 and 3 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Mon Aug 20 08:51:31 EDT 2007
Author: wolfc
Date: 2007-08-20 08:51:31 -0400 (Mon, 20 Aug 2007)
New Revision: 64706
Added:
branches/Branch_4_2/ejb3/src/main/org/jboss/ejb3/InfinitePool.java
branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/threadlocal/
branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/threadlocal/MockBean.java
branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/threadlocal/MockBeanContext.java
branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/threadlocal/MockContainer.java
branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/threadlocal/unit/
branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/threadlocal/unit/ThreadLocalPoolUnitTestCase.java
Modified:
branches/Branch_4_2/ejb3/build-test.xml
branches/Branch_4_2/ejb3/src/main/org/jboss/ejb3/ThreadlocalPool.java
Log:
EJBTHREE-1031: thread local pool backed by infinite pool
Modified: branches/Branch_4_2/ejb3/build-test.xml
===================================================================
--- branches/Branch_4_2/ejb3/build-test.xml 2007-08-20 12:24:01 UTC (rev 64705)
+++ branches/Branch_4_2/ejb3/build-test.xml 2007-08-20 12:51:31 UTC (rev 64706)
@@ -940,6 +940,9 @@
</jar>
</target>
+ <target name="threadlocal" depends="compile-classes">
+ </target>
+
<target name="timer"
description="Builds all jar files."
depends="compile-classes">
@@ -3382,6 +3385,9 @@
<condition property="client.run.classpath" value="iiop.client.classpath">
<equals arg1="${test}" arg2="iiop"/>
</condition>
+ <condition property="client.run.classpath" value="dd.classpath">
+ <equals arg1="${test}" arg2="threadlocal"/>
+ </condition>
<condition property="client.run.classpath" value="client.classpath">
<not>
<isset property="client.run.classpath"/>
@@ -3610,6 +3616,7 @@
</target>
<target name="tests" depends="init" description="Execute all tests">
+ <antcall target="simple-tests" inheritRefs="true"/>
<antcall target="ejb-tests" inheritRefs="true"/>
<antcall target="entity-tests" inheritRefs="true"/>
<antcall target="ssl-simple-test" inheritRefs="true"/>
@@ -3631,6 +3638,12 @@
<antcall target="no-start-jboss-iiop-tests" inheritRefs="true"/>
</target>
+ <target name="simple-tests" depends="init">
+ <antcall target="test" inheritRefs="true">
+ <param name="test" value="threadlocal"/>
+ </antcall>
+ </target>
+
<target name="ejb-tests" depends="init" description="Execute all tests">
<start-jboss conf="all" host="${node0}" jboss.dist="${ejb3.dist}" jvmargs="${ejb3.jboss.jvmargs}"/>
Added: branches/Branch_4_2/ejb3/src/main/org/jboss/ejb3/InfinitePool.java
===================================================================
--- branches/Branch_4_2/ejb3/src/main/org/jboss/ejb3/InfinitePool.java (rev 0)
+++ branches/Branch_4_2/ejb3/src/main/org/jboss/ejb3/InfinitePool.java 2007-08-20 12:51:31 UTC (rev 64706)
@@ -0,0 +1,101 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2007, Red Hat Middleware LLC, 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;
+
+import java.util.LinkedList;
+import java.util.List;
+
+/**
+ * A pool that has no constraints.
+ *
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class InfinitePool extends AbstractPool
+{
+ private List<BeanContext> active = new LinkedList<BeanContext>();
+
+ public void destroy()
+ {
+ for(BeanContext ctx : active)
+ {
+ // call super.remove or else get concurrent modification
+ super.remove(ctx);
+ }
+ active = null;
+ }
+
+ public BeanContext get()
+ {
+ BeanContext ctx = create();
+ synchronized(active)
+ {
+ active.add(ctx);
+ }
+ return ctx;
+ }
+
+ public BeanContext get(Class[] initTypes, Object[] initValues)
+ {
+ BeanContext ctx = create(initTypes, initValues);
+ synchronized(active)
+ {
+ active.add(ctx);
+ }
+ return ctx;
+ }
+
+ public int getAvailableCount()
+ {
+ return -1;
+ }
+
+ public int getCurrentSize()
+ {
+ return active.size();
+ }
+
+ public int getMaxSize()
+ {
+ return -1;
+ }
+
+ public void release(BeanContext ctx)
+ {
+ remove(ctx);
+ }
+
+ public void remove(BeanContext ctx)
+ {
+ synchronized(active)
+ {
+ active.remove(ctx);
+ }
+
+ super.remove(ctx);
+ }
+
+ public void setMaxSize(int maxSize)
+ {
+ }
+
+}
Property changes on: branches/Branch_4_2/ejb3/src/main/org/jboss/ejb3/InfinitePool.java
___________________________________________________________________
Name: svn:keywords
+ Author Date Id Revision
Name: svn:eol-style
+ native
Modified: branches/Branch_4_2/ejb3/src/main/org/jboss/ejb3/ThreadlocalPool.java
===================================================================
--- branches/Branch_4_2/ejb3/src/main/org/jboss/ejb3/ThreadlocalPool.java 2007-08-20 12:24:01 UTC (rev 64705)
+++ branches/Branch_4_2/ejb3/src/main/org/jboss/ejb3/ThreadlocalPool.java 2007-08-20 12:51:31 UTC (rev 64706)
@@ -21,6 +21,7 @@
*/
package org.jboss.ejb3;
+import org.jboss.injection.Injector;
import org.jboss.lang.ref.WeakThreadLocal;
import org.jboss.logging.Logger;
@@ -31,30 +32,48 @@
* @author <a href="mailto:bill at jboss.org">Bill Burke</a>
* @version $Revision$
*/
-public class ThreadlocalPool extends AbstractPool
+public class ThreadlocalPool implements Pool
{
private static final Logger log = Logger.getLogger(ThreadlocalPool.class);
- protected WeakThreadLocal<BeanContext> pool = new WeakThreadLocal<BeanContext>();
+ protected Pool delegate = new InfinitePool();
+ protected WeakThreadLocal<BeanContext> currentBeanContext = new WeakThreadLocal<BeanContext>();
public ThreadlocalPool()
{
}
+ protected BeanContext create()
+ {
+ return delegate.get();
+ }
+
+ protected BeanContext create(Class[] initTypes, Object[] initValues)
+ {
+ return delegate.get(initTypes, initValues);
+ }
+
+ public void discard(BeanContext obj)
+ {
+ delegate.discard(obj);
+ }
+
public void destroy()
{
log.trace("destroying pool");
+ delegate.destroy();
+
// This really serves little purpose, because we want the whole thread local map to die
- pool.remove();
+ currentBeanContext.remove();
}
public BeanContext get()
{
- BeanContext ctx = pool.get();
+ BeanContext ctx = currentBeanContext.get();
if (ctx != null)
{
- pool.set(null);
+ currentBeanContext.set(null);
return ctx;
}
@@ -64,10 +83,10 @@
public BeanContext get(Class[] initTypes, Object[] initValues)
{
- BeanContext ctx = pool.get();
+ BeanContext ctx = currentBeanContext.get();
if (ctx != null)
{
- pool.set(null);
+ currentBeanContext.set(null);
return ctx;
}
@@ -75,14 +94,24 @@
return ctx;
}
+ public void initialize(Container container, Class contextClass, Class beanClass, int maxSize, long timeout)
+ {
+ delegate.initialize(container, contextClass, beanClass, maxSize, timeout);
+ }
+
public void release(BeanContext ctx)
{
- if (pool.get() != null)
+ if (currentBeanContext.get() != null)
remove(ctx);
else
- pool.set(ctx);
+ currentBeanContext.set(ctx);
}
+ public void remove(BeanContext ctx)
+ {
+ delegate.remove(ctx);
+ }
+
public int getCurrentSize()
{
return -1;
@@ -93,11 +122,26 @@
return -1;
}
+ public int getCreateCount()
+ {
+ return delegate.getCreateCount();
+ }
+
public int getMaxSize()
{
return -1;
}
+ public int getRemoveCount()
+ {
+ return delegate.getRemoveCount();
+ }
+
+ public void setInjectors(Injector[] injectors)
+ {
+ delegate.setInjectors(injectors);
+ }
+
public void setMaxSize(int maxSize)
{
}
Added: branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/threadlocal/MockBean.java
===================================================================
--- branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/threadlocal/MockBean.java (rev 0)
+++ branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/threadlocal/MockBean.java 2007-08-20 12:51:31 UTC (rev 64706)
@@ -0,0 +1,56 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2007, Red Hat Middleware LLC, 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.threadlocal;
+
+import org.jboss.logging.Logger;
+
+/**
+ * Comment
+ *
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class MockBean
+{
+ private static final Logger log = Logger.getLogger(MockBean.class);
+ public static int finalizers = 0;
+
+ @Override
+ protected void finalize() throws Throwable
+ {
+ log.info("finalize");
+
+ finalizers++;
+
+ super.finalize();
+ }
+
+ protected void postConstruct()
+ {
+ log.info("postConstruct");
+ }
+
+ protected void preDestroy()
+ {
+ log.info("preDestroy");
+ }
+}
Property changes on: branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/threadlocal/MockBean.java
___________________________________________________________________
Name: svn:keywords
+ Author Date Id Revision
Name: svn:eol-style
+ native
Added: branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/threadlocal/MockBeanContext.java
===================================================================
--- branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/threadlocal/MockBeanContext.java (rev 0)
+++ branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/threadlocal/MockBeanContext.java 2007-08-20 12:51:31 UTC (rev 64706)
@@ -0,0 +1,141 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2007, Red Hat Middleware LLC, 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.threadlocal;
+
+import javax.ejb.EJBContext;
+
+import org.jboss.aop.metadata.SimpleMetaData;
+import org.jboss.ejb3.BeanContext;
+import org.jboss.ejb3.Container;
+import org.jboss.ejb3.interceptor.InterceptorInfo;
+import org.jboss.logging.Logger;
+
+/**
+ * Comment
+ *
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class MockBeanContext implements BeanContext
+{
+ private static Logger log = Logger.getLogger(MockBeanContext.class);
+
+ private Object instance;
+
+ @Override
+ protected void finalize() throws Throwable
+ {
+ log.info("finalize");
+ super.finalize();
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.ejb3.BeanContext#getContainer()
+ */
+ public Container getContainer()
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.ejb3.BeanContext#getEJBContext()
+ */
+ public EJBContext getEJBContext()
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.ejb3.BeanContext#getInstance()
+ */
+ public Object getInstance()
+ {
+ assert instance != null;
+ return instance;
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.ejb3.BeanContext#getInterceptorInstances(org.jboss.ejb3.interceptor.InterceptorInfo[])
+ */
+ public Object[] getInterceptorInstances(InterceptorInfo[] interceptorInfos)
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.ejb3.BeanContext#getInvokedMethodKey()
+ */
+ public Object getInvokedMethodKey()
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.ejb3.BeanContext#getMetaData()
+ */
+ public SimpleMetaData getMetaData()
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.ejb3.BeanContext#initialiseInterceptorInstances()
+ */
+ public void initialiseInterceptorInstances()
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.ejb3.BeanContext#remove()
+ */
+ public void remove()
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.ejb3.BeanContext#setContainer(org.jboss.ejb3.Container)
+ */
+ public void setContainer(Container container)
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.ejb3.BeanContext#setInstance(java.lang.Object)
+ */
+ public void setInstance(Object instance)
+ {
+ assert instance != null;
+ this.instance = instance;
+ }
+
+}
Property changes on: branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/threadlocal/MockBeanContext.java
___________________________________________________________________
Name: svn:keywords
+ Author Date Id Revision
Name: svn:eol-style
+ native
Added: branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/threadlocal/MockContainer.java
===================================================================
--- branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/threadlocal/MockContainer.java (rev 0)
+++ branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/threadlocal/MockContainer.java 2007-08-20 12:51:31 UTC (rev 64706)
@@ -0,0 +1,259 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2007, Red Hat Middleware LLC, 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.threadlocal;
+
+import java.util.Hashtable;
+
+import javax.ejb.TimerService;
+import javax.management.ObjectName;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+
+import org.jboss.ejb3.BeanContext;
+import org.jboss.ejb3.Container;
+import org.jboss.ejb3.DependencyPolicy;
+import org.jboss.ejb3.Pool;
+import org.jboss.ejb3.statistics.InvocationStatistics;
+
+/**
+ * Comment
+ *
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class MockContainer implements Container
+{
+
+ /* (non-Javadoc)
+ * @see org.jboss.ejb3.Container#construct()
+ */
+ public Object construct()
+ {
+ return new MockBean();
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.ejb3.Container#create()
+ */
+ public void create() throws Exception
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.ejb3.Container#destroy()
+ */
+ public void destroy() throws Exception
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.ejb3.Container#getBeanClass()
+ */
+ public Class getBeanClass()
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.ejb3.Container#getDependencyPolicy()
+ */
+ public DependencyPolicy getDependencyPolicy()
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.ejb3.Container#getEjbName()
+ */
+ public String getEjbName()
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.ejb3.Container#getEnc()
+ */
+ public Context getEnc()
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.ejb3.Container#getInitialContext()
+ */
+ public InitialContext getInitialContext()
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.ejb3.Container#getInitialContextProperties()
+ */
+ public Hashtable getInitialContextProperties()
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.ejb3.Container#getInvokeStats()
+ */
+ public InvocationStatistics getInvokeStats()
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.ejb3.Container#getObjectName()
+ */
+ public ObjectName getObjectName()
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.ejb3.Container#getPool()
+ */
+ public Pool getPool()
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.ejb3.Container#getTimerService()
+ */
+ public TimerService getTimerService()
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.ejb3.Container#getTimerService(java.lang.Object)
+ */
+ public TimerService getTimerService(Object pKey)
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.ejb3.Container#invokeInit(java.lang.Object)
+ */
+ public void invokeInit(Object bean)
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.ejb3.Container#invokeInit(java.lang.Object, java.lang.Class[], java.lang.Object[])
+ */
+ public void invokeInit(Object bean, Class[] initTypes, Object[] initValues)
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.ejb3.Container#invokePostActivate(org.jboss.ejb3.BeanContext)
+ */
+ public void invokePostActivate(BeanContext beanContext)
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.ejb3.Container#invokePostConstruct(org.jboss.ejb3.BeanContext)
+ */
+ public void invokePostConstruct(BeanContext beanContext)
+ {
+ ((MockBean) beanContext.getInstance()).postConstruct();
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.ejb3.Container#invokePreDestroy(org.jboss.ejb3.BeanContext)
+ */
+ public void invokePreDestroy(BeanContext beanContext)
+ {
+ ((MockBean) beanContext.getInstance()).preDestroy();
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.ejb3.Container#invokePrePassivate(org.jboss.ejb3.BeanContext)
+ */
+ public void invokePrePassivate(BeanContext beanContext)
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.ejb3.Container#isClustered()
+ */
+ public boolean isClustered()
+ {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.ejb3.Container#processMetadata(org.jboss.ejb3.DependencyPolicy)
+ */
+ public void processMetadata(DependencyPolicy dependencyPolicy)
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.ejb3.Container#start()
+ */
+ public void start() throws Exception
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.ejb3.Container#stop()
+ */
+ public void stop() throws Exception
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+}
Property changes on: branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/threadlocal/MockContainer.java
___________________________________________________________________
Name: svn:keywords
+ Author Date Id Revision
Name: svn:eol-style
+ native
Added: branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/threadlocal/unit/ThreadLocalPoolUnitTestCase.java
===================================================================
--- branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/threadlocal/unit/ThreadLocalPoolUnitTestCase.java (rev 0)
+++ branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/threadlocal/unit/ThreadLocalPoolUnitTestCase.java 2007-08-20 12:51:31 UTC (rev 64706)
@@ -0,0 +1,245 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2007, Red Hat Middleware LLC, 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.threadlocal.unit;
+
+import org.jboss.ejb3.BeanContext;
+import org.jboss.ejb3.Container;
+import org.jboss.ejb3.ThreadlocalPool;
+import org.jboss.ejb3.test.threadlocal.MockBean;
+import org.jboss.ejb3.test.threadlocal.MockBeanContext;
+import org.jboss.ejb3.test.threadlocal.MockContainer;
+
+import junit.framework.TestCase;
+
+/**
+ * Comment
+ *
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class ThreadLocalPoolUnitTestCase extends TestCase
+{
+ int used = 0;
+
+ private static void gc()
+ {
+ for(int i = 0; i < 3; i++)
+ {
+ System.gc();
+ try
+ {
+ Thread.sleep(100);
+ }
+ catch (InterruptedException e)
+ {
+ // ignore
+ }
+ System.runFinalization();
+ }
+ }
+
+ public void test1()
+ {
+ ThreadlocalPool pool = new ThreadlocalPool();
+ Container container = new MockContainer();
+ Class<? extends BeanContext> contextClass = MockBeanContext.class;
+ Class<?> beanClass = null;
+ int maxSize = -1;
+ int timeout = -1;
+ pool.initialize(container, contextClass, beanClass, maxSize, timeout);
+ BeanContext ctx = pool.get();
+ pool.release(ctx);
+
+ ctx = null;
+
+ gc();
+ assertEquals(0, pool.getRemoveCount());
+ assertEquals(0, MockBean.finalizers);
+
+ pool.destroy();
+
+ gc();
+ assertEquals(1, pool.getRemoveCount());
+ assertEquals(1, MockBean.finalizers);
+ }
+
+ public void testWithThreads() throws Exception
+ {
+ final ThreadlocalPool pool = new ThreadlocalPool();
+ Container container = new MockContainer();
+ Class<? extends BeanContext> contextClass = MockBeanContext.class;
+ Class<?> beanClass = null;
+ int maxSize = -1;
+ int timeout = -1;
+ pool.initialize(container, contextClass, beanClass, maxSize, timeout);
+
+ Runnable r = new Runnable()
+ {
+ public void run()
+ {
+ BeanContext ctx = pool.get();
+ pool.release(ctx);
+
+ ctx = null;
+ used++;
+ }
+ };
+
+ Thread threads[] = new Thread[20];
+ for(int i = 0; i < threads.length; i++)
+ {
+ threads[i] = new Thread(r);
+ threads[i].start();
+ }
+
+ for(Thread t : threads)
+ {
+ t.join(1000);
+ }
+
+ gc();
+ assertEquals(0, pool.getRemoveCount());
+ assertEquals(0, MockBean.finalizers);
+
+ pool.destroy();
+
+ gc();
+ assertEquals(20, pool.getRemoveCount());
+ assertEquals(20, MockBean.finalizers);
+
+ assertEquals(20, used);
+ }
+
+ public void testMultipleWithThreads() throws Exception
+ {
+ final ThreadlocalPool pool = new ThreadlocalPool();
+ Container container = new MockContainer();
+ Class<? extends BeanContext> contextClass = MockBeanContext.class;
+ Class<?> beanClass = null;
+ int maxSize = -1;
+ int timeout = -1;
+ pool.initialize(container, contextClass, beanClass, maxSize, timeout);
+
+ Runnable r = new Runnable()
+ {
+ public void run()
+ {
+ for(int i = 0; i < 10; i++)
+ {
+ BeanContext ctx = pool.get();
+ pool.release(ctx);
+
+ ctx = null;
+ used++;
+ }
+ }
+ };
+
+ Thread threads[] = new Thread[20];
+ for(int i = 0; i < threads.length; i++)
+ {
+ threads[i] = new Thread(r);
+ threads[i].start();
+ }
+
+ for(Thread t : threads)
+ {
+ t.join(1000);
+ }
+
+ gc();
+ assertEquals(0, pool.getRemoveCount());
+ assertEquals(0, MockBean.finalizers);
+
+ pool.destroy();
+
+ gc();
+ assertEquals(20, pool.getRemoveCount());
+ assertEquals(20, MockBean.finalizers);
+
+ assertEquals(200, used);
+ }
+
+ public void testMultipleRecursiveWithThreads() throws Exception
+ {
+ final ThreadlocalPool pool = new ThreadlocalPool();
+ Container container = new MockContainer();
+ Class<? extends BeanContext> contextClass = MockBeanContext.class;
+ Class<?> beanClass = null;
+ int maxSize = -1;
+ int timeout = -1;
+ pool.initialize(container, contextClass, beanClass, maxSize, timeout);
+
+ Runnable r = new Runnable()
+ {
+ public void run()
+ {
+ for(int i = 0; i < 10; i++)
+ {
+ BeanContext ctx = pool.get();
+ BeanContext ctx2 = pool.get();
+
+ pool.release(ctx2);
+ ctx2 = null;
+ used ++;
+
+ pool.release(ctx);
+ ctx = null;
+ used ++;
+ }
+ }
+ };
+
+ Thread threads[] = new Thread[20];
+ for(int i = 0; i < threads.length; i++)
+ {
+ threads[i] = new Thread(r);
+ threads[i].start();
+ }
+
+ for(Thread t : threads)
+ {
+ t.join(1000);
+ }
+
+ gc();
+ assertEquals(200, pool.getRemoveCount());
+ assertEquals(200, MockBean.finalizers);
+
+ pool.destroy();
+
+ gc();
+ assertEquals(220, pool.getRemoveCount());
+ assertEquals(220, MockBean.finalizers);
+
+ assertEquals(400, used);
+ }
+
+ @Override
+ protected void tearDown() throws Exception
+ {
+ super.tearDown();
+
+ MockBean.finalizers = 0;
+ used = 0;
+ }
+}
Property changes on: branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/threadlocal/unit/ThreadLocalPoolUnitTestCase.java
___________________________________________________________________
Name: svn:keywords
+ Author Date Id Revision
Name: svn:eol-style
+ native
More information about the jboss-cvs-commits
mailing list