[jboss-cvs] JBossAS SVN: r111745 - projects/jboss-jca/branches/performance/perfenv/src/main/java/org/jboss/jca/performance/perfenv.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Jul 11 12:26:01 EDT 2011


Author: whitingjr
Date: 2011-07-11 12:25:59 -0400 (Mon, 11 Jul 2011)
New Revision: 111745

Added:
   projects/jboss-jca/branches/performance/perfenv/src/main/java/org/jboss/jca/performance/perfenv/AfterTest.java
   projects/jboss-jca/branches/performance/perfenv/src/main/java/org/jboss/jca/performance/perfenv/BeforeTest.java
   projects/jboss-jca/branches/performance/perfenv/src/main/java/org/jboss/jca/performance/perfenv/Registry.java
   projects/jboss-jca/branches/performance/perfenv/src/main/java/org/jboss/jca/performance/perfenv/TestSetUp.java
   projects/jboss-jca/branches/performance/perfenv/src/main/java/org/jboss/jca/performance/perfenv/TestTearDown.java
Modified:
   projects/jboss-jca/branches/performance/perfenv/src/main/java/org/jboss/jca/performance/perfenv/Perf.java
   projects/jboss-jca/branches/performance/perfenv/src/main/java/org/jboss/jca/performance/perfenv/TestRunner.java
Log:
Added support for test lifecycle.

Added: projects/jboss-jca/branches/performance/perfenv/src/main/java/org/jboss/jca/performance/perfenv/AfterTest.java
===================================================================
--- projects/jboss-jca/branches/performance/perfenv/src/main/java/org/jboss/jca/performance/perfenv/AfterTest.java	                        (rev 0)
+++ projects/jboss-jca/branches/performance/perfenv/src/main/java/org/jboss/jca/performance/perfenv/AfterTest.java	2011-07-11 16:25:59 UTC (rev 111745)
@@ -0,0 +1,37 @@
+ /*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2010, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt in the distribution for a
+  * full listing of individual contributors.
+  *
+  * This is free software; you can redistribute it and/or modify it
+  * under the terms of the GNU Lesser General Public License as
+  * published by the Free Software Foundation; either version 2.1 of
+  * the License, or (at your option) any later version.
+  *
+  * This software is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  * Lesser General Public License for more details.
+  *
+  * You should have received a copy of the GNU Lesser General Public
+  * License along with this software; if not, write to the Free
+  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+  */
+
+package org.jboss.jca.performance.perfenv;
+
+import java.io.Serializable;
+
+/**
+ * A AfterTest.
+ * 
+ * @author <a href="jwhiting at redhat.com">Jeremy Whiting</a>
+ * @version $Revision: 1.1 $
+ */
+public interface AfterTest
+{
+
+   public Serializable tearDown() throws Exception;
+}

Added: projects/jboss-jca/branches/performance/perfenv/src/main/java/org/jboss/jca/performance/perfenv/BeforeTest.java
===================================================================
--- projects/jboss-jca/branches/performance/perfenv/src/main/java/org/jboss/jca/performance/perfenv/BeforeTest.java	                        (rev 0)
+++ projects/jboss-jca/branches/performance/perfenv/src/main/java/org/jboss/jca/performance/perfenv/BeforeTest.java	2011-07-11 16:25:59 UTC (rev 111745)
@@ -0,0 +1,36 @@
+ /*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2010, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt in the distribution for a
+  * full listing of individual contributors.
+  *
+  * This is free software; you can redistribute it and/or modify it
+  * under the terms of the GNU Lesser General Public License as
+  * published by the Free Software Foundation; either version 2.1 of
+  * the License, or (at your option) any later version.
+  *
+  * This software is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  * Lesser General Public License for more details.
+  *
+  * You should have received a copy of the GNU Lesser General Public
+  * License along with this software; if not, write to the Free
+  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+  */
+
+package org.jboss.jca.performance.perfenv;
+
+import java.io.Serializable;
+
+/**
+ * A BeforeTest.
+ * 
+ * @author <a href="jwhiting at redhat.com">Jeremy Whiting</a>
+ * @version $Revision: 1.1 $
+ */
+public interface BeforeTest
+{
+   public Serializable setUp(Serializable[] args) throws Exception;
+}

