[jboss-cvs] JBossAS SVN: r111462 - in projects/jboss-jca/branches/performance/perfenv: src/main/java/org/jboss/jca/performance/perfenv and 1 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Thu May 26 13:26:44 EDT 2011
Author: jesper.pedersen
Date: 2011-05-26 13:26:44 -0400 (Thu, 26 May 2011)
New Revision: 111462
Added:
projects/jboss-jca/branches/performance/perfenv/src/main/java/org/jboss/jca/performance/perfenv/tests/
projects/jboss-jca/branches/performance/perfenv/src/main/java/org/jboss/jca/performance/perfenv/tests/AbstractDatabaseTester.java
projects/jboss-jca/branches/performance/perfenv/src/main/java/org/jboss/jca/performance/perfenv/tests/H2DSMulti.java
projects/jboss-jca/branches/performance/perfenv/src/main/java/org/jboss/jca/performance/perfenv/tests/H2DSSingle.java
projects/jboss-jca/branches/performance/perfenv/src/main/java/org/jboss/jca/performance/perfenv/tests/package.html
Modified:
projects/jboss-jca/branches/performance/perfenv/build.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/TestRunner.java
Log:
Port POJO tests, create tests/ directory
Modified: projects/jboss-jca/branches/performance/perfenv/build.xml
===================================================================
--- projects/jboss-jca/branches/performance/perfenv/build.xml 2011-05-26 16:37:03 UTC (rev 111461)
+++ projects/jboss-jca/branches/performance/perfenv/build.xml 2011-05-26 17:26:44 UTC (rev 111462)
@@ -61,13 +61,24 @@
</copy>
<jar destfile="${target.dir}/ironjacamar-performance-perfenv.jar"
- basedir="${build.perfenv.dir}/jars">
+ basedir="${build.perfenv.dir}/jars"
+ excludes="**/tests/**">
<manifest>
<attribute name="Implementation-Title" value="IronJacamar Performance (Perfenv)"/>
<attribute name="Implementation-Vendor" value="The IronJacamar project (http://www.jboss.org/ironjacamar)"/>
<attribute name="Implementation-Vendor-Id" value="org.jboss"/>
</manifest>
</jar>
+
+ <jar destfile="${target.dir}/ironjacamar-performance-perfenv-tests.jar"
+ basedir="${build.perfenv.dir}/jars"
+ includes="**/tests/**">
+ <manifest>
+ <attribute name="Implementation-Title" value="IronJacamar Performance (Perfenv - Tests)"/>
+ <attribute name="Implementation-Vendor" value="The IronJacamar project (http://www.jboss.org/ironjacamar)"/>
+ <attribute name="Implementation-Vendor-Id" value="org.jboss"/>
+ </manifest>
+ </jar>
</target>
<!-- =================================
@@ -105,6 +116,7 @@
<mkdir dir="${target.dir}/perfenv/deployments" />
<mkdir dir="${target.dir}/perfenv/lib" />
<mkdir dir="${target.dir}/perfenv/installations" />
+ <mkdir dir="${target.dir}/perfenv/tests" />
<copy todir="${target.dir}/perfenv/bin">
<fileset dir="src/main/resources" includes="**/*.sh"/>
@@ -124,6 +136,11 @@
includes="**"/>
</copy>
+ <copy todir="${target.dir}/perfenv/tests">
+ <fileset dir="${target.dir}"
+ includes="ironjacamar-performance-perfenv-tests.jar"/>
+ </copy>
+
<chmod dir="${target.dir}/perfenv/bin" perm="ugo+rx"
includes="**/*.sh"/>
</target>
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-05-26 16:37:03 UTC (rev 111461)
+++ projects/jboss-jca/branches/performance/perfenv/src/main/java/org/jboss/jca/performance/perfenv/Perf.java 2011-05-26 17:26:44 UTC (rev 111462)
@@ -60,6 +60,9 @@
/** The installations directory */
private static File installationsRoot;
+ /** The tests directory */
+ private static File testsRoot;
+
/** The available installations and their root */
private static Map<String, File> installations;
@@ -81,6 +84,9 @@
/** Deployments class loader */
private static URLClassLoader deploymentsClassLoader;
+ /** Tests class loader */
+ private static URLClassLoader testsClassLoader;
+
/**
* Get the installation directories available
* @param root The root directory
@@ -177,6 +183,18 @@
}
/**
+ * Get the active classloader
+ * @return The value
+ */
+ static ClassLoader getActiveClassLoader()
+ {
+ if (active != null)
+ return testsClassLoader;
+
+ return deploymentsClassLoader;
+ }
+
+ /**
* Is the specified profile available
* @param name The name of the profile
* @return True if available
@@ -221,12 +239,15 @@
{
URLClassLoader cl = new URLClassLoader(getURLs(installations.get(profile.getName())),
deploymentsClassLoader);
- Thread.currentThread().setContextClassLoader(cl);
+ testsClassLoader = new URLClassLoader(getURLs(testsRoot), cl);
+
+ Thread.currentThread().setContextClassLoader(testsClassLoader);
+
String home = new File(profile.getName()).toURI().toURL().toString();
System.setProperty("iron.jacamar.home", home);
- Class<?> embeddedFactory = cl.loadClass("org.jboss.jca.embedded.EmbeddedFactory");
+ Class<?> embeddedFactory = testsClassLoader.loadClass("org.jboss.jca.embedded.EmbeddedFactory");
Method create = embeddedFactory.getMethod("create", new Class[] {boolean.class});
Object embedded = create.invoke(null, new Object[] {Boolean.FALSE});
@@ -546,6 +567,7 @@
deploymentsRoot = new File(home, "deployments");
installationsRoot = new File(home, "installations");
+ testsRoot = new File(home, "tests");
String hostname = "localhost";
int hostport = 7000;
@@ -606,7 +628,7 @@
communicationServer.registerCommand(new GetProfiles());
communicationServer.registerCommand(new Deploy());
communicationServer.registerCommand(new Undeploy());
- communicationServer.registerCommand(new TestRunner(deploymentsClassLoader));
+ communicationServer.registerCommand(new TestRunner());
communicationServer.registerCommand(new Reload());
communicationServer.start();
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-05-26 16:37:03 UTC (rev 111461)
+++ projects/jboss-jca/branches/performance/perfenv/src/main/java/org/jboss/jca/performance/perfenv/TestRunner.java 2011-05-26 17:26:44 UTC (rev 111462)
@@ -40,16 +40,11 @@
/** The logger */
private static Logger log = Logger.getLogger(TestRunner.class.getName());
- /** The classloader */
- private ClassLoader cl;
-
/**
* Constructor
- * @param cl The classloader
*/
- public TestRunner(ClassLoader cl)
+ public TestRunner()
{
- this.cl = cl;
}
/**
@@ -84,6 +79,9 @@
try
{
+ ClassLoader cl = Perf.getActiveClassLoader();
+ Thread.currentThread().setContextClassLoader(cl);
+
Class<?> clz = Class.forName(testCase, true, cl);
Test test = (Test)clz.newInstance();
Added: projects/jboss-jca/branches/performance/perfenv/src/main/java/org/jboss/jca/performance/perfenv/tests/AbstractDatabaseTester.java
===================================================================
--- projects/jboss-jca/branches/performance/perfenv/src/main/java/org/jboss/jca/performance/perfenv/tests/AbstractDatabaseTester.java (rev 0)
+++ projects/jboss-jca/branches/performance/perfenv/src/main/java/org/jboss/jca/performance/perfenv/tests/AbstractDatabaseTester.java 2011-05-26 17:26:44 UTC (rev 111462)
@@ -0,0 +1,305 @@
+ /*
+ * 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 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 javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.sql.DataSource;
+import javax.transaction.UserTransaction;
+
+import org.jboss.logging.Logger;
+
+/**
+ * A test application for database access
+ *
+ * @author <a href="jesper.pedersen at jboss.org">Jesper Pedersen</a>
+ */
+public abstract class AbstractDatabaseTester implements Test
+{
+ /** The logger */
+ private static Logger log = Logger.getLogger("DatabaseTester");
+
+ /** User transaction JNDI name */
+ private static final String JNDI_USER_TRANSACTION = "java:/UserTransaction";
+
+ /** Multithreaded execution */
+ private boolean multiThreaded;
+
+ /** Max number of threads */
+ private int maxThreads;
+
+ /** The JNDI for the datasource */
+ private String dbJndiName;
+
+ /** Iterations */
+ private int iterations;
+
+ /** The list of SQL statements to execute */
+ private List<String> sqls;
+
+ /**
+ * Constructor
+ * @param multithreaded multithreaded
+ * @param maxthreads maxthreads
+ * @param dbjndiname dbjndiname
+ * @param iterations iterations
+ */
+ public AbstractDatabaseTester(boolean multithreaded, int maxthreads, String dbjndiname, int iterations)
+ {
+ this.multiThreaded = multithreaded;
+ this.maxThreads = maxthreads;
+ this.dbJndiName = dbjndiname;
+ this.iterations = iterations;
+ this.sqls = new ArrayList<String>(1);
+ this.sqls.add("SELECT 1");
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Serializable run(Serializable[] args)
+ {
+ /*
+ if (args == null || args.length == 0)
+ return new IllegalArgumentException("Unsupported argument list: " + Arrays.toString(args));
+ */
+
+ try
+ {
+ /*
+ dbJndiName = (String)args[0];
+
+ if (args.length > 1)
+ multiThreaded = ((Boolean)args[1]).booleanValue();
+
+ if (args.length > 2)
+ maxThreads = ((Integer)args[2]).intValue();
+
+ if (args.length > 3)
+ iterations = ((Integer)args[3]).intValue();
+
+ if (dbJndiName == null || dbJndiName.trim().equals(""))
+ throw new IllegalArgumentException("No datasource JNDI name defined");
+ */
+
+ long start = 0;
+ long end = 0;
+
+ Context context = new InitialContext();
+ UserTransaction userTransaction = (UserTransaction)context.lookup(JNDI_USER_TRANSACTION);
+ DataSource dataSource = (DataSource)context.lookup(dbJndiName);
+
+ if (multiThreaded)
+ {
+ try
+ {
+ CountDownLatch cdl = new CountDownLatch(iterations);
+
+ BlockingQueue<Runnable> threadPoolQueue = new LinkedBlockingQueue<Runnable>(iterations);
+ ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(maxThreads, maxThreads,
+ 60, TimeUnit.SECONDS,
+ threadPoolQueue);
+
+ threadPoolExecutor.allowCoreThreadTimeOut(true);
+ threadPoolExecutor.prestartAllCoreThreads();
+
+ start = System.currentTimeMillis();
+ for (int counter = 0; counter < iterations; counter++)
+ {
+ TestCase t = new TestCase(dataSource, userTransaction, sqls, cdl);
+ threadPoolExecutor.submit(t);
+ }
+ cdl.await();
+ end = System.currentTimeMillis();
+
+ threadPoolExecutor.shutdown();
+ }
+ catch (Throwable t)
+ {
+ // Ignore
+ }
+ }
+ else
+ {
+ start = System.currentTimeMillis();
+ TestCase t = new TestCase(dataSource, userTransaction, sqls);
+ for (int counter = 0; counter < iterations; counter++)
+ {
+ t.run();
+ }
+ end = System.currentTimeMillis();
+ }
+
+ long elapsed = end - start;
+
+ if (elapsed <= 0)
+ elapsed = 1;
+
+ log.info("Took: " + elapsed + " ms");
+ log.info("Unit of work/ms: " + (iterations / (double)elapsed));
+
+ context.close();
+
+ return new Double((iterations * 1000L) / (double)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());
+ }
+ }
+
+ /**
+ * Test class
+ */
+ private static class TestCase implements Runnable
+ {
+ private DataSource dataSource;
+ private UserTransaction userTransaction;
+ private List<String> sqls;
+ private CountDownLatch cdl;
+
+ TestCase(DataSource db, UserTransaction ut, List<String> sqls)
+ {
+ this(db, ut, sqls, null);
+ }
+
+ TestCase(DataSource db, UserTransaction ut, List<String> sqls, CountDownLatch cdl)
+ {
+ this.dataSource = db;
+ this.userTransaction = ut;
+ this.sqls = sqls;
+ this.cdl = cdl;
+ }
+
+ public void run()
+ {
+ if (dataSource == null)
+ throw new IllegalArgumentException("No datasource defined");
+
+ if (userTransaction == null)
+ throw new IllegalArgumentException("UserTransaction is null");
+
+ 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
+ }
+
+ if (cdl != null)
+ cdl.countDown();
+ }
+ }
+ }
+}
Added: projects/jboss-jca/branches/performance/perfenv/src/main/java/org/jboss/jca/performance/perfenv/tests/H2DSMulti.java
===================================================================
--- projects/jboss-jca/branches/performance/perfenv/src/main/java/org/jboss/jca/performance/perfenv/tests/H2DSMulti.java (rev 0)
+++ projects/jboss-jca/branches/performance/perfenv/src/main/java/org/jboss/jca/performance/perfenv/tests/H2DSMulti.java 2011-05-26 17:26:44 UTC (rev 111462)
@@ -0,0 +1,38 @@
+ /*
+ * 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;
+
+/**
+ * H2DS multi-threaded
+ *
+ * @author <a href="jesper.pedersen at jboss.org">Jesper Pedersen</a>
+ */
+public class H2DSMulti extends AbstractDatabaseTester
+{
+ /**
+ * Constructor
+ */
+ public H2DSMulti()
+ {
+ super(true, 100, "java:/H2DS", 100000);
+ }
+}
Added: projects/jboss-jca/branches/performance/perfenv/src/main/java/org/jboss/jca/performance/perfenv/tests/H2DSSingle.java
===================================================================
--- projects/jboss-jca/branches/performance/perfenv/src/main/java/org/jboss/jca/performance/perfenv/tests/H2DSSingle.java (rev 0)
+++ projects/jboss-jca/branches/performance/perfenv/src/main/java/org/jboss/jca/performance/perfenv/tests/H2DSSingle.java 2011-05-26 17:26:44 UTC (rev 111462)
@@ -0,0 +1,38 @@
+ /*
+ * 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;
+
+/**
+ * H2DS single-threaded
+ *
+ * @author <a href="jesper.pedersen at jboss.org">Jesper Pedersen</a>
+ */
+public class H2DSSingle extends AbstractDatabaseTester
+{
+ /**
+ * Constructor
+ */
+ public H2DSSingle()
+ {
+ super(false, 100, "java:/H2DS", 100000);
+ }
+}
Added: projects/jboss-jca/branches/performance/perfenv/src/main/java/org/jboss/jca/performance/perfenv/tests/package.html
===================================================================
--- projects/jboss-jca/branches/performance/perfenv/src/main/java/org/jboss/jca/performance/perfenv/tests/package.html (rev 0)
+++ projects/jboss-jca/branches/performance/perfenv/src/main/java/org/jboss/jca/performance/perfenv/tests/package.html 2011-05-26 17:26:44 UTC (rev 111462)
@@ -0,0 +1,3 @@
+<body>
+Contains bundled performance test cases.
+</body>
More information about the jboss-cvs-commits
mailing list