You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ps...@apache.org on 2008/03/23 18:00:51 UTC

svn commit: r640221 - in /commons/sandbox/performance/trunk: ./ src/java/org/apache/commons/performance/ src/java/org/apache/commons/performance/dbcp/ src/java/org/apache/commons/performance/pool/ src/site/apt/ src/test/org/apache/commons/performance/ ...

Author: psteitz
Date: Sun Mar 23 10:00:49 2008
New Revision: 640221

URL: http://svn.apache.org/viewvc?rev=640221&view=rev
Log:
Fixed svn props.

Modified:
    commons/sandbox/performance/trunk/build-dbcp.xml   (props changed)
    commons/sandbox/performance/trunk/build-pool.xml   (props changed)
    commons/sandbox/performance/trunk/build.properties.sample   (props changed)
    commons/sandbox/performance/trunk/config-dbcp.xml   (props changed)
    commons/sandbox/performance/trunk/config-pool.xml   (props changed)
    commons/sandbox/performance/trunk/logging.properties   (props changed)
    commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/ClientThread.java   (props changed)
    commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/ConfigurationException.java   (props changed)
    commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/Statistics.java   (props changed)
    commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/dbcp/DBCPClientThread.java   (props changed)
    commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/dbcp/DBCPSoak.java   (contents, props changed)
    commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/dbcp/DBCPTest.java   (props changed)
    commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/pool/PoolClientThread.java   (props changed)
    commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/pool/PoolSoak.java   (contents, props changed)
    commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/pool/PoolTest.java   (props changed)
    commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/pool/Waiter.java   (props changed)
    commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/pool/WaiterFactory.java   (props changed)
    commons/sandbox/performance/trunk/src/site/apt/index.apt   (props changed)
    commons/sandbox/performance/trunk/src/test/org/apache/commons/performance/LoadGeneratorTest.java   (props changed)
    commons/sandbox/performance/trunk/src/test/org/apache/commons/performance/pool/config-pool.xml   (props changed)