Modified: projects/jboss-jca/branches/performance/perfenv/src/main/java/org/jboss/jca/performance/perfenv/Perf.java
===================================================================
--- projects/jboss-jca/branches/performance/perfenv/src/main/java/org/jboss/jca/performance/perfenv/Perf.java	2011-07-11 16:23:28 UTC (rev 111744)
+++ projects/jboss-jca/branches/performance/perfenv/src/main/java/org/jboss/jca/performance/perfenv/Perf.java	2011-07-11 16:25:59 UTC (rev 111745)
@@ -625,6 +625,8 @@
          communicationServer.registerCommand(new TestRunner());
          communicationServer.registerCommand(new Reload());
          communicationServer.registerCommand(new org.jboss.jca.performance.perfenv.Set());
+         communicationServer.registerCommand(new TestSetUp());
+         communicationServer.registerCommand(new TestTearDown());
 
          communicationServer.start();
          getExecutorService().submit(communicationServer);

Added: projects/jboss-jca/branches/performance/perfenv/src/main/java/org/jboss/jca/performance/perfenv/Registry.java
===================================================================
--- projects/jboss-jca/branches/performance/perfenv/src/main/java/org/jboss/jca/performance/perfenv/Registry.java	                        (rev 0)
+++ projects/jboss-jca/branches/performance/perfenv/src/main/java/org/jboss/jca/performance/perfenv/Registry.java	2011-07-11 16:25:59 UTC (rev 111745)
@@ -0,0 +1,108 @@
+ /*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2011, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt in the distribution for a
+  * full listing of individual contributors.
+  *
+  * This is free software; you can redistribute it and/or modify it
+  * under the terms of the GNU Lesser General Public License as
+  * published by the Free Software Foundation; either version 2.1 of
+  * the License, or (at your option) any later version.
+  *
+  * This software is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  * Lesser General Public License for more details.
+  *
+  * You should have received a copy of the GNU Lesser General Public
+  * License along with this software; if not, write to the Free
+  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+  */
+
+package org.jboss.jca.performance.perfenv;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * A Registry for tests. To be used when tests require setting
+ * up and tearing down.
+ * This registry is not thread safe. The caller should ensure
+ * only one thread calls getInstance.
+ * 
+ * @author <a href="jwhiting at redhat.com">Jeremy Whiting</a>
+ * @version $Revision: 1.1 $
+ */
+public class Registry<T>
+{
+   private static Registry reg;
+   private Map<String, T> testsRegistry;
+   
+   public static Registry getInstance()
+   {
+      if (null == reg)
+      {
+         reg = new Registry();
+      }
+      return reg;
+   }
+   
+   /**
+    * Register a test class.
+    * 
+    * @param test
+    */
+   public void registerTest(T test)
+   {
+      if (!testsRegistry.containsKey(test.getClass().getName()))
+      {
+         testsRegistry.put(test.getClass().getName(), test);
+      }
+   }
+   
+   /**
+    * Remove a registered object.
+    * 
+    * @param test
+    * @return indication of the test existing in the 
+    * registry before removal.
+    */
+   public boolean remove(T test)
+   {
+      boolean isInRegistryBeforehand = testsRegistry.containsKey(test.getClass().getName());
+      testsRegistry.remove(test.getClass().getName());
+      return isInRegistryBeforehand;
+   }
+   
+   /**
+    * Obtain a reference to a registered object.
+    * 
+    * @param type
+    * @return Instance or null reference if not registered
+    */
+   public T getTest(Class<T> type)
+   {
+      return testsRegistry.get(type.getName());
+   }
+   
+   /**
+    * Obtain the reference using the fully qualified class name.
+    * 
+    * @param key
+    * @return an instance or null
+    */
+   public T getTest(String key)
+   {
+      return testsRegistry.get(key);
+   }
+   
+   /**
+    * Create a new Registry.
+    * 
+    */
+   public Registry()
+   {
+      this.testsRegistry = new HashMap<String, T>(1);
+   }
+}

