[jboss-cvs] JBossAS SVN: r67804 - in branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test: threadlocal and 1 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Dec 3 15:33:49 EST 2007


Author: bdecoste
Date: 2007-12-03 15:33:48 -0500 (Mon, 03 Dec 2007)
New Revision: 67804

Added:
   branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/threadlocal/
   branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/threadlocal/MockBean.java
   branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/threadlocal/MockBeanContext.java
   branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/threadlocal/MockContainer.java
   branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/threadlocal/unit/
   branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/threadlocal/unit/ThreadLocalPoolUnitTestCase.java
Log:
[JBPAPP-478] merged tests

Added: branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/threadlocal/MockBean.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/threadlocal/MockBean.java	                        (rev 0)
+++ branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/threadlocal/MockBean.java	2007-12-03 20:33:48 UTC (rev 67804)
@@ -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: 64706 $
+ */
+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");
+   }
+}

Added: branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/threadlocal/MockBeanContext.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/threadlocal/MockBeanContext.java	                        (rev 0)
+++ branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/threadlocal/MockBeanContext.java	2007-12-03 20:33:48 UTC (rev 67804)
@@ -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: 64706 $
+ */
+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;
+   }
+
+}

Added: branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/threadlocal/MockContainer.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/threadlocal/MockContainer.java	                        (rev 0)
+++ branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/threadlocal/MockContainer.java	2007-12-03 20:33:48 UTC (rev 67804)
@@ -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: 64706 $
+ */
+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
+
+   }
+
+}

Added: branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/threadlocal/unit/ThreadLocalPoolUnitTestCase.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/threadlocal/unit/ThreadLocalPoolUnitTestCase.java	                        (rev 0)
+++ branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/threadlocal/unit/ThreadLocalPoolUnitTestCase.java	2007-12-03 20:33:48 UTC (rev 67804)
@@ -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: 64706 $
+ */
+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;
+   }
+}




More information about the jboss-cvs-commits mailing list