Propchange: commons/sandbox/performance/trunk/build-dbcp.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/sandbox/performance/trunk/build-pool.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/sandbox/performance/trunk/build.properties.sample
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/sandbox/performance/trunk/config-dbcp.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/sandbox/performance/trunk/config-pool.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/sandbox/performance/trunk/logging.properties
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/ClientThread.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/ConfigurationException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/Statistics.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/dbcp/DBCPClientThread.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/dbcp/DBCPSoak.java
URL: http://svn.apache.org/viewvc/commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/dbcp/DBCPSoak.java?rev=640221&r1=640220&r2=640221&view=diff
==============================================================================
--- commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/dbcp/DBCPSoak.java (original)
+++ commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/dbcp/DBCPSoak.java Sun Mar 23 10:00:49 2008
@@ -1,364 +1,364 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- * 
- *      http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.commons.performance.dbcp;
-
-
-import java.sql.Connection;
-import java.sql.Driver;
-import java.sql.DriverManager;
-import java.sql.Statement;
-import java.util.Properties;
-import java.util.logging.Logger;
-import org.apache.commons.dbcp.AbandonedConfig;
-import org.apache.commons.dbcp.AbandonedObjectPool;
-import org.apache.commons.dbcp.ConnectionFactory;
-import org.apache.commons.dbcp.DriverConnectionFactory;
-import org.apache.commons.dbcp.DriverManagerConnectionFactory;
-import org.apache.commons.dbcp.PoolableConnectionFactory;
-import org.apache.commons.dbcp.PoolingDataSource;
-import org.apache.commons.pool.KeyedObjectPoolFactory;
-import org.apache.commons.pool.PoolableObjectFactory;
-import org.apache.commons.pool.impl.GenericKeyedObjectPool;
-import org.apache.commons.pool.impl.GenericKeyedObjectPoolFactory;
-import org.apache.commons.pool.impl.GenericObjectPool;
-import org.apache.commons.math.random.RandomData;
-import org.apache.commons.math.random.RandomDataImpl;
-import org.apache.commons.performance.ConfigurationException;
-import org.apache.commons.performance.ClientThread;
-import org.apache.commons.performance.LoadGenerator;
-import org.apache.commons.performance.Statistics;
- 
-/**
- * Configurable load / performance tester for commons dbcp.
- * Uses Commons Digester to parse and load configuration and spawns
- * DBCPClientThread instances to generate load and gather statistics.
- *
- */
-public class DBCPSoak extends LoadGenerator {
-    // Connection properties
-    private String driverClass;
-    private String connectUrl;
-    private String connectUser;
-    private String connectPassword;
-    private String queryType;
-    
-    // Connection pool properties
-    private String poolType;
-    private String driverType;
-    private String factoryType;
-    private boolean autocommit;
-    private boolean readOnly;
-    private byte exhaustedAction;
-    private boolean testOnBorrow;
-    private boolean testOnReturn;
-    private long timeBetweenEvictions;
-    private int testsPerEviction;
-    private long idleTimeout;
-    private boolean testWhileIdle;
-    private String validationQuery;
-    private AbandonedConfig abandonedConfig = new AbandonedConfig();
-    private boolean poolPreparedStatements;
-    private int maxOpenStatements;
-    private int maxActive;
-    private int maxIdle;
-    private int minIdle;
-    private long maxWait;
-    
-    // Instance variables
-    private GenericObjectPool connectionPool;
-    private PoolingDataSource dataSource;
-    
-    /**
-     * Create connection pool and, if necessary, test table.
-     */
-    protected void init() throws Exception {
-        Class.forName(driverClass);
-        
-        // Create object pool
-        if (poolType.equals("GenericObjectPool")) {
-            connectionPool = new GenericObjectPool(
-                    null, maxActive, exhaustedAction,
-                    maxWait, maxIdle, minIdle, testOnBorrow, testOnReturn,
-                    timeBetweenEvictions, testsPerEviction, idleTimeout,
-                    testWhileIdle);
-        } else if (poolType.equals("AbandonedObjectPool")) {
-            connectionPool = new AbandonedObjectPool(null,abandonedConfig);
-        } else {
-            throw new ConfigurationException(
-                    "invalid pool type configuration: " + poolType);
-        }
-        
-        // Create raw connection factory
-        ConnectionFactory connectionFactory = null;
-        if (driverType.equals("DriverManager")) {
-            connectionFactory = new DriverManagerConnectionFactory(
-                    connectUrl,connectUser,
-                    connectPassword);
-        } else if (driverType.equals("Driver")) {
-            Properties props = new Properties();
-            props.put("user", connectUser);
-            props.put("password", connectPassword);
-            connectionFactory = new DriverConnectionFactory(
-                    (Driver) Class.forName(driverClass).newInstance(),
-                    connectUrl, props);
-        } else {
-            throw new ConfigurationException(
-            "Bad config setting for driver type"); 
-        } 
-   
-        // Create object factory
-        PoolableObjectFactory poolableConnectionFactory = null;
-        KeyedObjectPoolFactory statementPoolFactory = null;
-        if (poolPreparedStatements) { // Use same defaults as BasicDataSource
-            statementPoolFactory = new GenericKeyedObjectPoolFactory(null,
-                        -1, // unlimited maxActive (per key)
-                        GenericKeyedObjectPool.WHEN_EXHAUSTED_FAIL,
-                        0, // maxWait
-                        1, // maxIdle (per key)
-                        maxOpenStatements); //TODO: make all configurable
-        }
-        if (factoryType.equals("PoolableConnectionFactory")) {
-            poolableConnectionFactory = 
-                new PoolableConnectionFactory(
-                        connectionFactory,connectionPool, statementPoolFactory,
-                        validationQuery, readOnly, autocommit);
-        } else if (factoryType.equals("CPDSConnectionFactory")) {
-            throw new ConfigurationException(
-            "CPDSConnectionFactory not implemented yet");
-        } else {
-            throw new ConfigurationException(
-                    "Invalid factory type: " + factoryType);
-        }
-        
-        // Create DataSource
-        dataSource = new PoolingDataSource(connectionPool); 
-        
-        // Try to connect and query test_table. If "test_table" appears in 
-        // exception message, assume table needs to be created. 
-        Connection conn = dataSource.getConnection();
-        try {
-            Statement stmnt = conn.createStatement();
-            stmnt.execute("select * from test_table where indexed=1;");
-            stmnt.close();
-        } catch (Exception ex) {
-            if (ex.getMessage().indexOf("test_table") > 0) {
-                logger.info("Creating test_table");
-                makeTable();
-                logger.info("test_table created successfully");
-            } else {
-                throw ex;
-            }
-        } finally {
-            conn.close();
-        }
-    }
-    
-    protected ClientThread makeClientThread(
-            long iterations, long minDelay, long maxDelay, double sigma,
-            String delayType, long rampPeriod, long peakPeriod,
-            long troughPeriod, String cycleType, String rampType,
-            Logger logger, Statistics stats) {
-        
-        return new DBCPClientThread(iterations, minDelay, maxDelay,
-            sigma, delayType, queryType, rampPeriod, peakPeriod, 
-            troughPeriod, cycleType, rampType, logger, dataSource,
-            stats);
-    }
-    
-    // ------------------------------------------------------------------------
-    // Configuration methods specific to this LoadGenerator invoked by Digester
-    // when superclass execute calls digester.parse.
-    // ------------------------------------------------------------------------
-    public void configureDataBase(String driver, String url,
-            String username, String password, String queryType) {
-        this.driverClass = driver;
-        this.connectUrl = url;
-        this.connectUser = username;
-        this.connectPassword = password;
-        this.queryType = queryType;
-    }
-    
-    public void configureConnectionFactory(String type,
-            String autoCommit, String readOnly, String validationQuery) {
-        this.driverType = type;
-        this.autocommit = Boolean.parseBoolean(autoCommit);
-        this.readOnly = Boolean.parseBoolean(readOnly);
-        this.validationQuery = validationQuery;
-    }
-    
-    public void configurePoolableConnectionFactory(String type, 
-            String poolPreparedStatements, String maxOpenStatements) {
-        this.factoryType = type;
-        this.poolPreparedStatements = 
-            Boolean.parseBoolean(poolPreparedStatements);
-        this.maxOpenStatements = Integer.parseInt(maxOpenStatements);
-    }
-    
-    public void configurePool(String maxActive, String maxIdle, String minIdle,
-            String maxWait, String exhaustedAction, String testOnBorrow,
-            String testOnReturn, String timeBetweenEvictions,
-            String testsPerEviction, String idleTimeout, 
-            String testWhileIdle, String type) throws ConfigurationException { 
-        this.maxActive = Integer.parseInt(maxActive);
-        this.maxIdle = Integer.parseInt(maxIdle);
-        this.minIdle = Integer.parseInt(minIdle);
-        this.maxWait = Long.parseLong(maxWait);
-        this.testOnBorrow = Boolean.parseBoolean(testOnBorrow);
-        this.testOnReturn = Boolean.parseBoolean(testOnReturn);
-        this.timeBetweenEvictions = Long.parseLong(timeBetweenEvictions);
-        this.testsPerEviction = Integer.parseInt(testsPerEviction);
-        this.idleTimeout = Long.parseLong(idleTimeout);
-        this.testWhileIdle = Boolean.parseBoolean(testWhileIdle);
-        this.poolType = type;
-        if (exhaustedAction.equals("block")) {
-            this.exhaustedAction = GenericObjectPool.WHEN_EXHAUSTED_BLOCK;
-        } else if (exhaustedAction.equals("fail")) {
-            this.exhaustedAction = GenericObjectPool.WHEN_EXHAUSTED_FAIL;
-        } else if (exhaustedAction.equals("grow")) {
-            this.exhaustedAction = GenericObjectPool.WHEN_EXHAUSTED_GROW;
-        } else { 
-            throw new ConfigurationException(
-            "Bad configuration setting for exhausted action: "
-                    + exhaustedAction); 
-        }  
-    }
-    
-    public void configureAbandonedConfig(String logAbandoned,
-            String removeAbandoned, String abandonedTimeout) {
-        abandonedConfig.setLogAbandoned(Boolean.parseBoolean(logAbandoned));
-        abandonedConfig.setRemoveAbandoned(
-                Boolean.parseBoolean(removeAbandoned));
-        abandonedConfig.setRemoveAbandonedTimeout(
-                Integer.parseInt(abandonedTimeout));
-    }
-     
-    /**
-     * Creates and populates the test table (test_table) used in the 
-     * load tests. The created table will have 10,000 rows and 3 columns,
-     * populated with random data: <ul>
-     * <li> indexed (indexed integer column) </li>
-     * <li> not_indexed (non-indexed integer column) </li>
-     * <li> text (non-indexed varchar column) </li>
-     * </ul>
-     *
-     * @throws Exception
-     */
-    protected void makeTable() throws Exception {
-        Class.forName(driverClass); 
-        Connection db = DriverManager.getConnection(connectUrl,connectUser,
-                connectPassword);
-        try {
-            Statement sql = db.createStatement();
-            String sqlText = 
-                "create table test_table (indexed int, text varchar(20)," + 
-                " not_indexed int)";
-            sql.executeUpdate(sqlText);
-            sqlText = "CREATE INDEX test1_id_index ON test_table (indexed);";
-            sql.executeUpdate(sqlText);
-            RandomData randomData = new RandomDataImpl();
-            for (int i = 0; i < 10000; i++) {
-                int indexed = randomData.nextInt(0, 100);
-                int not_indexed = randomData.nextInt(0, 1000);
-                String text = randomData.nextHexString(20);
-                sqlText = 
-                    "INSERT INTO test_table (indexed, text, not_indexed)" + 
-                    "VALUES (" + indexed + "," + "'"+ text + "'," + 
-                    not_indexed + ");";
-                sql.executeUpdate(sqlText);
-            }
-            sql.close();
-        } finally {
-            db.close();
-        }
-    }
-    
-    /**
-     * Add dbcp configuration to parameters loaded by super.
-     * Also set config file name.
-     */
-    protected void configure() throws Exception {
-        
-        super.configure();
-        
-        digester.addCallMethod("configuration/database",
-                "configureDataBase", 5);
-        digester.addCallParam("configuration/database/driver", 0);
-        digester.addCallParam("configuration/database/url", 1);
-        digester.addCallParam("configuration/database/username", 2);
-        digester.addCallParam("configuration/database/password", 3);
-        digester.addCallParam("configuration/database/query-type", 4);
-        
-        digester.addCallMethod("configuration/connection-factory", 
-                "configureConnectionFactory", 4);
-        digester.addCallParam(
-                "configuration/connection-factory/type", 0);
-        digester.addCallParam(
-                "configuration/connection-factory/auto-commit", 1);
-        digester.addCallParam(
-                "configuration/connection-factory/read-only", 2);
-        digester.addCallParam(
-                "configuration/connection-factory/validation-query", 3);
-        
-        digester.addCallMethod("configuration/poolable-connection-factory", 
-                "configurePoolableConnectionFactory", 3);
-        digester.addCallParam(
-                "configuration/poolable-connection-factory/type", 0);
-        digester.addCallParam(
-                "configuration/poolable-connection-factory/pool-prepared-statements", 1);
-        digester.addCallParam(
-                "configuration/poolable-connection-factory/max-open-statements", 2);
-        
-        digester.addCallMethod("configuration/pool", 
-                "configurePool", 12);
-        digester.addCallParam(
-                "configuration/pool/max-active", 0);
-        digester.addCallParam(
-                "configuration/pool/max-idle", 1);
-        digester.addCallParam(
-                "configuration/pool/min-idle", 2);
-        digester.addCallParam(
-                "configuration/pool/max-wait", 3);
-        digester.addCallParam(
-                "configuration/pool/exhausted-action", 4);
-        digester.addCallParam(
-                "configuration/pool/test-on-borrow", 5);
-        digester.addCallParam(
-                "configuration/pool/test-on-return", 6);
-        digester.addCallParam(
-                "configuration/pool/time-between-evictions", 7);
-        digester.addCallParam(
-                "configuration/pool/tests-per-eviction", 8);
-        digester.addCallParam(
-                "configuration/pool/idle-timeout", 9);
-        digester.addCallParam(
-                "configuration/pool/test-while-idle", 10);
-        digester.addCallParam(
-                "configuration/pool/type", 11);
-        
-        digester.addCallMethod("configuration/abandoned-config",
-                "configureAbandonedConfig", 3);
-        digester.addCallParam(
-                "configuration/abandoned-config/log-abandoned", 0);
-        digester.addCallParam(
-                "configuration/abandoned-config/remove-abandoned", 1);
-        digester.addCallParam(
-                "configuration/abandoned-config/abandoned-timeout", 2);
-        
-        this.configFile = "config-dbcp.xml";
-    }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.performance.dbcp;
+
+
+import java.sql.Connection;
+import java.sql.Driver;
+import java.sql.DriverManager;
+import java.sql.Statement;
+import java.util.Properties;
+import java.util.logging.Logger;
+import org.apache.commons.dbcp.AbandonedConfig;
+import org.apache.commons.dbcp.AbandonedObjectPool;
+import org.apache.commons.dbcp.ConnectionFactory;
+import org.apache.commons.dbcp.DriverConnectionFactory;
+import org.apache.commons.dbcp.DriverManagerConnectionFactory;
+import org.apache.commons.dbcp.PoolableConnectionFactory;
+import org.apache.commons.dbcp.PoolingDataSource;
+import org.apache.commons.pool.KeyedObjectPoolFactory;
+import org.apache.commons.pool.PoolableObjectFactory;
+import org.apache.commons.pool.impl.GenericKeyedObjectPool;
+import org.apache.commons.pool.impl.GenericKeyedObjectPoolFactory;
+import org.apache.commons.pool.impl.GenericObjectPool;
+import org.apache.commons.math.random.RandomData;
+import org.apache.commons.math.random.RandomDataImpl;
+import org.apache.commons.performance.ConfigurationException;
+import org.apache.commons.performance.ClientThread;
+import org.apache.commons.performance.LoadGenerator;
+import org.apache.commons.performance.Statistics;
+ 
+/**
+ * Configurable load / performance tester for commons dbcp.
+ * Uses Commons Digester to parse and load configuration and spawns
+ * DBCPClientThread instances to generate load and gather statistics.
+ *
+ */
+public class DBCPSoak extends LoadGenerator {
+    // Connection properties
+    private String driverClass;
+    private String connectUrl;
+    private String connectUser;
+    private String connectPassword;
+    private String queryType;
+    
+    // Connection pool properties
+    private String poolType;
+    private String driverType;
+    private String factoryType;
+    private boolean autocommit;
+    private boolean readOnly;
+    private byte exhaustedAction;
+    private boolean testOnBorrow;
+    private boolean testOnReturn;
+    private long timeBetweenEvictions;
+    private int testsPerEviction;
+    private long idleTimeout;
+    private boolean testWhileIdle;
+    private String validationQuery;
+    private AbandonedConfig abandonedConfig = new AbandonedConfig();
+    private boolean poolPreparedStatements;
+    private int maxOpenStatements;
+    private int maxActive;
+    private int maxIdle;
+    private int minIdle;
+    private long maxWait;
+    
+    // Instance variables
+    private GenericObjectPool connectionPool;
+    private PoolingDataSource dataSource;
+    
+    /**
+     * Create connection pool and, if necessary, test table.
+     */
+    protected void init() throws Exception {
+        Class.forName(driverClass);
+        
+        // Create object pool
+        if (poolType.equals("GenericObjectPool")) {
+            connectionPool = new GenericObjectPool(
+                    null, maxActive, exhaustedAction,
+                    maxWait, maxIdle, minIdle, testOnBorrow, testOnReturn,
+                    timeBetweenEvictions, testsPerEviction, idleTimeout,
+                    testWhileIdle);
+        } else if (poolType.equals("AbandonedObjectPool")) {
+            connectionPool = new AbandonedObjectPool(null,abandonedConfig);
+        } else {
+            throw new ConfigurationException(
+                    "invalid pool type configuration: " + poolType);
+        }
+        
+        // Create raw connection factory
+        ConnectionFactory connectionFactory = null;
+        if (driverType.equals("DriverManager")) {
+            connectionFactory = new DriverManagerConnectionFactory(
+                    connectUrl,connectUser,
+                    connectPassword);
+        } else if (driverType.equals("Driver")) {
+            Properties props = new Properties();
+            props.put("user", connectUser);
+            props.put("password", connectPassword);
+            connectionFactory = new DriverConnectionFactory(
+                    (Driver) Class.forName(driverClass).newInstance(),
+                    connectUrl, props);
+        } else {
+            throw new ConfigurationException(
+            "Bad config setting for driver type"); 
+        } 
+   
+        // Create object factory
+        PoolableObjectFactory poolableConnectionFactory = null;
+        KeyedObjectPoolFactory statementPoolFactory = null;
+        if (poolPreparedStatements) { // Use same defaults as BasicDataSource
+            statementPoolFactory = new GenericKeyedObjectPoolFactory(null,
+                        -1, // unlimited maxActive (per key)
+                        GenericKeyedObjectPool.WHEN_EXHAUSTED_FAIL,
+                        0, // maxWait
+                        1, // maxIdle (per key)
+                        maxOpenStatements); //TODO: make all configurable
+        }
+        if (factoryType.equals("PoolableConnectionFactory")) {
+            poolableConnectionFactory = 
+                new PoolableConnectionFactory(
+                        connectionFactory,connectionPool, statementPoolFactory,
+                        validationQuery, readOnly, autocommit);
+        } else if (factoryType.equals("CPDSConnectionFactory")) {
+            throw new ConfigurationException(
+            "CPDSConnectionFactory not implemented yet");
+        } else {
+            throw new ConfigurationException(
+                    "Invalid factory type: " + factoryType);
+        }
+        
+        // Create DataSource
+        dataSource = new PoolingDataSource(connectionPool); 
+        
+        // Try to connect and query test_table. If "test_table" appears in 
+        // exception message, assume table needs to be created. 
+        Connection conn = dataSource.getConnection();
+        try {
+            Statement stmnt = conn.createStatement();
+            stmnt.execute("select * from test_table where indexed=1;");
+            stmnt.close();
+        } catch (Exception ex) {
+            if (ex.getMessage().indexOf("test_table") > 0) {
+                logger.info("Creating test_table");
+                makeTable();
+                logger.info("test_table created successfully");
+            } else {
+                throw ex;
+            }
+        } finally {
+            conn.close();
+        }
+    }
+    
+    protected ClientThread makeClientThread(
+            long iterations, long minDelay, long maxDelay, double sigma,
+            String delayType, long rampPeriod, long peakPeriod,
+            long troughPeriod, String cycleType, String rampType,
+            Logger logger, Statistics stats) {
+        
+        return new DBCPClientThread(iterations, minDelay, maxDelay,
+            sigma, delayType, queryType, rampPeriod, peakPeriod, 
+            troughPeriod, cycleType, rampType, logger, dataSource,
+            stats);
+    }
+    
+    // ------------------------------------------------------------------------
+    // Configuration methods specific to this LoadGenerator invoked by Digester
+    // when superclass execute calls digester.parse.
+    // ------------------------------------------------------------------------
+    public void configureDataBase(String driver, String url,
+            String username, String password, String queryType) {
+        this.driverClass = driver;
+        this.connectUrl = url;
+        this.connectUser = username;
+        this.connectPassword = password;
+        this.queryType = queryType;
+    }
+    
+    public void configureConnectionFactory(String type,
+            String autoCommit, String readOnly, String validationQuery) {
+        this.driverType = type;
+        this.autocommit = Boolean.parseBoolean(autoCommit);
+        this.readOnly = Boolean.parseBoolean(readOnly);
+        this.validationQuery = validationQuery;
+    }
+    
+    public void configurePoolableConnectionFactory(String type, 
+            String poolPreparedStatements, String maxOpenStatements) {
+        this.factoryType = type;
+        this.poolPreparedStatements = 
+            Boolean.parseBoolean(poolPreparedStatements);
+        this.maxOpenStatements = Integer.parseInt(maxOpenStatements);
+    }
+    
+    public void configurePool(String maxActive, String maxIdle, String minIdle,
+            String maxWait, String exhaustedAction, String testOnBorrow,
+            String testOnReturn, String timeBetweenEvictions,
+            String testsPerEviction, String idleTimeout, 
+            String testWhileIdle, String type) throws ConfigurationException { 
+        this.maxActive = Integer.parseInt(maxActive);
+        this.maxIdle = Integer.parseInt(maxIdle);
+        this.minIdle = Integer.parseInt(minIdle);
+        this.maxWait = Long.parseLong(maxWait);
+        this.testOnBorrow = Boolean.parseBoolean(testOnBorrow);
+        this.testOnReturn = Boolean.parseBoolean(testOnReturn);
+        this.timeBetweenEvictions = Long.parseLong(timeBetweenEvictions);
+        this.testsPerEviction = Integer.parseInt(testsPerEviction);
+        this.idleTimeout = Long.parseLong(idleTimeout);
+        this.testWhileIdle = Boolean.parseBoolean(testWhileIdle);
+        this.poolType = type;
+        if (exhaustedAction.equals("block")) {
+            this.exhaustedAction = GenericObjectPool.WHEN_EXHAUSTED_BLOCK;
+        } else if (exhaustedAction.equals("fail")) {
+            this.exhaustedAction = GenericObjectPool.WHEN_EXHAUSTED_FAIL;
+        } else if (exhaustedAction.equals("grow")) {
+            this.exhaustedAction = GenericObjectPool.WHEN_EXHAUSTED_GROW;
+        } else { 
+            throw new ConfigurationException(
+            "Bad configuration setting for exhausted action: "
+                    + exhaustedAction); 
+        }  
+    }
+    
+    public void configureAbandonedConfig(String logAbandoned,
+            String removeAbandoned, String abandonedTimeout) {
+        abandonedConfig.setLogAbandoned(Boolean.parseBoolean(logAbandoned));
+        abandonedConfig.setRemoveAbandoned(
+                Boolean.parseBoolean(removeAbandoned));
+        abandonedConfig.setRemoveAbandonedTimeout(
+                Integer.parseInt(abandonedTimeout));
+    }
+     
+    /**
+     * Creates and populates the test table (test_table) used in the 
+     * load tests. The created table will have 10,000 rows and 3 columns,
+     * populated with random data: <ul>
+     * <li> indexed (indexed integer column) </li>
+     * <li> not_indexed (non-indexed integer column) </li>
+     * <li> text (non-indexed varchar column) </li>
+     * </ul>
+     *
+     * @throws Exception
+     */
+    protected void makeTable() throws Exception {
+        Class.forName(driverClass); 
+        Connection db = DriverManager.getConnection(connectUrl,connectUser,
+                connectPassword);
+        try {
+            Statement sql = db.createStatement();
+            String sqlText = 
+                "create table test_table (indexed int, text varchar(20)," + 
+                " not_indexed int)";
+            sql.executeUpdate(sqlText);
+            sqlText = "CREATE INDEX test1_id_index ON test_table (indexed);";
+            sql.executeUpdate(sqlText);
+            RandomData randomData = new RandomDataImpl();
+            for (int i = 0; i < 10000; i++) {
+                int indexed = randomData.nextInt(0, 100);
+                int not_indexed = randomData.nextInt(0, 1000);
+                String text = randomData.nextHexString(20);
+                sqlText = 
+                    "INSERT INTO test_table (indexed, text, not_indexed)" + 
+                    "VALUES (" + indexed + "," + "'"+ text + "'," + 
+                    not_indexed + ");";
+                sql.executeUpdate(sqlText);
+            }
+            sql.close();
+        } finally {
+            db.close();
+        }
+    }
+    
+    /**
+     * Add dbcp configuration to parameters loaded by super.
+     * Also set config file name.
+     */
+    protected void configure() throws Exception {
+        
+        super.configure();
+        
+        digester.addCallMethod("configuration/database",
+                "configureDataBase", 5);
+        digester.addCallParam("configuration/database/driver", 0);
+        digester.addCallParam("configuration/database/url", 1);
+        digester.addCallParam("configuration/database/username", 2);
+        digester.addCallParam("configuration/database/password", 3);
+        digester.addCallParam("configuration/database/query-type", 4);
+        
+        digester.addCallMethod("configuration/connection-factory", 
+                "configureConnectionFactory", 4);
+        digester.addCallParam(
+                "configuration/connection-factory/type", 0);
+        digester.addCallParam(
+                "configuration/connection-factory/auto-commit", 1);
+        digester.addCallParam(
+                "configuration/connection-factory/read-only", 2);
+        digester.addCallParam(
+                "configuration/connection-factory/validation-query", 3);
+        
+        digester.addCallMethod("configuration/poolable-connection-factory", 
+                "configurePoolableConnectionFactory", 3);
+        digester.addCallParam(
+                "configuration/poolable-connection-factory/type", 0);
+        digester.addCallParam(
+                "configuration/poolable-connection-factory/pool-prepared-statements", 1);
+        digester.addCallParam(
+                "configuration/poolable-connection-factory/max-open-statements", 2);
+        
+        digester.addCallMethod("configuration/pool", 
+                "configurePool", 12);
+        digester.addCallParam(
+                "configuration/pool/max-active", 0);
+        digester.addCallParam(
+                "configuration/pool/max-idle", 1);
+        digester.addCallParam(
+                "configuration/pool/min-idle", 2);
+        digester.addCallParam(
+                "configuration/pool/max-wait", 3);
+        digester.addCallParam(
+                "configuration/pool/exhausted-action", 4);
+        digester.addCallParam(
+                "configuration/pool/test-on-borrow", 5);
+        digester.addCallParam(
+                "configuration/pool/test-on-return", 6);
+        digester.addCallParam(
+                "configuration/pool/time-between-evictions", 7);
+        digester.addCallParam(
+                "configuration/pool/tests-per-eviction", 8);
+        digester.addCallParam(
+                "configuration/pool/idle-timeout", 9);
+        digester.addCallParam(
+                "configuration/pool/test-while-idle", 10);
+        digester.addCallParam(
+                "configuration/pool/type", 11);
+        
+        digester.addCallMethod("configuration/abandoned-config",
+                "configureAbandonedConfig", 3);
+        digester.addCallParam(
+                "configuration/abandoned-config/log-abandoned", 0);
+        digester.addCallParam(
+                "configuration/abandoned-config/remove-abandoned", 1);
+        digester.addCallParam(
+                "configuration/abandoned-config/abandoned-timeout", 2);
+        
+        this.configFile = "config-dbcp.xml";
+    }
+}

Propchange: commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/dbcp/DBCPSoak.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/dbcp/DBCPTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/pool/PoolClientThread.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/pool/PoolSoak.java
URL: http://svn.apache.org/viewvc/commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/pool/PoolSoak.java?rev=640221&r1=640220&r2=640221&view=diff
==============================================================================
--- commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/pool/PoolSoak.java (original)
+++ commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/pool/PoolSoak.java Sun Mar 23 10:00:49 2008
@@ -1,345 +1,345 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- * 
- *      http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.commons.performance.pool;
-
-import java.util.List;
-import java.util.logging.Logger;
-import org.apache.commons.dbcp.AbandonedConfig;
-import org.apache.commons.dbcp.AbandonedObjectPool;
-import org.apache.commons.math.stat.descriptive.SummaryStatistics;
-import org.apache.commons.pool.ObjectPool;
-import org.apache.commons.pool.KeyedObjectPool;
-import org.apache.commons.pool.impl.GenericObjectPool;
-import org.apache.commons.pool.impl.StackObjectPool;
-import org.apache.commons.pool.impl.SoftReferenceObjectPool;
-import org.apache.commons.pool.impl.GenericKeyedObjectPool;
-import org.apache.commons.pool.impl.StackKeyedObjectPool;
-import org.apache.commons.performance.ConfigurationException;
-import org.apache.commons.performance.ClientThread;
-import org.apache.commons.performance.LoadGenerator;
-import org.apache.commons.performance.Statistics;
- 
-/**
- * Configurable load / performance tester for commons pool.
- * Uses Commons Digester to parse and load configuration and spawns
- * PoolClientThread instances to generate load and gather statistics.
- *
- */
-public class PoolSoak extends LoadGenerator {
-    
-    // Pool instances
-    private GenericObjectPool genericObjectPool;
-    private GenericKeyedObjectPool genericKeyedObjectPool;
-    private StackObjectPool stackObjectPool;
-    private SoftReferenceObjectPool softReferenceObjectPool;
-    private StackKeyedObjectPool stackKeyedObjectPool;
-    
-    // Pool properties
-    private String poolType;
-    private int maxActive;       // maxActive for GOP, maxTotal for GKOP
-    private int maxActivePerKey; // maxActive for GKOP
-    private int maxIdle;
-    private int minIdle;
-    private long maxWait;
-    private byte exhaustedAction;
-    private boolean testOnBorrow;
-    private boolean testOnReturn;
-    private long timeBetweenEvictions;
-    private int testsPerEviction;
-    private long idleTimeout;
-    private boolean testWhileIdle;
-    private AbandonedConfig abandonedConfig = new AbandonedConfig();
-    private boolean lifo;
-    private double samplingRate;
-    
-    // WaiterFactory properties
-    private long activateLatency;
-    private long destroyLatency;
-    private long makeLatency;
-    private long passivateLatency;
-    private long validateLatency;
-    private long waiterLatency;
-    
-    /**
-     * Add pool configuration to parameters loaded by super.
-     * Also set config file name.
-     */
-    protected void configure() throws Exception {
-        super.configure();
-        digester.addCallMethod("configuration/factory", 
-                "configureFactory", 6);
-        digester.addCallParam(
-                "configuration/factory/activate-latency", 0);
-        digester.addCallParam(
-                "configuration/factory/destroy-latency", 1);
-        digester.addCallParam(
-                "configuration/factory/make-latency", 2);
-        digester.addCallParam(
-                "configuration/factory/passivate-latency", 3);
-        digester.addCallParam(
-                "configuration/factory/validate-latency", 4);
-        digester.addCallParam(
-                "configuration/factory/waiter-latency", 5);   
-        digester.addCallMethod("configuration/pool", 
-                "configurePool", 15);
-        digester.addCallParam(
-                "configuration/pool/max-active", 0);
-        digester.addCallParam(
-                "configuration/pool/max-active-per-key", 1);
-        digester.addCallParam(
-                "configuration/pool/max-idle", 2);
-        digester.addCallParam(
-                "configuration/pool/min-idle", 3);
-        digester.addCallParam(
-                "configuration/pool/max-wait", 4);
-        digester.addCallParam(
-                "configuration/pool/exhausted-action", 5);
-        digester.addCallParam(
-                "configuration/pool/test-on-borrow", 6);
-        digester.addCallParam(
-                "configuration/pool/test-on-return", 7);
-        digester.addCallParam(
-                "configuration/pool/time-between-evictions", 8);
-        digester.addCallParam(
-                "configuration/pool/tests-per-eviction", 9);
-        digester.addCallParam(
-                "configuration/pool/idle-timeout", 10);
-        digester.addCallParam(
-                "configuration/pool/test-while-idle", 11);
-        digester.addCallParam(
-                "configuration/pool/lifo", 12);
-        digester.addCallParam(
-                "configuration/pool/type", 13);
-        digester.addCallParam(
-                "configuration/pool/sampling-rate", 14);
-        digester.addCallMethod("configuration/abandoned-config",
-                "configureAbandonedConfig", 3);
-        digester.addCallParam(
-                "configuration/abandoned-config/log-abandoned", 0);
-        digester.addCallParam(
-                "configuration/abandoned-config/remove-abandoned", 1);
-        digester.addCallParam(
-                "configuration/abandoned-config/abandoned-timeout", 2); 
-        
-        this.configFile = "config-pool.xml";
-        
-    }
-    
-    /**
-     * Create object pool and factory
-     */
-    protected void init() throws Exception {
-        // Create factory
-        WaiterFactory factory = new WaiterFactory(activateLatency, destroyLatency,
-                makeLatency, passivateLatency, validateLatency, waiterLatency,
-                maxActive, maxActivePerKey); 
-        
-        // Create object pool
-        if (poolType.equals("GenericObjectPool")) {
-            genericObjectPool = new GenericObjectPool(factory);
-            genericObjectPool.setMaxActive(maxActive);
-            genericObjectPool.setWhenExhaustedAction(exhaustedAction);
-            genericObjectPool.setMaxWait(maxWait);
-            genericObjectPool.setMaxIdle(maxIdle);
-            genericObjectPool.setMinIdle(minIdle);
-            genericObjectPool.setTestOnBorrow(testOnBorrow);
-            genericObjectPool.setTestOnReturn(testOnReturn);
-            genericObjectPool.setTimeBetweenEvictionRunsMillis(
-                    timeBetweenEvictions);
-            genericObjectPool.setNumTestsPerEvictionRun(testsPerEviction);
-            genericObjectPool.setMinEvictableIdleTimeMillis(idleTimeout);
-            genericObjectPool.setTestWhileIdle(testWhileIdle);
-            //genericObjectPool.setLifo(lifo);
-        } else if (poolType.equals("AbandonedObjectPool")) {
-            genericObjectPool = new AbandonedObjectPool(null,abandonedConfig);
-            genericObjectPool.setMaxActive(maxActive);
-            genericObjectPool.setWhenExhaustedAction(exhaustedAction);
-            genericObjectPool.setMaxWait(maxWait);
-            genericObjectPool.setMaxIdle(maxIdle);
-            genericObjectPool.setMinIdle(minIdle);
-            genericObjectPool.setTestOnBorrow(testOnBorrow);
-            genericObjectPool.setTestOnReturn(testOnReturn);
-            genericObjectPool.setTimeBetweenEvictionRunsMillis(
-                    timeBetweenEvictions);
-            genericObjectPool.setNumTestsPerEvictionRun(testsPerEviction);
-            genericObjectPool.setMinEvictableIdleTimeMillis(idleTimeout);
-            genericObjectPool.setTestWhileIdle(testWhileIdle);
-            //genericObjectPool.setLifo(lifo);
-            genericObjectPool.setFactory(factory);
-        } else if (poolType.equals("GenericKeyedObjectPool")) {
-            genericKeyedObjectPool = new GenericKeyedObjectPool();
-            genericKeyedObjectPool.setMaxActive(maxActivePerKey);
-            genericKeyedObjectPool.setMaxTotal(maxActive);
-            genericKeyedObjectPool.setWhenExhaustedAction(exhaustedAction);
-            genericKeyedObjectPool.setMaxWait(maxWait);
-            genericKeyedObjectPool.setMaxIdle(maxIdle);
-            genericKeyedObjectPool.setMinIdle(minIdle);
-            genericKeyedObjectPool.setTestOnBorrow(testOnBorrow);
-            genericKeyedObjectPool.setTestOnReturn(testOnReturn);
-            genericKeyedObjectPool.setTimeBetweenEvictionRunsMillis(
-                    timeBetweenEvictions);
-            genericKeyedObjectPool.setNumTestsPerEvictionRun(testsPerEviction);
-            genericKeyedObjectPool.setMinEvictableIdleTimeMillis(idleTimeout);
-            genericKeyedObjectPool.setTestWhileIdle(testWhileIdle);
-            //genericKeyedObjectPool.setLifo(lifo);
-            genericKeyedObjectPool.setFactory(factory);
-        } else if (poolType.equals("StackObjectPool")) {
-            stackObjectPool = new StackObjectPool();
-            stackObjectPool.setFactory(factory);
-        } else if (poolType.equals("SoftReferenceObjectPool")) {
-            softReferenceObjectPool = new SoftReferenceObjectPool();
-            softReferenceObjectPool.setFactory(factory);
-        } else if (poolType.equals("StackKeyedObjectPool")) {
-            stackKeyedObjectPool = new StackKeyedObjectPool();
-            stackKeyedObjectPool.setFactory(factory);
-        } else {
-            throw new ConfigurationException(
-                    "invalid pool type configuration: " + poolType);
-        }
-        
-        logger.info("Initialized pool with properties: ");
-        logger.info(" poolTypeT: " + poolType);
-        logger.info(" exhaustedAction: " + exhaustedAction);
-        logger.info(" maxActive: " + maxActive);
-        logger.info(" maxActivePerKey: " + maxActivePerKey);
-        logger.info(" maxIdle: " + maxIdle);
-        logger.info(" minIdle: " + minIdle);
-        logger.info(" testOnBorrow: " + testOnBorrow);
-        logger.info(" testWhileIdle: " + testWhileIdle);
-        logger.info(" timeBetweenEvictions: " + timeBetweenEvictions);
-        logger.info(" testsPerEviction: " + testsPerEviction);
-        logger.info(" idleTimeout: " + idleTimeout);
-        logger.info(" lifo: " + lifo);
-        logger.info(" abandonedConfig: ");
-        logger.info("  logAbandoned: " +
-                abandonedConfig.getLogAbandoned());
-        logger.info("  removeAbandoned: " +
-                abandonedConfig.getRemoveAbandoned());
-        logger.info("  abandonedTimeout: " + 
-                abandonedConfig.getRemoveAbandonedTimeout()); 
-    }
-    
-    /**
-     * Create and return a PoolClientThread
-     */
-    protected ClientThread makeClientThread(long iterations, long minDelay,
-            long maxDelay, double sigma, String delayType, long rampPeriod,
-            long peakPeriod, long troughPeriod, String cycleType, 
-            String rampType, Logger logger, Statistics stats) {
-        if (poolType.equals("GenericObjectPool")) {
-            return new PoolClientThread(iterations, minDelay, maxDelay,
-                    sigma, delayType, rampPeriod, peakPeriod, troughPeriod,
-                    cycleType, rampType, logger, stats, genericObjectPool, 
-                    samplingRate);
-        }
-        if (poolType.equals("GenericKeyedObjectPool")) {
-            return new PoolClientThread(iterations, minDelay, maxDelay,
-                    sigma, delayType, rampPeriod, peakPeriod, troughPeriod,
-                    cycleType, rampType, logger, stats,
-                    genericKeyedObjectPool, samplingRate);
-        }
-        if (poolType.equals("StackKeyedObjectPool")) {
-            return new PoolClientThread(iterations, minDelay, maxDelay,
-                    sigma, delayType, rampPeriod, peakPeriod, troughPeriod,
-                    cycleType, rampType, logger, stats,
-                    stackKeyedObjectPool, samplingRate);
-        }
-        if (poolType.equals("StackObjectPool")) {
-            return new PoolClientThread(iterations, minDelay, maxDelay,
-                    sigma, delayType, rampPeriod, peakPeriod, troughPeriod,
-                    cycleType, rampType, logger, stats,
-                    stackObjectPool, samplingRate);
-        }
-        if (poolType.equals("SoftReferenceObjectPool")) {
-            return new PoolClientThread(iterations, minDelay, maxDelay,
-                    sigma, delayType, rampPeriod, peakPeriod, troughPeriod,
-                    cycleType, rampType, logger, stats,
-                    softReferenceObjectPool, samplingRate);
-        }
-        return null;
-    }
-    
-    // ------------------------------------------------------------------------
-    // Configuration methods specific to this LoadGenerator invoked by Digester
-    // when superclass execute calls digerster.parse.
-    // ------------------------------------------------------------------------       
-    public void configureFactory(String activateLatency, String destroyLatency,
-            String makeLatency, String passivateLatency, String validateLatency,
-            String waiterLatency) {
-       
-        this.activateLatency = Long.parseLong(activateLatency);
-        this.destroyLatency = Long.parseLong(destroyLatency);
-        this.makeLatency = Long.parseLong(makeLatency);
-        this.passivateLatency = Long.parseLong(passivateLatency);
-        this.validateLatency = Long.parseLong(validateLatency);
-        this.waiterLatency = Long.parseLong(waiterLatency);
-    }
-    
-    public void configurePool(String maxActive, String maxActivePerKey,
-            String maxIdle, String minIdle, String maxWait,
-            String exhaustedAction, String testOnBorrow,
-            String testOnReturn, String timeBetweenEvictions,
-            String testsPerEviction, String idleTimeout, 
-            String testWhileIdle, String lifo, String type, String samplingRate)
-        throws ConfigurationException { 
-        this.maxActive = Integer.parseInt(maxActive);
-        this.maxActivePerKey = Integer.parseInt(maxActivePerKey);
-        this.maxIdle = Integer.parseInt(maxIdle);
-        this.minIdle = Integer.parseInt(minIdle);
-        this.maxWait = Long.parseLong(maxWait);
-        this.testOnBorrow = Boolean.parseBoolean(testOnBorrow);
-        this.testOnReturn = Boolean.parseBoolean(testOnReturn);
-        this.timeBetweenEvictions = Long.parseLong(timeBetweenEvictions);
-        this.testsPerEviction = Integer.parseInt(testsPerEviction);
-        this.idleTimeout = Long.parseLong(idleTimeout);
-        this.testWhileIdle = Boolean.parseBoolean(testWhileIdle);
-        this.lifo = Boolean.parseBoolean(lifo);
-        this.poolType = type;
-        if (exhaustedAction.equals("block")) {
-            this.exhaustedAction = GenericObjectPool.WHEN_EXHAUSTED_BLOCK;
-        } else if (exhaustedAction.equals("fail")) {
-            this.exhaustedAction = GenericObjectPool.WHEN_EXHAUSTED_FAIL;
-        } else if (exhaustedAction.equals("grow")) {
-            this.exhaustedAction = GenericObjectPool.WHEN_EXHAUSTED_GROW;
-        } else { 
-            throw new ConfigurationException(
-            "Bad configuration setting for exhausted action: "
-                    + exhaustedAction); 
-        }  
-        this.samplingRate = Double.parseDouble(samplingRate);
-    }
-    
-    public void configureAbandonedConfig(String logAbandoned,
-            String removeAbandoned, String abandonedTimeout) {
-        abandonedConfig.setLogAbandoned(Boolean.parseBoolean(logAbandoned));
-        abandonedConfig.setRemoveAbandoned(
-                Boolean.parseBoolean(removeAbandoned));
-        abandonedConfig.setRemoveAbandonedTimeout(
-                Integer.parseInt(abandonedTimeout));
-    }
-    
-    // Pool getters for unit tests
-    protected GenericObjectPool getGenericObjectPool() {
-        return genericObjectPool;
-    }
-    
-    protected GenericKeyedObjectPool getGenericKeyedObjectPool() {
-        return genericKeyedObjectPool;
-    }
-    
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.performance.pool;
+
+import java.util.List;
+import java.util.logging.Logger;
+import org.apache.commons.dbcp.AbandonedConfig;
+import org.apache.commons.dbcp.AbandonedObjectPool;
+import org.apache.commons.math.stat.descriptive.SummaryStatistics;
+import org.apache.commons.pool.ObjectPool;
+import org.apache.commons.pool.KeyedObjectPool;
+import org.apache.commons.pool.impl.GenericObjectPool;
+import org.apache.commons.pool.impl.StackObjectPool;
+import org.apache.commons.pool.impl.SoftReferenceObjectPool;
+import org.apache.commons.pool.impl.GenericKeyedObjectPool;
+import org.apache.commons.pool.impl.StackKeyedObjectPool;
+import org.apache.commons.performance.ConfigurationException;
+import org.apache.commons.performance.ClientThread;
+import org.apache.commons.performance.LoadGenerator;
+import org.apache.commons.performance.Statistics;
+ 
+/**
+ * Configurable load / performance tester for commons pool.
+ * Uses Commons Digester to parse and load configuration and spawns
+ * PoolClientThread instances to generate load and gather statistics.
+ *
+ */
+public class PoolSoak extends LoadGenerator {
+    
+    // Pool instances
+    private GenericObjectPool genericObjectPool;
+    private GenericKeyedObjectPool genericKeyedObjectPool;
+    private StackObjectPool stackObjectPool;
+    private SoftReferenceObjectPool softReferenceObjectPool;
+    private StackKeyedObjectPool stackKeyedObjectPool;
+    
+    // Pool properties
+    private String poolType;
+    private int maxActive;       // maxActive for GOP, maxTotal for GKOP
+    private int maxActivePerKey; // maxActive for GKOP
+    private int maxIdle;
+    private int minIdle;
+    private long maxWait;
+    private byte exhaustedAction;
+    private boolean testOnBorrow;
+    private boolean testOnReturn;
+    private long timeBetweenEvictions;
+    private int testsPerEviction;
+    private long idleTimeout;
+    private boolean testWhileIdle;
+    private AbandonedConfig abandonedConfig = new AbandonedConfig();
+    private boolean lifo;
+    private double samplingRate;
+    
+    // WaiterFactory properties
+    private long activateLatency;
+    private long destroyLatency;
+    private long makeLatency;
+    private long passivateLatency;
+    private long validateLatency;
+    private long waiterLatency;
+    
+    /**
+     * Add pool configuration to parameters loaded by super.
+     * Also set config file name.
+     */
+    protected void configure() throws Exception {
+        super.configure();
+        digester.addCallMethod("configuration/factory", 
+                "configureFactory", 6);
+        digester.addCallParam(
+                "configuration/factory/activate-latency", 0);
+        digester.addCallParam(
+                "configuration/factory/destroy-latency", 1);
+        digester.addCallParam(
+                "configuration/factory/make-latency", 2);
+        digester.addCallParam(
+                "configuration/factory/passivate-latency", 3);
+        digester.addCallParam(
+                "configuration/factory/validate-latency", 4);
+        digester.addCallParam(
+                "configuration/factory/waiter-latency", 5);   
+        digester.addCallMethod("configuration/pool", 
+                "configurePool", 15);
+        digester.addCallParam(
+                "configuration/pool/max-active", 0);
+        digester.addCallParam(
+                "configuration/pool/max-active-per-key", 1);
+        digester.addCallParam(
+                "configuration/pool/max-idle", 2);
+        digester.addCallParam(
+                "configuration/pool/min-idle", 3);
+        digester.addCallParam(
+                "configuration/pool/max-wait", 4);
+        digester.addCallParam(
+                "configuration/pool/exhausted-action", 5);
+        digester.addCallParam(
+                "configuration/pool/test-on-borrow", 6);
+        digester.addCallParam(
+                "configuration/pool/test-on-return", 7);
+        digester.addCallParam(
+                "configuration/pool/time-between-evictions", 8);
+        digester.addCallParam(
+                "configuration/pool/tests-per-eviction", 9);
+        digester.addCallParam(
+                "configuration/pool/idle-timeout", 10);
+        digester.addCallParam(
+                "configuration/pool/test-while-idle", 11);
+        digester.addCallParam(
+                "configuration/pool/lifo", 12);
+        digester.addCallParam(
+                "configuration/pool/type", 13);
+        digester.addCallParam(
+                "configuration/pool/sampling-rate", 14);
+        digester.addCallMethod("configuration/abandoned-config",
+                "configureAbandonedConfig", 3);
+        digester.addCallParam(
+                "configuration/abandoned-config/log-abandoned", 0);
+        digester.addCallParam(
+                "configuration/abandoned-config/remove-abandoned", 1);
+        digester.addCallParam(
+                "configuration/abandoned-config/abandoned-timeout", 2); 
+        
+        this.configFile = "config-pool.xml";
+        
+    }
+    
+    /**
+     * Create object pool and factory
+     */
+    protected void init() throws Exception {
+        // Create factory
+        WaiterFactory factory = new WaiterFactory(activateLatency, destroyLatency,
+                makeLatency, passivateLatency, validateLatency, waiterLatency,
+                maxActive, maxActivePerKey); 
+        
+        // Create object pool
+        if (poolType.equals("GenericObjectPool")) {
+            genericObjectPool = new GenericObjectPool(factory);
+            genericObjectPool.setMaxActive(maxActive);
+            genericObjectPool.setWhenExhaustedAction(exhaustedAction);
+            genericObjectPool.setMaxWait(maxWait);
+            genericObjectPool.setMaxIdle(maxIdle);
+            genericObjectPool.setMinIdle(minIdle);
+            genericObjectPool.setTestOnBorrow(testOnBorrow);
+            genericObjectPool.setTestOnReturn(testOnReturn);
+            genericObjectPool.setTimeBetweenEvictionRunsMillis(
+                    timeBetweenEvictions);
+            genericObjectPool.setNumTestsPerEvictionRun(testsPerEviction);
+            genericObjectPool.setMinEvictableIdleTimeMillis(idleTimeout);
+            genericObjectPool.setTestWhileIdle(testWhileIdle);
+            //genericObjectPool.setLifo(lifo);
+        } else if (poolType.equals("AbandonedObjectPool")) {
+            genericObjectPool = new AbandonedObjectPool(null,abandonedConfig);
+            genericObjectPool.setMaxActive(maxActive);
+            genericObjectPool.setWhenExhaustedAction(exhaustedAction);
+            genericObjectPool.setMaxWait(maxWait);
+            genericObjectPool.setMaxIdle(maxIdle);
+            genericObjectPool.setMinIdle(minIdle);
+            genericObjectPool.setTestOnBorrow(testOnBorrow);
+            genericObjectPool.setTestOnReturn(testOnReturn);
+            genericObjectPool.setTimeBetweenEvictionRunsMillis(
+                    timeBetweenEvictions);
+            genericObjectPool.setNumTestsPerEvictionRun(testsPerEviction);
+            genericObjectPool.setMinEvictableIdleTimeMillis(idleTimeout);
+            genericObjectPool.setTestWhileIdle(testWhileIdle);
+            //genericObjectPool.setLifo(lifo);
+            genericObjectPool.setFactory(factory);
+        } else if (poolType.equals("GenericKeyedObjectPool")) {
+            genericKeyedObjectPool = new GenericKeyedObjectPool();
+            genericKeyedObjectPool.setMaxActive(maxActivePerKey);
+            genericKeyedObjectPool.setMaxTotal(maxActive);
+            genericKeyedObjectPool.setWhenExhaustedAction(exhaustedAction);
+            genericKeyedObjectPool.setMaxWait(maxWait);
+            genericKeyedObjectPool.setMaxIdle(maxIdle);
+            genericKeyedObjectPool.setMinIdle(minIdle);
+            genericKeyedObjectPool.setTestOnBorrow(testOnBorrow);
+            genericKeyedObjectPool.setTestOnReturn(testOnReturn);
+            genericKeyedObjectPool.setTimeBetweenEvictionRunsMillis(
+                    timeBetweenEvictions);
+            genericKeyedObjectPool.setNumTestsPerEvictionRun(testsPerEviction);
+            genericKeyedObjectPool.setMinEvictableIdleTimeMillis(idleTimeout);
+            genericKeyedObjectPool.setTestWhileIdle(testWhileIdle);
+            //genericKeyedObjectPool.setLifo(lifo);
+            genericKeyedObjectPool.setFactory(factory);
+        } else if (poolType.equals("StackObjectPool")) {
+            stackObjectPool = new StackObjectPool();
+            stackObjectPool.setFactory(factory);
+        } else if (poolType.equals("SoftReferenceObjectPool")) {
+            softReferenceObjectPool = new SoftReferenceObjectPool();
+            softReferenceObjectPool.setFactory(factory);
+        } else if (poolType.equals("StackKeyedObjectPool")) {
+            stackKeyedObjectPool = new StackKeyedObjectPool();
+            stackKeyedObjectPool.setFactory(factory);
+        } else {
+            throw new ConfigurationException(
+                    "invalid pool type configuration: " + poolType);
+        }
+        
+        logger.info("Initialized pool with properties: ");
+        logger.info(" poolTypeT: " + poolType);
+        logger.info(" exhaustedAction: " + exhaustedAction);
+        logger.info(" maxActive: " + maxActive);
+        logger.info(" maxActivePerKey: " + maxActivePerKey);
+        logger.info(" maxIdle: " + maxIdle);
+        logger.info(" minIdle: " + minIdle);
+        logger.info(" testOnBorrow: " + testOnBorrow);
+        logger.info(" testWhileIdle: " + testWhileIdle);
+        logger.info(" timeBetweenEvictions: " + timeBetweenEvictions);
+        logger.info(" testsPerEviction: " + testsPerEviction);
+        logger.info(" idleTimeout: " + idleTimeout);
+        logger.info(" lifo: " + lifo);
+        logger.info(" abandonedConfig: ");
+        logger.info("  logAbandoned: " +
+                abandonedConfig.getLogAbandoned());
+        logger.info("  removeAbandoned: " +
+                abandonedConfig.getRemoveAbandoned());
+        logger.info("  abandonedTimeout: " + 
+                abandonedConfig.getRemoveAbandonedTimeout()); 
+    }
+    
+    /**
+     * Create and return a PoolClientThread
+     */
+    protected ClientThread makeClientThread(long iterations, long minDelay,
+            long maxDelay, double sigma, String delayType, long rampPeriod,
+            long peakPeriod, long troughPeriod, String cycleType, 
+            String rampType, Logger logger, Statistics stats) {
+        if (poolType.equals("GenericObjectPool")) {
+            return new PoolClientThread(iterations, minDelay, maxDelay,
+                    sigma, delayType, rampPeriod, peakPeriod, troughPeriod,
+                    cycleType, rampType, logger, stats, genericObjectPool, 
+                    samplingRate);
+        }
+        if (poolType.equals("GenericKeyedObjectPool")) {
+            return new PoolClientThread(iterations, minDelay, maxDelay,
+                    sigma, delayType, rampPeriod, peakPeriod, troughPeriod,
+                    cycleType, rampType, logger, stats,
+                    genericKeyedObjectPool, samplingRate);
+        }
+        if (poolType.equals("StackKeyedObjectPool")) {
+            return new PoolClientThread(iterations, minDelay, maxDelay,
+                    sigma, delayType, rampPeriod, peakPeriod, troughPeriod,
+                    cycleType, rampType, logger, stats,
+                    stackKeyedObjectPool, samplingRate);
+        }
+        if (poolType.equals("StackObjectPool")) {
+            return new PoolClientThread(iterations, minDelay, maxDelay,
+                    sigma, delayType, rampPeriod, peakPeriod, troughPeriod,
+                    cycleType, rampType, logger, stats,
+                    stackObjectPool, samplingRate);
+        }
+        if (poolType.equals("SoftReferenceObjectPool")) {
+            return new PoolClientThread(iterations, minDelay, maxDelay,
+                    sigma, delayType, rampPeriod, peakPeriod, troughPeriod,
+                    cycleType, rampType, logger, stats,
+                    softReferenceObjectPool, samplingRate);
+        }
+        return null;
+    }
+    
+    // ------------------------------------------------------------------------
+    // Configuration methods specific to this LoadGenerator invoked by Digester
+    // when superclass execute calls digerster.parse.
+    // ------------------------------------------------------------------------       
+    public void configureFactory(String activateLatency, String destroyLatency,
+            String makeLatency, String passivateLatency, String validateLatency,
+            String waiterLatency) {
+       
+        this.activateLatency = Long.parseLong(activateLatency);
+        this.destroyLatency = Long.parseLong(destroyLatency);
+        this.makeLatency = Long.parseLong(makeLatency);
+        this.passivateLatency = Long.parseLong(passivateLatency);
+        this.validateLatency = Long.parseLong(validateLatency);
+        this.waiterLatency = Long.parseLong(waiterLatency);
+    }
+    
+    public void configurePool(String maxActive, String maxActivePerKey,
+            String maxIdle, String minIdle, String maxWait,
+            String exhaustedAction, String testOnBorrow,
+            String testOnReturn, String timeBetweenEvictions,
+            String testsPerEviction, String idleTimeout, 
+            String testWhileIdle, String lifo, String type, String samplingRate)
+        throws ConfigurationException { 
+        this.maxActive = Integer.parseInt(maxActive);
+        this.maxActivePerKey = Integer.parseInt(maxActivePerKey);
+        this.maxIdle = Integer.parseInt(maxIdle);
+        this.minIdle = Integer.parseInt(minIdle);
+        this.maxWait = Long.parseLong(maxWait);
+        this.testOnBorrow = Boolean.parseBoolean(testOnBorrow);
+        this.testOnReturn = Boolean.parseBoolean(testOnReturn);
+        this.timeBetweenEvictions = Long.parseLong(timeBetweenEvictions);
+        this.testsPerEviction = Integer.parseInt(testsPerEviction);
+        this.idleTimeout = Long.parseLong(idleTimeout);
+        this.testWhileIdle = Boolean.parseBoolean(testWhileIdle);
+        this.lifo = Boolean.parseBoolean(lifo);
+        this.poolType = type;
+        if (exhaustedAction.equals("block")) {
+            this.exhaustedAction = GenericObjectPool.WHEN_EXHAUSTED_BLOCK;
+        } else if (exhaustedAction.equals("fail")) {
+            this.exhaustedAction = GenericObjectPool.WHEN_EXHAUSTED_FAIL;
+        } else if (exhaustedAction.equals("grow")) {
+            this.exhaustedAction = GenericObjectPool.WHEN_EXHAUSTED_GROW;
+        } else { 
+            throw new ConfigurationException(
+            "Bad configuration setting for exhausted action: "
+                    + exhaustedAction); 
+        }  
+        this.samplingRate = Double.parseDouble(samplingRate);
+    }
+    
+    public void configureAbandonedConfig(String logAbandoned,
+            String removeAbandoned, String abandonedTimeout) {
+        abandonedConfig.setLogAbandoned(Boolean.parseBoolean(logAbandoned));
+        abandonedConfig.setRemoveAbandoned(
+                Boolean.parseBoolean(removeAbandoned));
+        abandonedConfig.setRemoveAbandonedTimeout(
+                Integer.parseInt(abandonedTimeout));
+    }
+    
+    // Pool getters for unit tests
+    protected GenericObjectPool getGenericObjectPool() {
+        return genericObjectPool;
+    }
+    
+    protected GenericKeyedObjectPool getGenericKeyedObjectPool() {
+        return genericKeyedObjectPool;
+    }
+    
+}

Propchange: commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/pool/PoolSoak.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/pool/PoolTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/pool/Waiter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/pool/WaiterFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/sandbox/performance/trunk/src/site/apt/index.apt
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/sandbox/performance/trunk/src/test/org/apache/commons/performance/LoadGeneratorTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/sandbox/performance/trunk/src/test/org/apache/commons/performance/pool/config-pool.xml
------------------------------------------------------------------------------
    svn:eol-style = native