Modified: projects/jboss-jca/branches/performance/perfenv/src/main/java/org/jboss/jca/performance/perfenv/TestRunner.java
===================================================================
--- projects/jboss-jca/branches/performance/perfenv/src/main/java/org/jboss/jca/performance/perfenv/TestRunner.java	2011-07-11 16:23:28 UTC (rev 111744)
+++ projects/jboss-jca/branches/performance/perfenv/src/main/java/org/jboss/jca/performance/perfenv/TestRunner.java	2011-07-11 16:25:59 UTC (rev 111745)
@@ -84,7 +84,14 @@
 
          Class<?> clz = Class.forName(testCase, true, cl);
 
-         Test test = (Test)clz.newInstance();
+         Test test = null;
+         Object obj = Registry.getInstance().getTest(testCase);
+         
+         if (null == obj)
+         {// not registered
+            obj = clz.newInstance();
+         }
+         test = (Test)obj;
 
          Serializable[] testArgs = null;
          if (args.length > 1)

Added: projects/jboss-jca/branches/performance/perfenv/src/main/java/org/jboss/jca/performance/perfenv/TestSetUp.java
===================================================================
--- projects/jboss-jca/branches/performance/perfenv/src/main/java/org/jboss/jca/performance/perfenv/TestSetUp.java	                        (rev 0)
+++ projects/jboss-jca/branches/performance/perfenv/src/main/java/org/jboss/jca/performance/perfenv/TestSetUp.java	2011-07-11 16:25:59 UTC (rev 111745)
@@ -0,0 +1,138 @@
+ /*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2011, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt in the distribution for a
+  * full listing of individual contributors.
+  *
+  * This is free software; you can redistribute it and/or modify it
+  * under the terms of the GNU Lesser General Public License as
+  * published by the Free Software Foundation; either version 2.1 of
+  * the License, or (at your option) any later version.
+  *
+  * This software is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  * Lesser General Public License for more details.
+  *
+  * You should have received a copy of the GNU Lesser General Public
+  * License along with this software; if not, write to the Free
+  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+  */
+
+package org.jboss.jca.performance.perfenv;
+
+import java.io.PrintWriter;
+import java.io.Serializable;
+import java.io.StringWriter;
+import java.util.Arrays;
+
+import org.jboss.logging.Logger;
+
+
+/**
+ * A SetUp.
+ * 
+ * @author <a href="jwhiting at redhat.com">Jeremy Whiting</a>
+ * @version $Revision: 1.1 $
+ */
+public class TestSetUp implements Command
+{
+   /** Command name */
+   private static final String NAME = "setup";
+
+   /** The logger */
+   private static final Logger logger = Logger.getLogger(TestSetUp.class);
+   
+   /**
+    * Constructor
+    */
+   public TestSetUp()
+   {
+   }
+   
+   /**
+    * Get the name of the command
+    * @return The name
+    */
+   public String getName()
+   {
+      return NAME;
+   }
+   
+   /**
+    * Get the parameter types of the command; <code>null</code> if none
+    * @return The types
+    */
+   public Class[] getParameterTypes()
+   {
+      return new Class<?>[] {String.class};
+   }
+
+   /**
+    * Invoke the setup method on the class
+    * @param args The arguments
+    * @return The return value
+    */
+   @SuppressWarnings("unchecked")
+   public Serializable invoke(Serializable[] args)
+   {
+      if (args == null || args.length == 0 || !(args[0] instanceof String))
+         return new IllegalArgumentException("Unsupported argument list: " + Arrays.toString(args));
+
+      String testCase = (String)args[0];
+
+      try
+      {
+         ClassLoader cl = Perf.getActiveClassLoader();
+         Thread.currentThread().setContextClassLoader(cl);
+
+         Class<?> clz = Class.forName(testCase, true, cl);
+         BeforeTest test = (BeforeTest) clz.newInstance();
+         Registry<BeforeTest> registry = (Registry<BeforeTest>)Registry.getInstance();
+         Serializable[] testArgs = null;
+         if (args.length > 1)
+         {
+            testArgs = new Serializable[args.length - 1];
+            for (int i = 1; i < args.length; i++)
+            {
+               testArgs[i - 1] = args[i];
+            }
+         }
+         Serializable returnValue = null;
+         try
+         {
+            returnValue = test.setUp(testArgs);
+            /* the test will not be stored in the registry if it's setup
+             * did not complete. */
+            registry.registerTest(test);
+         } catch (Exception e)
+         {
+            logger.error("Test failed to setup correctly.");
+         }
+
+         return returnValue;
+      }
+      catch (Throwable t)
+      {
+         StringWriter sw = new StringWriter();
+         sw.write(t.getMessage());
+         sw.write('\n');
+
+         t.printStackTrace(new PrintWriter(sw));
+
+         return new Exception(sw.toString());
+      }
+   }
+   
+   /**
+    * Is it a public command
+    * @return True if system-wide; false if internal
+    */
+   public boolean isPublic()
+   {
+      return true;
+   }
+
+   
+}

