[jboss-cvs] JBossAS SVN: r111746 - in projects/jboss-jca/branches/performance: perfenv/src/main/java/org/jboss/jca/performance/perfenv and 2 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue Jul 12 09:07:09 EDT 2011
Author: jesper.pedersen
Date: 2011-07-12 09:07:08 -0400 (Tue, 12 Jul 2011)
New Revision: 111746
Added:
projects/jboss-jca/branches/performance/perfenv/src/main/java/org/jboss/jca/performance/perfenv/Driver.java
projects/jboss-jca/branches/performance/perfenv/src/main/java/org/jboss/jca/performance/perfenv/tests/TimedDatabaseTester.java
projects/jboss-jca/branches/performance/perfenv/src/main/resources/driver.sh
Removed:
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
Modified:
projects/jboss-jca/branches/performance/doc/perfguide/en-US/modules/perfenv.xml
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/Registry.java
projects/jboss-jca/branches/performance/perfenv/src/main/java/org/jboss/jca/performance/perfenv/Test.java
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/TestSetUp.java
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/tests/DatabaseTester.java
projects/jboss-jca/branches/performance/perfenv/src/main/java/org/jboss/jca/performance/perfenv/tests/RampDatabaseTester.java
projects/jboss-jca/branches/performance/perfenv/src/main/resources/perf.sh
Log:
Add driver, and merge BeforeTest / AfterTest into Test
Modified: projects/jboss-jca/branches/performance/doc/perfguide/en-US/modules/perfenv.xml
===================================================================
--- projects/jboss-jca/branches/performance/doc/perfguide/en-US/modules/perfenv.xml 2011-07-11 16:25:59 UTC (rev 111745)
+++ projects/jboss-jca/branches/performance/doc/perfguide/en-US/modules/perfenv.xml 2011-07-12 13:07:08 UTC (rev 111746)
@@ -151,7 +151,9 @@
reload
run <java.lang.String>
set <java.lang.String> <java.lang.String>
+setup <java.lang.String>
shutdown
+teardown <java.lang.String>
undeploy <java.lang.String>
</programlisting>
@@ -186,11 +188,15 @@
<para>An example of running a H2 test case:</para>
<programlisting>
-./cli.sh deactivate # Deactivates current profile
-./cli.sh activate daily false # Activates 'daily' profile using NoopTS
-./cli.sh deploy jdbc-local.rar # Deploys jdbc-local.rar artifact
-./cli.sh deploy h2-ds.xml # Deploys h2-ds.xml artifact
-./cli.sh run MyH2Test # Runs MyH2Test (fully qualified class name)
+./cli.sh activate daily false # Activates 'daily' profile using NoopTS
+./cli.sh deploy jdbc-local.rar # Deploys jdbc-local.rar artifact
+./cli.sh deploy h2-ds.xml # Deploys h2-ds.xml artifact
+./cli.sh setup MyH2Test # Setup MyH2Test (fully qualified class name)
+./cli.sh run MyH2Test # Runs MyH2Test (fully qualified class name)
+./cli.sh teardown MyH2Test # Teardown MyH2Test (fully qualified class name)
+./cli.sh undeploy h2-ds.xml # Undeploys h2-ds.xml artifact
+./cli.sh undeploy jdbc-local.rar # Undeploys jdbc-local.rar artifact
+./cli.sh deactivate # Deactivates current profile
</programlisting>
</section>
Deleted: 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 2011-07-11 16:25:59 UTC (rev 111745)
+++ projects/jboss-jca/branches/performance/perfenv/src/main/java/org/jboss/jca/performance/perfenv/AfterTest.java 2011-07-12 13:07:08 UTC (rev 111746)
@@ -1,37 +0,0 @@
- /*
- * 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;
-}
Deleted: 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 2011-07-11 16:25:59 UTC (rev 111745)
+++ projects/jboss-jca/branches/performance/perfenv/src/main/java/org/jboss/jca/performance/perfenv/BeforeTest.java 2011-07-12 13:07:08 UTC (rev 111746)
@@ -1,36 +0,0 @@
- /*
- * 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;
-}
Added: projects/jboss-jca/branches/performance/perfenv/src/main/java/org/jboss/jca/performance/perfenv/Driver.java
===================================================================
--- projects/jboss-jca/branches/performance/perfenv/src/main/java/org/jboss/jca/performance/perfenv/Driver.java (rev 0)
+++ projects/jboss-jca/branches/performance/perfenv/src/main/java/org/jboss/jca/performance/perfenv/Driver.java 2011-07-12 13:07:08 UTC (rev 111746)
@@ -0,0 +1,588 @@
+ /*
+ * 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 org.jboss.jca.performance.perfenv.Test;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.PrintWriter;
+import java.io.Serializable;
+import java.io.StringWriter;
+import java.net.Socket;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.Properties;
+import java.util.StringTokenizer;
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.concurrent.atomic.AtomicLong;
+
+/**
+ * A driver for perfenv based tests.
+ *
+ * @author <a href="jesper.pedersen at jboss.org">Jesper Pedersen</a>
+ */
+public class Driver
+{
+ /**
+ * Main
+ */
+ public static void main(String[] args)
+ {
+ try
+ {
+ Properties prop = new Properties();
+
+ File f = new File("driver.properties");
+ if (f.exists())
+ {
+ FileInputStream fis = new FileInputStream(f);
+ prop.load(fis);
+ fis.close();
+ }
+
+ String host = prop.getProperty("host", "localhost");
+ int port = Integer.valueOf(prop.getProperty("port", "7000"));
+ String profile = prop.getProperty("profile", "1.0.0.Final");
+ boolean realtx = Boolean.valueOf(prop.getProperty("realtx", "false"));
+ String testClass = prop.getProperty("test", "org.jboss.jca.performance.perfenv.tests.TimedDatabaseTester");
+ String dbJndi = prop.getProperty("db", "java:/NoopDS");
+
+ List<String> deployments = new ArrayList<String>();
+
+ String s = prop.getProperty("deployments", "jdbc-local.rar,noopdb-ds.xml");
+ StringTokenizer st = new StringTokenizer(s, ",");
+ while (st.hasMoreTokens())
+ {
+ String token = st.nextToken();
+ deployments.add(token.trim());
+ }
+
+ int maxThreads = Integer.valueOf(prop.getProperty("threads", "1"));
+ int rampUp = Integer.valueOf(prop.getProperty("rampup", "1"));
+ int testPeriod = Integer.valueOf(prop.getProperty("testperiod", "1"));
+ int rampDown = Integer.valueOf(prop.getProperty("rampdown", "1"));
+
+ System.out.println("Server : " + host + ":" + port);
+ System.out.println("Profile: " + profile);
+ System.out.println("Threads: " + maxThreads);
+ System.out.println("Test : " + testClass);
+
+ doActivate(host, port, profile, realtx);
+ doDeploy(host, port, deployments);
+ doSetup(host, port, testClass, dbJndi);
+
+ long rampUpStart = System.currentTimeMillis();
+ execute(rampUp * 60000, maxThreads, host, port, testClass);
+ long rampUpEnd = System.currentTimeMillis();
+
+ long testPeriodStart = System.currentTimeMillis();
+ double d = execute(testPeriod * 60000, maxThreads, host, port, testClass);
+ long testPeriodEnd = System.currentTimeMillis();
+
+ long rampDownStart = System.currentTimeMillis();
+ execute(rampDown * 60000, maxThreads, host, port, testClass);
+ long rampDownEnd = System.currentTimeMillis();
+
+ long elapsed = testPeriodEnd - testPeriodStart;
+ if (elapsed <= 0)
+ elapsed = 1;
+
+ System.out.println("");
+ System.out.println("Result");
+ System.out.println("======");
+ System.out.println("Ramp up : " + (rampUpEnd - rampUpStart) + " ms");
+ System.out.println("Test : " + (testPeriodEnd - testPeriodStart) + " ms");
+ System.out.println("Ramp down: " + (rampDownEnd - rampDownStart) + " ms");
+ System.out.println("Ops/sec : " + (long)d);
+
+ Collections.reverse(deployments);
+
+ doTeardown(host, port, testClass);
+ doUndeploy(host, port, deployments);
+ doDeactivate(host, port);
+ }
+ catch (Throwable t)
+ {
+ t.printStackTrace();
+ }
+ }
+
+ /**
+ * Activate
+ * @param host The host
+ * @param port The port
+ * @param profile The profile
+ * @param realtx Should a real transaction manager be used
+ */
+ private static void doActivate(String host, int port, String profile, boolean realtx)
+ {
+ Socket socket = null;
+
+ try
+ {
+ socket = new Socket(host, port);
+
+ ObjectOutputStream oos = new ObjectOutputStream(socket.getOutputStream());
+
+ oos.writeUTF("activate");
+ oos.writeInt(2);
+ oos.writeObject(profile);
+ oos.writeObject(realtx ? Boolean.TRUE : Boolean.FALSE);
+
+ oos.flush();
+
+ ObjectInputStream ois = new ObjectInputStream(socket.getInputStream());
+
+ Serializable result = (Serializable)ois.readObject();
+ if (result != null && result instanceof Throwable)
+ {
+ Throwable throwable = (Throwable)result;
+ throwable.printStackTrace();
+ }
+ }
+ catch (Throwable t)
+ {
+ t.printStackTrace();
+ }
+ finally
+ {
+ if (socket != null)
+ {
+ try
+ {
+ socket.close();
+ }
+ catch (Throwable ignore)
+ {
+ // Ignore
+ }
+ }
+ }
+ }
+
+ /**
+ * Deploy
+ * @param host The host
+ * @param port The port
+ * @param deployments The deployments
+ */
+ private static void doDeploy(String host, int port, List<String> deployments)
+ {
+ for (String deployment : deployments)
+ {
+ Socket socket = null;
+
+ try
+ {
+ socket = new Socket(host, port);
+
+ ObjectOutputStream oos = new ObjectOutputStream(socket.getOutputStream());
+
+ oos.writeUTF("deploy");
+ oos.writeInt(1);
+ oos.writeObject(deployment);
+
+ oos.flush();
+
+ ObjectInputStream ois = new ObjectInputStream(socket.getInputStream());
+
+ Serializable result = (Serializable)ois.readObject();
+ if (result != null && result instanceof Throwable)
+ {
+ Throwable throwable = (Throwable)result;
+ throwable.printStackTrace();
+ }
+ }
+ catch (Throwable t)
+ {
+ t.printStackTrace();
+ }
+ finally
+ {
+ if (socket != null)
+ {
+ try
+ {
+ socket.close();
+ }
+ catch (Throwable ignore)
+ {
+ // Ignore
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * Setup
+ * @param host The host
+ * @param port The port
+ * @param testClass The test class
+ * @param dbJndi The JNDI name of the database
+ */
+ private static void doSetup(String host, int port, String testClass, String dbJndi)
+ {
+ Socket socket = null;
+
+ try
+ {
+ socket = new Socket(host, port);
+
+ ObjectOutputStream oos = new ObjectOutputStream(socket.getOutputStream());
+
+ oos.writeUTF("setup");
+ oos.writeInt(2);
+ oos.writeObject(testClass);
+ oos.writeObject(dbJndi);
+
+ oos.flush();
+
+ ObjectInputStream ois = new ObjectInputStream(socket.getInputStream());
+
+ Serializable result = (Serializable)ois.readObject();
+ if (result != null && result instanceof Throwable)
+ {
+ Throwable throwable = (Throwable)result;
+ throwable.printStackTrace();
+ }
+ }
+ catch (Throwable t)
+ {
+ t.printStackTrace();
+ }
+ finally
+ {
+ if (socket != null)
+ {
+ try
+ {
+ socket.close();
+ }
+ catch (Throwable ignore)
+ {
+ // Ignore
+ }
+ }
+ }
+ }
+
+ /**
+ * Teardown
+ * @param host The host
+ * @param port The port
+ * @param testClass The test class
+ */
+ private static void doTeardown(String host, int port, String testClass)
+ {
+ Socket socket = null;
+
+ try
+ {
+ socket = new Socket(host, port);
+
+ ObjectOutputStream oos = new ObjectOutputStream(socket.getOutputStream());
+
+ oos.writeUTF("teardown");
+ oos.writeInt(1);
+ oos.writeObject(testClass);
+
+ oos.flush();
+
+ ObjectInputStream ois = new ObjectInputStream(socket.getInputStream());
+
+ Serializable result = (Serializable)ois.readObject();
+ if (result != null && result instanceof Throwable)
+ {
+ Throwable throwable = (Throwable)result;
+ throwable.printStackTrace();
+ }
+ }
+ catch (Throwable t)
+ {
+ t.printStackTrace();
+ }
+ finally
+ {
+ if (socket != null)
+ {
+ try
+ {
+ socket.close();
+ }
+ catch (Throwable ignore)
+ {
+ // Ignore
+ }
+ }
+ }
+ }
+
+ /**
+ * Undeploy
+ * @param host The host
+ * @param port The port
+ * @param deployments The deployments
+ */
+ private static void doUndeploy(String host, int port, List<String> deployments)
+ {
+ for (String deployment : deployments)
+ {
+ Socket socket = null;
+
+ try
+ {
+ socket = new Socket(host, port);
+
+ ObjectOutputStream oos = new ObjectOutputStream(socket.getOutputStream());
+
+ oos.writeUTF("undeploy");
+ oos.writeInt(1);
+ oos.writeObject(deployment);
+
+ oos.flush();
+
+ ObjectInputStream ois = new ObjectInputStream(socket.getInputStream());
+
+ Serializable result = (Serializable)ois.readObject();
+ if (result != null && result instanceof Throwable)
+ {
+ Throwable throwable = (Throwable)result;
+ throwable.printStackTrace();
+ }
+ }
+ catch (Throwable t)
+ {
+ t.printStackTrace();
+ }
+ finally
+ {
+ if (socket != null)
+ {
+ try
+ {
+ socket.close();
+ }
+ catch (Throwable ignore)
+ {
+ // Ignore
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * Deactivate
+ * @param host The host
+ * @param port The port
+ */
+ private static void doDeactivate(String host, int port)
+ {
+ Socket socket = null;
+
+ try
+ {
+ socket = new Socket(host, port);
+
+ ObjectOutputStream oos = new ObjectOutputStream(socket.getOutputStream());
+
+ oos.writeUTF("deactivate");
+ oos.writeInt(0);
+
+ oos.flush();
+
+ ObjectInputStream ois = new ObjectInputStream(socket.getInputStream());
+
+ Serializable result = (Serializable)ois.readObject();
+ if (result != null && result instanceof Throwable)
+ {
+ Throwable throwable = (Throwable)result;
+ throwable.printStackTrace();
+ }
+ }
+ catch (Throwable t)
+ {
+ t.printStackTrace();
+ }
+ finally
+ {
+ if (socket != null)
+ {
+ try
+ {
+ socket.close();
+ }
+ catch (Throwable ignore)
+ {
+ // Ignore
+ }
+ }
+ }
+ }
+
+ /**
+ * Execute for a duration
+ * @param duration The duration of execution
+ * @param maxThreads The maximum number of threads
+ * @param host The host
+ * @param port The port
+ * @param testClass The test class name
+ * @return The ops/sec
+ */
+ private static double execute(long duration, int maxThreads, String host, int port, String testClass)
+ {
+ AtomicInteger counter = new AtomicInteger(0);
+ AtomicLong time = new AtomicLong(0);
+
+ if (maxThreads != 1)
+ {
+ try
+ {
+ BlockingQueue<Runnable> threadPoolQueue = new LinkedBlockingQueue<Runnable>();
+ ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(maxThreads, maxThreads,
+ 60, TimeUnit.SECONDS,
+ threadPoolQueue);
+
+ threadPoolExecutor.allowCoreThreadTimeOut(true);
+ threadPoolExecutor.prestartAllCoreThreads();
+
+ long start = System.currentTimeMillis();
+ long now = start;
+
+ while ((now - start) < duration)
+ {
+ if (threadPoolQueue.size() < maxThreads)
+ {
+ Tester tester = new Tester(host, port, testClass, counter, time);
+ threadPoolExecutor.submit(tester);
+ }
+
+ now = System.currentTimeMillis();
+ }
+
+ threadPoolExecutor.shutdown();
+ }
+ catch (Throwable t)
+ {
+ // Ignore
+ }
+ }
+ else
+ {
+ Tester tester = new Tester(host, port, testClass, counter, time);
+
+ long start = System.currentTimeMillis();
+ long now = start;
+
+ while ((now - start) < duration)
+ {
+ tester.run();
+ now = System.currentTimeMillis();
+ }
+ }
+
+ return ((counter.get() * 1000) / (double)time.get());
+ }
+
+
+ /**
+ * Test class
+ */
+ private static class Tester implements Runnable
+ {
+ private String host;
+ private int port;
+ private String testClass;
+
+ private AtomicInteger counter;
+ private AtomicLong time;
+
+ Tester(String host, int port, String testClass, AtomicInteger counter, AtomicLong time)
+ {
+ this.host = host;
+ this.port = port;
+ this.testClass = testClass;
+ this.counter = counter;
+ this.time = time;
+ }
+
+ public void run()
+ {
+ Socket socket = null;
+
+ try
+ {
+ socket = new Socket(host, port);
+
+ ObjectOutputStream oos = new ObjectOutputStream(socket.getOutputStream());
+
+ oos.writeUTF("run");
+ oos.writeInt(1);
+ oos.writeObject(testClass);
+
+ oos.flush();
+
+ ObjectInputStream ois = new ObjectInputStream(socket.getInputStream());
+
+ Long result = (Long)ois.readObject();
+
+ if (result != null)
+ {
+ counter.incrementAndGet();
+ time.addAndGet(result.longValue());
+ }
+ }
+ catch (Throwable t)
+ {
+ // Nothing to do
+ }
+ finally
+ {
+ if (socket != null)
+ {
+ try
+ {
+ socket.close();
+ }
+ catch (Throwable ignore)
+ {
+ // Ignore
+ }
+ }
+ }
+ }
+ }
+}
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:25:59 UTC (rev 111745)
+++ projects/jboss-jca/branches/performance/perfenv/src/main/java/org/jboss/jca/performance/perfenv/Perf.java 2011-07-12 13:07:08 UTC (rev 111746)
@@ -572,6 +572,23 @@
String hostname = "localhost";
int hostport = 7000;
+ if (args != null && args.length > 0)
+ {
+ for (int i = 0; i < args.length; i++)
+ {
+ if ("-host".equals(args[i]))
+ {
+ hostname = args[i + 1];
+ i++;
+ }
+ else if ("-port".equals(args[i]))
+ {
+ hostport = Integer.valueOf(args[i + 1]);
+ i++;
+ }
+ }
+ }
+
LifeThread lifeThread = new LifeThread();
lifeThread.start();
Modified: 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 2011-07-11 16:25:59 UTC (rev 111745)
+++ projects/jboss-jca/branches/performance/perfenv/src/main/java/org/jboss/jca/performance/perfenv/Registry.java 2011-07-12 13:07:08 UTC (rev 111746)
@@ -24,6 +24,7 @@
import java.util.HashMap;
import java.util.Map;
+import java.util.concurrent.atomic.AtomicInteger;
/**
* A Registry for tests. To be used when tests require setting
@@ -34,75 +35,96 @@
* @author <a href="jwhiting at redhat.com">Jeremy Whiting</a>
* @version $Revision: 1.1 $
*/
-public class Registry<T>
+public class Registry
{
- private static Registry reg;
- private Map<String, T> testsRegistry;
+ private static Registry registry = new Registry();
+ private Map<String, Test> testsRegistry;
+ private Map<String, AtomicInteger> testsRunners;
+ /**
+ * Constructor
+ */
+ private Registry()
+ {
+ this.testsRegistry = new HashMap<String, Test>(1);
+ this.testsRunners = new HashMap<String, AtomicInteger>(1);
+ }
+
+ /**
+ * Get the instance
+ * @return The value
+ */
public static Registry getInstance()
{
- if (null == reg)
- {
- reg = new Registry();
- }
- return reg;
+ return registry;
}
/**
* Register a test class.
- *
- * @param test
+ * @param test The test instance
*/
- public void registerTest(T test)
+ public void addTest(Test test)
{
- if (!testsRegistry.containsKey(test.getClass().getName()))
- {
- testsRegistry.put(test.getClass().getName(), test);
- }
+ testsRegistry.put(test.getClass().getName(), test);
+ testsRunners.put(test.getClass().getName(), new AtomicInteger(0));
}
/**
* Remove a registered object.
- *
- * @param test
- * @return indication of the test existing in the
- * registry before removal.
+ * @param test The test instance
+ * @return indication of the test existing in the registry before removal.
*/
- public boolean remove(T test)
+ public boolean removeTest(Test test)
{
boolean isInRegistryBeforehand = testsRegistry.containsKey(test.getClass().getName());
testsRegistry.remove(test.getClass().getName());
+ testsRunners.remove(test.getClass().getName());
return isInRegistryBeforehand;
}
/**
- * Obtain a reference to a registered object.
- *
- * @param type
- * @return Instance or null reference if not registered
+ * Obtain the reference using the fully qualified class name.
+ * @param key The class name
+ * @return The value
*/
- public T getTest(Class<T> type)
+ public Test getTest(String key)
{
- return testsRegistry.get(type.getName());
+ return testsRegistry.get(key);
}
+
+ /**
+ * Add a runner
+ * @param test The test
+ */
+ public void addRunner(String test)
+ {
+ AtomicInteger i = testsRunners.get(test);
+ if (i != null)
+ i.incrementAndGet();
+ }
/**
- * Obtain the reference using the fully qualified class name.
- *
- * @param key
- * @return an instance or null
+ * Remove a runner
+ * @param test The test
*/
- public T getTest(String key)
+ public void removeRunner(String test)
{
- return testsRegistry.get(key);
+ AtomicInteger i = testsRunners.get(test);
+ if (i != null)
+ i.decrementAndGet();
}
/**
- * Create a new Registry.
- *
+ * Get the number of runners
+ * @param test The class name
+ * @return The value
*/
- public Registry()
+ public int getRunners(String test)
{
- this.testsRegistry = new HashMap<String, T>(1);
+ AtomicInteger i = testsRunners.get(test);
+ if (i != null)
+ return i.get();
+
+ return 0;
}
}
Modified: projects/jboss-jca/branches/performance/perfenv/src/main/java/org/jboss/jca/performance/perfenv/Test.java
===================================================================
--- projects/jboss-jca/branches/performance/perfenv/src/main/java/org/jboss/jca/performance/perfenv/Test.java 2011-07-11 16:25:59 UTC (rev 111745)
+++ projects/jboss-jca/branches/performance/perfenv/src/main/java/org/jboss/jca/performance/perfenv/Test.java 2011-07-12 13:07:08 UTC (rev 111746)
@@ -27,12 +27,34 @@
* Represents a performance test
* @author <a href="mailto:jesper.pedersen at jboss.org">Jesper Pedersen</a>
*/
-public interface Test
+public interface Test extends Cloneable
{
/**
+ * Setup
+ * @param args The arguments
+ * @return The result of the run
+ */
+ public Serializable setup(Serializable[] args);
+
+ /**
* Run
* @param args The arguments
* @return The result of the run
*/
public Serializable run(Serializable[] args);
+
+ /**
+ * Teardown
+ * @param args The arguments
+ * @return The result of the run
+ */
+ public Serializable teardown(Serializable[] args);
+
+ /**
+ * Clone the test implementation
+ * @return A copy of the test
+ * @exception CloneNotSupportedException Thrown if the copy operation isn't supported
+ *
+ */
+ public Test clone() throws CloneNotSupportedException;
}
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:25:59 UTC (rev 111745)
+++ projects/jboss-jca/branches/performance/perfenv/src/main/java/org/jboss/jca/performance/perfenv/TestRunner.java 2011-07-12 13:07:08 UTC (rev 111746)
@@ -79,40 +79,36 @@
try
{
- ClassLoader cl = Perf.getActiveClassLoader();
- Thread.currentThread().setContextClassLoader(cl);
+ Registry registry = Registry.getInstance();
+ Test testMaster = registry.getTest(testCase);
- Class<?> clz = Class.forName(testCase, true, cl);
+ Serializable result = null;
+ if (testMaster != null)
+ {
+ Test test = testMaster.clone();
- Test test = null;
- Object obj = Registry.getInstance().getTest(testCase);
-
- if (null == obj)
- {// not registered
- obj = clz.newInstance();
- }
- test = (Test)obj;
+ Thread.currentThread().setContextClassLoader(test.getClass().getClassLoader());
- Serializable[] testArgs = null;
- if (args.length > 1)
- {
- testArgs = new Serializable[args.length - 1];
- for (int i = 1; i < args.length; i++)
+ Serializable[] testArgs = null;
+ if (args.length > 1)
{
- testArgs[i - 1] = args[i];
+ testArgs = new Serializable[args.length - 1];
+ for (int i = 1; i < args.length; i++)
+ {
+ testArgs[i - 1] = args[i];
+ }
}
- }
- if (testArgs != null)
- {
- log.info("Executing: " + testCase + Arrays.toString(testArgs));
+ registry.addRunner(testCase);
+ result = test.run(testArgs);
+ registry.removeRunner(testCase);
}
else
{
- log.info("Executing: " + testCase);
+ log.warn("Unknown test: " + testCase);
}
- return test.run(testArgs);
+ return result;
}
catch (Throwable t)
{
Modified: 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 2011-07-11 16:25:59 UTC (rev 111745)
+++ projects/jboss-jca/branches/performance/perfenv/src/main/java/org/jboss/jca/performance/perfenv/TestSetUp.java 2011-07-12 13:07:08 UTC (rev 111746)
@@ -42,7 +42,7 @@
private static final String NAME = "setup";
/** The logger */
- private static final Logger logger = Logger.getLogger(TestSetUp.class);
+ private static final Logger log = Logger.getLogger(TestSetUp.class);
/**
* Constructor
@@ -82,14 +82,17 @@
String testCase = (String)args[0];
+ log.info("Setup: " + testCase);
+
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();
+ Test test = (Test)clz.newInstance();
+ Registry registry = Registry.getInstance();
+
Serializable[] testArgs = null;
if (args.length > 1)
{
@@ -99,18 +102,12 @@
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.");
- }
+ Serializable returnValue = test.setup(testArgs);
+
+ if (returnValue == null || !(returnValue instanceof Throwable))
+ registry.addTest(test);
+
return returnValue;
}
catch (Throwable t)
@@ -133,6 +130,4 @@
{
return true;
}
-
-
}
Modified: 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 2011-07-11 16:25:59 UTC (rev 111745)
+++ projects/jboss-jca/branches/performance/perfenv/src/main/java/org/jboss/jca/performance/perfenv/TestTearDown.java 2011-07-12 13:07:08 UTC (rev 111746)
@@ -42,7 +42,7 @@
private static final String NAME = "teardown";
/** The logger */
- private static final Logger logger = Logger.getLogger(TestSetUp.class);
+ private static final Logger log = Logger.getLogger(TestSetUp.class);
/**
* Constructor
@@ -82,17 +82,46 @@
String testCase = (String)args[0];
+ log.info("Teardown: " + testCase);
+
try
{
- ClassLoader cl = Perf.getActiveClassLoader();
- Thread.currentThread().setContextClassLoader(cl);
+ Registry registry = Registry.getInstance();
+ Test test = registry.getTest(testCase);
- Class<?> clz = Class.forName(testCase, true, cl);
- AfterTest test = (AfterTest)clz.newInstance();
- Registry<AfterTest> registry = (Registry<AfterTest>)Registry.getInstance();
- registry.remove(test);
+ Serializable result = null;
+ if (test != null)
+ {
+ Thread.currentThread().setContextClassLoader(test.getClass().getClassLoader());
- return test.tearDown();
+ 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];
+ }
+ }
+
+ boolean teardown = false;
+
+ while (!teardown)
+ {
+ if (registry.getRunners(testCase) == 0)
+ {
+ result = test.teardown(testArgs);
+ registry.removeTest(test);
+ teardown = true;
+ }
+ else
+ {
+ Thread.sleep(1000);
+ }
+ }
+ }
+
+ return result;
}
catch (Throwable t)
{
@@ -114,6 +143,4 @@
{
return true;
}
-
-
}
Modified: projects/jboss-jca/branches/performance/perfenv/src/main/java/org/jboss/jca/performance/perfenv/tests/DatabaseTester.java
===================================================================
--- projects/jboss-jca/branches/performance/perfenv/src/main/java/org/jboss/jca/performance/perfenv/tests/DatabaseTester.java 2011-07-11 16:25:59 UTC (rev 111745)
+++ projects/jboss-jca/branches/performance/perfenv/src/main/java/org/jboss/jca/performance/perfenv/tests/DatabaseTester.java 2011-07-12 13:07:08 UTC (rev 111746)
@@ -91,6 +91,14 @@
/**
* {@inheritDoc}
*/
+ public Serializable setup(Serializable[] args)
+ {
+ return null;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
public Serializable run(Serializable[] args)
{
if (args == null || args.length == 0)
@@ -185,6 +193,24 @@
}
/**
+ * {@inheritDoc}
+ */
+ public Serializable teardown(Serializable[] args)
+ {
+ return null;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Test clone() throws CloneNotSupportedException
+ {
+ DatabaseTester t = (DatabaseTester)super.clone();
+
+ return t;
+ }
+
+ /**
* Test class
*/
private static class TestCase implements Runnable
Modified: projects/jboss-jca/branches/performance/perfenv/src/main/java/org/jboss/jca/performance/perfenv/tests/RampDatabaseTester.java
===================================================================
--- projects/jboss-jca/branches/performance/perfenv/src/main/java/org/jboss/jca/performance/perfenv/tests/RampDatabaseTester.java 2011-07-11 16:25:59 UTC (rev 111745)
+++ projects/jboss-jca/branches/performance/perfenv/src/main/java/org/jboss/jca/performance/perfenv/tests/RampDatabaseTester.java 2011-07-12 13:07:08 UTC (rev 111746)
@@ -102,6 +102,14 @@
/**
* {@inheritDoc}
*/
+ public Serializable setup(Serializable[] args)
+ {
+ return null;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
public Serializable run(Serializable[] args)
{
if (args == null || args.length < 4)
@@ -165,6 +173,24 @@
}
/**
+ * {@inheritDoc}
+ */
+ public Serializable teardown(Serializable[] args)
+ {
+ return null;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Test clone() throws CloneNotSupportedException
+ {
+ RampDatabaseTester t = (RampDatabaseTester)super.clone();
+
+ return t;
+ }
+
+ /**
* Execute for a duration
* @param duration The duration of execution
* @param dataSource The data source
Added: projects/jboss-jca/branches/performance/perfenv/src/main/java/org/jboss/jca/performance/perfenv/tests/TimedDatabaseTester.java
===================================================================
--- projects/jboss-jca/branches/performance/perfenv/src/main/java/org/jboss/jca/performance/perfenv/tests/TimedDatabaseTester.java (rev 0)
+++ projects/jboss-jca/branches/performance/perfenv/src/main/java/org/jboss/jca/performance/perfenv/tests/TimedDatabaseTester.java 2011-07-12 13:07:08 UTC (rev 111746)
@@ -0,0 +1,320 @@
+ /*
+ * 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.tests;
+
+import org.jboss.jca.performance.perfenv.Test;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.io.Serializable;
+import java.io.StringWriter;
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.sql.DataSource;
+import javax.transaction.UserTransaction;
+
+import org.jboss.logging.Logger;
+
+/**
+ * A timed test application for database access
+ *
+ * @author <a href="jesper.pedersen at jboss.org">Jesper Pedersen</a>
+ */
+public class TimedDatabaseTester implements Test
+{
+ /** The logger */
+ private static Logger log = Logger.getLogger("TimedDatabaseTester");
+
+ /** User transaction JNDI name */
+ private static final String JNDI_USER_TRANSACTION = "java:/UserTransaction";
+
+ /** User transaction */
+ private UserTransaction userTransaction;
+
+ /** Data source */
+ private DataSource dataSource;
+
+ /** The JNDI for the datasource */
+ private String dbJndiName;
+
+ /** The list of SQL statements to execute */
+ private List<String> sqls;
+
+ /** The test case */
+ private TestCase testCase;
+
+ /**
+ * Constructor
+ */
+ public TimedDatabaseTester()
+ {
+ this.dbJndiName = null;
+ this.sqls = new ArrayList<String>(1);
+ this.sqls.add("SELECT 1");
+ this.testCase = null;
+ }
+
+ /**
+ * Get the user transaction
+ * @return The value
+ */
+ UserTransaction getUserTransaction()
+ {
+ return userTransaction;
+ }
+
+ /**
+ * Get the data source
+ * @return The value
+ */
+ DataSource getDataSource()
+ {
+ return dataSource;
+ }
+
+ /**
+ * Get the SQL statements
+ * @return The value
+ */
+ List<String> getSQLs()
+ {
+ return new ArrayList<String>(sqls);
+ }
+
+ /**
+ * Set the test case
+ * @param tc The value
+ */
+ void setTestCase(TestCase tc)
+ {
+ this.testCase = tc;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Serializable setup(Serializable[] args)
+ {
+ if (args == null || args.length != 1)
+ return new IllegalArgumentException("Unsupported argument list: " + Arrays.toString(args));
+
+ Context context = null;
+ try
+ {
+ dbJndiName = (String)args[0];
+
+ if (dbJndiName == null || dbJndiName.trim().equals(""))
+ throw new IllegalArgumentException("No datasource JNDI name defined");
+
+ context = new InitialContext();
+ userTransaction = (UserTransaction)context.lookup(JNDI_USER_TRANSACTION);
+ dataSource = (DataSource)context.lookup(dbJndiName);
+
+ setTestCase(new TestCase(dataSource, userTransaction, sqls));
+ }
+ catch (Throwable t)
+ {
+ StringWriter sw = new StringWriter();
+ sw.write(t.getMessage());
+ sw.write('\n');
+
+ t.printStackTrace(new PrintWriter(sw));
+
+ return new Exception(sw.toString());
+ } finally {
+ if (context != null)
+ {
+ try
+ {
+ context.close();
+ }
+ catch (Throwable ignore)
+ {
+ // Ignore
+ }
+ }
+ }
+
+ return null;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Serializable run(Serializable[] args)
+ {
+ if (testCase == null)
+ return new IllegalArgumentException("Test case not defined");
+
+ try
+ {
+ long start = System.currentTimeMillis();
+ testCase.run();
+ long end = System.currentTimeMillis();
+
+ long elapsed = end - start;
+
+ if (elapsed <= 0)
+ elapsed = 1;
+
+ return Long.valueOf(elapsed);
+ }
+ catch (Throwable t)
+ {
+ StringWriter sw = new StringWriter();
+ sw.write(t.getMessage());
+ sw.write('\n');
+
+ t.printStackTrace(new PrintWriter(sw));
+
+ return new Exception(sw.toString());
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Serializable teardown(Serializable[] args)
+ {
+ return null;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Test clone() throws CloneNotSupportedException
+ {
+ TimedDatabaseTester t = (TimedDatabaseTester)super.clone();
+ t.setTestCase(new TestCase(getDataSource(), getUserTransaction(), getSQLs()));
+
+ return t;
+ }
+
+ /**
+ * Test class
+ */
+ private static class TestCase implements Runnable
+ {
+ private DataSource dataSource;
+ private UserTransaction userTransaction;
+ private List<String> sqls;
+
+ TestCase(DataSource db, UserTransaction ut, List<String> sqls)
+ {
+ if (db == null)
+ throw new IllegalArgumentException("No datasource defined");
+
+ if (ut == null)
+ throw new IllegalArgumentException("UserTransaction is null");
+
+ this.dataSource = db;
+ this.userTransaction = ut;
+ this.sqls = sqls;
+ }
+
+ public void run()
+ {
+ Connection connection = null;
+
+ try
+ {
+ userTransaction.begin();
+
+ connection = dataSource.getConnection();
+
+ PreparedStatement ps = null;
+ ResultSet resultSet = null;
+
+ if (sqls != null)
+ {
+ for (String sqlStatement : sqls)
+ {
+ log.debug("Executing: " + sqlStatement);
+
+ try
+ {
+ ps = connection.prepareStatement(sqlStatement);
+ resultSet = ps.executeQuery();
+ }
+ finally
+ {
+ try
+ {
+ if (resultSet != null)
+ resultSet.close();
+ }
+ catch (SQLException se)
+ {
+ // Ignore
+ }
+ try
+ {
+ if (ps != null)
+ ps.close();
+ }
+ catch (SQLException se)
+ {
+ // Ignore
+ }
+ }
+ }
+ }
+
+ userTransaction.commit();
+ }
+ catch (Throwable t)
+ {
+ try
+ {
+ if (userTransaction != null)
+ userTransaction.rollback();
+ }
+ catch (Throwable inner)
+ {
+ // Ignore
+ }
+
+ log.error(t.getMessage(), t);
+ }
+ finally
+ {
+ try
+ {
+ if (connection != null)
+ connection.close();
+ }
+ catch (SQLException se)
+ {
+ // Ignore
+ }
+ }
+ }
+ }
+}
Added: projects/jboss-jca/branches/performance/perfenv/src/main/resources/driver.sh
===================================================================
--- projects/jboss-jca/branches/performance/perfenv/src/main/resources/driver.sh (rev 0)
+++ projects/jboss-jca/branches/performance/perfenv/src/main/resources/driver.sh 2011-07-12 13:07:08 UTC (rev 111746)
@@ -0,0 +1,17 @@
+#!/bin/sh
+
+# Setup the JVM
+if [ "x$JAVA" = "x" ]; then
+ if [ "x$JAVA_HOME" != "x" ]; then
+ JAVA="$JAVA_HOME/bin/java"
+ else
+ JAVA="java"
+ fi
+fi
+
+# Setup the JVM options
+JAVA_OPTS="$JAVA_OPTS -Xmx512m"
+
+# Start Driver
+"$JAVA" $JAVA_OPTS \
+ -classpath ../lib/ironjacamar-performance-perfenv.jar org.jboss.jca.performance.perfenv.Driver "$@"
Property changes on: projects/jboss-jca/branches/performance/perfenv/src/main/resources/driver.sh
___________________________________________________________________
Added: svn:executable
+ *
Modified: projects/jboss-jca/branches/performance/perfenv/src/main/resources/perf.sh
===================================================================
--- projects/jboss-jca/branches/performance/perfenv/src/main/resources/perf.sh 2011-07-11 16:25:59 UTC (rev 111745)
+++ projects/jboss-jca/branches/performance/perfenv/src/main/resources/perf.sh 2011-07-12 13:07:08 UTC (rev 111746)
@@ -13,7 +13,7 @@
fi
# Setup the JVM options
-JAVA_OPTS="$JAVA_OPTS -Xmx512m"
+JAVA_OPTS="$JAVA_OPTS -Xmx1024m"
# Start Perf
"$JAVA" $JAVA_OPTS \
More information about the jboss-cvs-commits
mailing list