[jboss-cvs] JBossAS SVN: r64939 - in trunk/ejb3/src/test/org/jboss/ejb3/test/stateless: unit and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue Aug 28 20:07:42 EDT 2007


Author: bdecoste
Date: 2007-08-28 20:07:42 -0400 (Tue, 28 Aug 2007)
New Revision: 64939

Added:
   trunk/ejb3/src/test/org/jboss/ejb3/test/stateless/DefaultPoolStatelessBean.java
   trunk/ejb3/src/test/org/jboss/ejb3/test/stateless/StatelessRemote.java
   trunk/ejb3/src/test/org/jboss/ejb3/test/stateless/StrictMaxPoolStatelessBean.java
   trunk/ejb3/src/test/org/jboss/ejb3/test/stateless/unit/MetricsUnitTestCase.java
Log:
[EJBTHREE-1031] [EJBTHREE-1032] additional tests for stateless pool creation and consistent pool metrics

Added: trunk/ejb3/src/test/org/jboss/ejb3/test/stateless/DefaultPoolStatelessBean.java
===================================================================
--- trunk/ejb3/src/test/org/jboss/ejb3/test/stateless/DefaultPoolStatelessBean.java	                        (rev 0)
+++ trunk/ejb3/src/test/org/jboss/ejb3/test/stateless/DefaultPoolStatelessBean.java	2007-08-29 00:07:42 UTC (rev 64939)
@@ -0,0 +1,53 @@
+/*
+ * 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.stateless;
+
+import javax.ejb.Stateless;
+import javax.ejb.Remote;
+
+import org.jboss.annotation.ejb.PoolClass;
+import org.jboss.ejb3.StrictMaxPool;
+import org.jboss.logging.Logger;
+
+/**
+ * @author <a href="mailto:bdecoste at jboss.com">William DeCoste</a>
+ */
+ at Stateless
+ at Remote(StatelessRemote.class)
+public class DefaultPoolStatelessBean implements StatelessRemote
+{
+   private static final Logger log = Logger.getLogger(DefaultPoolStatelessBean.class);
+   
+   public void test() 
+   {
+   }
+   
+   public void testException() 
+   {
+      throw new RuntimeException();
+   }
+   
+   public void delay() throws Exception
+   {
+      Thread.sleep(30 * 1000);
+   }
+}

Added: trunk/ejb3/src/test/org/jboss/ejb3/test/stateless/StatelessRemote.java
===================================================================
--- trunk/ejb3/src/test/org/jboss/ejb3/test/stateless/StatelessRemote.java	                        (rev 0)
+++ trunk/ejb3/src/test/org/jboss/ejb3/test/stateless/StatelessRemote.java	2007-08-29 00:07:42 UTC (rev 64939)
@@ -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.stateless;
+
+/**
+ * @author <a href="mailto:bdecoste at jboss.com">William DeCoste</a>
+ */
+public interface StatelessRemote
+{
+   void test();
+   
+   void testException();
+   
+   void delay() throws Exception;
+}

Added: trunk/ejb3/src/test/org/jboss/ejb3/test/stateless/StrictMaxPoolStatelessBean.java
===================================================================
--- trunk/ejb3/src/test/org/jboss/ejb3/test/stateless/StrictMaxPoolStatelessBean.java	                        (rev 0)
+++ trunk/ejb3/src/test/org/jboss/ejb3/test/stateless/StrictMaxPoolStatelessBean.java	2007-08-29 00:07:42 UTC (rev 64939)
@@ -0,0 +1,54 @@
+/*
+ * 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.stateless;
+
+import javax.ejb.Stateless;
+import javax.ejb.Remote;
+
+import org.jboss.annotation.ejb.PoolClass;
+import org.jboss.ejb3.StrictMaxPool;
+import org.jboss.logging.Logger;
+
+/**
+ * @author <a href="mailto:bdecoste at jboss.com">William DeCoste</a>
+ */
+ at Stateless
+ at Remote(StatelessRemote.class)
+ at PoolClass (value=StrictMaxPool.class, maxSize=3, timeout=1000)
+public class StrictMaxPoolStatelessBean implements StatelessRemote
+{
+   private static final Logger log = Logger.getLogger(StrictMaxPoolStatelessBean.class);
+   
+   public void test() 
+   {
+   }
+   
+   public void testException() 
+   {
+      throw new RuntimeException();
+   }
+   
+   public void delay() throws Exception
+   {
+      Thread.sleep(30 * 1000);
+   }
+}