Added: projects/jboss-jca/branches/performance/perfenv/src/main/java/org/jboss/jca/performance/perfenv/TestTearDown.java
===================================================================
--- projects/jboss-jca/branches/performance/perfenv/src/main/java/org/jboss/jca/performance/perfenv/TestTearDown.java	                        (rev 0)
+++ projects/jboss-jca/branches/performance/perfenv/src/main/java/org/jboss/jca/performance/perfenv/TestTearDown.java	2011-07-11 16:25:59 UTC (rev 111745)
@@ -0,0 +1,119 @@
+ /*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2011, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt in the distribution for a
+  * full listing of individual contributors.
+  *
+  * This is free software; you can redistribute it and/or modify it
+  * under the terms of the GNU Lesser General Public License as
+  * published by the Free Software Foundation; either version 2.1 of
+  * the License, or (at your option) any later version.
+  *
+  * This software is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  * Lesser General Public License for more details.
+  *
+  * You should have received a copy of the GNU Lesser General Public
+  * License along with this software; if not, write to the Free
+  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+  */
+
+package org.jboss.jca.performance.perfenv;
+
+import java.io.PrintWriter;
+import java.io.Serializable;
+import java.io.StringWriter;
+import java.util.Arrays;
+
+import org.jboss.logging.Logger;
+
+/**
+ * A TearDown.
+ * 
+ * @author <a href="jwhiting at redhat.com">Jeremy Whiting</a>
+ * @version $Revision: 1.1 $
+ */
+public class TestTearDown implements Command
+{
+
+   /** Command name */
+   private static final String NAME = "teardown";
+
+   /** The logger */
+   private static final Logger logger = Logger.getLogger(TestSetUp.class);
+   
+   /**
+    * Constructor
+    */
+   public TestTearDown()
+   {
+   }
+   
+   /**
+    * Get the name of the command
+    * @return The name
+    */
+   public String getName()
+   {
+      return NAME;
+   }
+   
+   /**
+    * Get the parameter types of the command; <code>null</code> if none
+    * @return The types
+    */
+   public Class[] getParameterTypes()
+   {
+      return new Class<?>[] {String.class};
+   }
+
+   /**
+    * Invoke the setup method on the class
+    * @param args The arguments
+    * @return The return value
+    */
+   @SuppressWarnings("unchecked")
+   public Serializable invoke(Serializable[] args)
+   {
+      if (args == null || args.length == 0 || !(args[0] instanceof String))
+         return new IllegalArgumentException("Unsupported argument list: " + Arrays.toString(args));
+
+      String testCase = (String)args[0];
+
+      try
+      {
+         ClassLoader cl = Perf.getActiveClassLoader();
+         Thread.currentThread().setContextClassLoader(cl);
+
+         Class<?> clz = Class.forName(testCase, true, cl);
+         AfterTest test = (AfterTest)clz.newInstance();
+         Registry<AfterTest> registry = (Registry<AfterTest>)Registry.getInstance(); 
+         registry.remove(test);
+
+         return test.tearDown();
+      }
+      catch (Throwable t)
+      {
+         StringWriter sw = new StringWriter();
+         sw.write(t.getMessage());
+         sw.write('\n');
+
+         t.printStackTrace(new PrintWriter(sw));
+
+         return new Exception(sw.toString());
+      }
+   }
+   
+   /**
+    * Is it a public command
+    * @return True if system-wide; false if internal
+    */
+   public boolean isPublic()
+   {
+      return true;
+   }
+
+
+}



More information about the jboss-cvs-commits mailing list