Added: trunk/ejb3/src/test/org/jboss/ejb3/test/stateless/unit/MetricsUnitTestCase.java
===================================================================
--- trunk/ejb3/src/test/org/jboss/ejb3/test/stateless/unit/MetricsUnitTestCase.java	                        (rev 0)
+++ trunk/ejb3/src/test/org/jboss/ejb3/test/stateless/unit/MetricsUnitTestCase.java	2007-08-29 00:07:42 UTC (rev 64939)
@@ -0,0 +1,234 @@
+/*
+ * 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.stateless.unit;
+
+import javax.management.MBeanServerConnection;
+import javax.management.ObjectName;
+
+import org.jboss.ejb3.test.stateless.StatelessRemote;
+import org.jboss.logging.Logger;
+import org.jboss.test.JBossTestCase;
+import junit.framework.Test;
+
+
+/**
+ * @author <a href="mailto:bdecoste at jboss.com">William DeCoste</a>
+ */
+public class MetricsUnitTestCase
+extends JBossTestCase
+{
+   private static final Logger log = Logger.getLogger(MetricsUnitTestCase.class);
+
+   public MetricsUnitTestCase(String name)
+   {
+      super(name);
+   }
+   
+   public void testDefaultJmxMetrics() throws Exception
+   {
+      MBeanServerConnection server = getServer();
+      ObjectName testerName = new ObjectName("jboss.j2ee:jar=stateless-test.jar,name=DefaultPoolStatelessBean,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("DefaultPoolStatelessBean/remote");
+      assertNotNull(stateless);
+      stateless.test();     
+      
+      size = (Integer)server.getAttribute(testerName, "CurrentSize");
+      assertEquals(1, size);
+      
+      size = (Integer)server.getAttribute(testerName, "AvailableCount");
+      assertEquals(30, size);
+      
+      size = (Integer)server.getAttribute(testerName, "MaxSize");
+      assertEquals(30, size);
+      
+      size = (Integer)server.getAttribute(testerName, "CreateCount");
+      assertEquals(1, size);
+      
+      size = (Integer)server.getAttribute(testerName, "RemoveCount");
+      assertEquals(0, size);
+      
+   }
+   
+   public void testStrictMaxPoolJmxMetrics() throws Exception
+   {
+      MBeanServerConnection server = getServer();
+      ObjectName testerName = new ObjectName("jboss.j2ee:jar=stateless-test.jar,name=StrictMaxPoolStatelessBean,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("StrictMaxPoolStatelessBean/remote");
+      assertNotNull(stateless);
+      stateless.test();     
+      
+      size = (Integer)server.getAttribute(testerName, "CurrentSize");
+      assertEquals(1, size);
+      
+      size = (Integer)server.getAttribute(testerName, "AvailableCount");
+      assertEquals(3, size);
+      
+      size = (Integer)server.getAttribute(testerName, "MaxSize");
+      assertEquals(3, size);
+      
+      size = (Integer)server.getAttribute(testerName, "CreateCount");
+      assertEquals(1, size);
+      
+      runConcurrentTests(20, 1);
+      
+      int currentSize = (Integer)server.getAttribute(testerName, "CurrentSize");
+      assertEquals(1, size);
+      
+      checkMetrics(server, testerName, currentSize, 3, 3, currentSize, 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);
+      
+      currentSize = (Integer)server.getAttribute(testerName, "CurrentSize");
+      assertEquals(1, size);
+      
+      checkMetrics(server, testerName, currentSize, 3, 3, currentSize + 10, 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 maxSize = (Integer)server.getAttribute(testerName, "MaxSize");
+      System.out.println("MaxSize=" + maxSize);
+      
+      int availableCount = (Integer)server.getAttribute(testerName, "AvailableCount");
+      System.out.println("AvailableCount=" + availableCount);
+     
+      assertEquals(maxSize - 1, 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 < 25 ; ++i)
+                  {                  
+                     stateless.test();     
+                  }
+               }
+               catch (Exception e)
+               {
+                  e.printStackTrace();
+               }
+            }
+         };
+         
+         new Thread(r).start();
+      }
+      
+      Thread.sleep(sleepSecs * 60 * 1000);  
+   }
+
+   public static Test suite() throws Exception
+   {
+      return getDeploySetup(MetricsUnitTestCase.class, "stateless-test.jar");
+   }
+
+}




More information about the jboss-cvs-commits mailing list