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 2014/03/23 21:31:37 UTC

svn commit: r1580595 [1/2] - 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/pool/ src/test/org/apache/commons/performanc...

Author: psteitz
Date: Sun Mar 23 20:31:36 2014
New Revision: 1580595

URL: http://svn.apache.org/r1580595
Log:
Udpated dependencies; implemented final pool 2.x API; replaced sandbox parent; reformatted some code.

Modified:
    commons/sandbox/performance/trunk/pom.xml
    commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/ClientThread.java
    commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/Statistics.java
    commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/dbcp/DBCPSoak.java
    commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/pool/PoolClientThread.java
    commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/pool/PoolSoak.java
    commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/pool/WaiterFactory2.java
    commons/sandbox/performance/trunk/src/pool/build.properties.sample
    commons/sandbox/performance/trunk/src/pool/build.xml
    commons/sandbox/performance/trunk/src/test/org/apache/commons/performance/LoadGeneratorTest.java
    commons/sandbox/performance/trunk/src/test/org/apache/commons/performance/pool/PoolSoakTest.java
    commons/sandbox/performance/trunk/src/test/org/apache/commons/performance/pool/WaiterTest.java

Modified: commons/sandbox/performance/trunk/pom.xml
URL: http://svn.apache.org/viewvc/commons/sandbox/performance/trunk/pom.xml?rev=1580595&r1=1580594&r2=1580595&view=diff
==============================================================================
--- commons/sandbox/performance/trunk/pom.xml (original)
+++ commons/sandbox/performance/trunk/pom.xml Sun Mar 23 20:31:36 2014
@@ -22,8 +22,8 @@
   <modelVersion>4.0.0</modelVersion>
   <parent>
     <groupId>org.apache.commons</groupId>
-	  <artifactId>commons-sandbox-parent</artifactId>
-    <version>10-SNAPSHOT</version>
+	  <artifactId>commons-parent</artifactId>
+    <version>33</version>
   </parent>
 
   <artifactId>commons-performance</artifactId>
@@ -51,7 +51,7 @@
     <dependency>
       <groupId>commons-digester</groupId>
       <artifactId>commons-digester</artifactId>
-      <version>1.8</version>
+      <version>2.1</version>
     </dependency>
    <dependency>
       <groupId>commons-dbcp</groupId>
@@ -65,8 +65,8 @@
     </dependency>
     <dependency>
        <groupId>org.apache.commons</groupId>
-       <artifactId>commons-math</artifactId>
-       <version>2.2</version>
+       <artifactId>commons-math3</artifactId>
+       <version>3.2</version>
     </dependency>
     <dependency>
        <groupId>commons-httpclient</groupId>
@@ -76,7 +76,7 @@
     <dependency>
       <groupId>junit</groupId>
       <artifactId>junit</artifactId>
-      <version>3.8.1</version>
+      <version>4.11</version>
       <scope>test</scope>
     </dependency>
     
@@ -84,12 +84,12 @@
     <dependency>
        <groupId>org.apache.commons</groupId>
        <artifactId>commons-pool2</artifactId>
-       <version>2.0-SNAPSHOT</version>
+       <version>2.2</version>
     </dependency>
     <dependency>
        <groupId>org.apache.commons</groupId>
        <artifactId>commons-dbcp2</artifactId>
-       <version>2.0-SNAPSHOT</version>
+       <version>2.0</version>
     </dependency>
     <dependency>
        <groupId>org.apache.tomcat</groupId>
@@ -207,8 +207,8 @@
 
   <!-- Compiler source and target JVM -->
   <properties>
-    <maven.compile.source>1.5</maven.compile.source>
-    <maven.compile.target>1.5</maven.compile.target>
+    <maven.compiler.source>1.6</maven.compiler.source>
+    <maven.compiler.target>1.6</maven.compiler.target>
     <commons.componentid>performance</commons.componentid>
     <commons.jira.componentid>12312203</commons.jira.componentid>
   </properties> 

Modified: commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/ClientThread.java
URL: http://svn.apache.org/viewvc/commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/ClientThread.java?rev=1580595&r1=1580594&r2=1580595&view=diff
==============================================================================
--- commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/ClientThread.java (original)
+++ commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/ClientThread.java Sun Mar 23 20:31:36 2014
@@ -19,36 +19,38 @@ package org.apache.commons.performance;
 
 import java.util.logging.Logger;
 
-import org.apache.commons.math.random.RandomData;
-import org.apache.commons.math.random.RandomDataImpl;
-import org.apache.commons.math.stat.descriptive.SummaryStatistics;
+import org.apache.commons.math3.random.RandomDataGenerator;
+import org.apache.commons.math3.stat.descriptive.SummaryStatistics;
 
 /**
- * <p>Base for performance / load test clients. 
- * The run method executes init, then setup-execute-cleanup in a loop,
- * gathering performance statistics, with time between executions based
- * on configuration parameters. The <code>finish</code> method is executed once
- * at the end of a run. See {@link #nextDelay()} for details on
- * inter-arrival time computation.</p>
+ * <p>
+ * Base for performance / load test clients. The run method executes init, then
+ * setup-execute-cleanup in a loop, gathering performance statistics, with time between executions
+ * based on configuration parameters. The <code>finish</code> method is executed once at the end of
+ * a run. See {@link #nextDelay()} for details on inter-arrival time computation.
+ * </p>
  * 
- * <p>Subclasses <strong>must</strong> implement <code>execute</code>, which
- * is the basic client request action that is executed, and timed, 
- * repeatedly. If per-request setup is required, and you do not want the time
- * associated with this setup to be included in the reported timings, implement 
- * <code>setUp</code> and put the setup code there.  Similarly for 
- * <code>cleanUp</code>. Initialization code that needs to be executed once
- * only, before any requests are initiated, should be put into 
- * <code>init</code> and cleanup code that needs to be executed only once
- * at the end of a simulation should be put into <code>finish.</code></p>
+ * <p>
+ * Subclasses <strong>must</strong> implement <code>execute</code>, which is the basic client
+ * request action that is executed, and timed, repeatedly. If per-request setup is required, and you
+ * do not want the time associated with this setup to be included in the reported timings, implement
+ * <code>setUp</code> and put the setup code there. Similarly for <code>cleanUp</code>.
+ * Initialization code that needs to be executed once only, before any requests are initiated,
+ * should be put into <code>init</code> and cleanup code that needs to be executed only once at the
+ * end of a simulation should be put into <code>finish.</code>
+ * </p>
  * 
- * <p>By default, the only statistics accumulated are for the latency of the 
- * <code>execute</code> method. Additional metrics can be captured and added
- * to the {@link Statistics} for the running thread.</p>
+ * <p>
+ * By default, the only statistics accumulated are for the latency of the <code>execute</code>
+ * method. Additional metrics can be captured and added to the {@link Statistics} for the running
+ * thread.
+ * </p>
  * 
  */
-public abstract class ClientThread implements Runnable {
+public abstract class ClientThread
+    implements Runnable {
 
-    // Inter-arrival time configuration parameters 
+    // Inter-arrival time configuration parameters
     /** Minimum mean time between requests */
     private long minDelay;
     /** Maximum mean time between requests */
@@ -67,10 +69,10 @@ public abstract class ClientThread imple
     private final String cycleType;
     /** Ramp type */
     private String rampType;
-    
+
     /** Number of iterations */
     private final long iterations;
-    
+
     // State data
     /** Start time of run */
     private long startTime;
@@ -89,14 +91,14 @@ public abstract class ClientThread imple
     private long numErrors = 0;
     /** Number of misses */
     private long numMisses = 0;
-    
+
     /** Random data generator */
-    protected RandomData randomData = new RandomDataImpl();
+    protected RandomDataGenerator randomData = new RandomDataGenerator();
     /** Statistics container */
     protected Statistics stats;
     /** Logger shared by client threads */
     protected Logger logger;
-    
+
     /**
      * Create a client thread.
      * 
@@ -113,11 +115,9 @@ public abstract class ClientThread imple
      * @param logger common logger shared by all clients
      * @param stats Statistics instance to add results to
      */
-    public ClientThread(long iterations, long minDelay, long maxDelay,
-            double sigma, String delayType, long rampPeriod, long peakPeriod,
-            long troughPeriod, String cycleType,
-            String rampType, Logger logger,
-            Statistics stats) {
+    public ClientThread(long iterations, long minDelay, long maxDelay, double sigma, String delayType, long rampPeriod,
+                        long peakPeriod, long troughPeriod, String cycleType, String rampType, Logger logger,
+                        Statistics stats) {
         this.iterations = iterations;
         this.minDelay = minDelay;
         this.maxDelay = maxDelay;
@@ -131,7 +131,8 @@ public abstract class ClientThread imple
         this.logger = logger;
         this.stats = stats;
     }
-    
+
+    @Override
     public void run() {
         try {
             init();
@@ -144,7 +145,7 @@ public abstract class ClientThread imple
         startTime = System.currentTimeMillis();
         long lastStart = startTime;
         periodStart = System.currentTimeMillis();
-        lastMean = (double) maxDelay; // Ramp up, if any, starts here
+        lastMean = maxDelay; // Ramp up, if any, starts here
         SummaryStatistics responseStats = new SummaryStatistics();
         SummaryStatistics onTimeStats = new SummaryStatistics();
         SummaryStatistics successStats = new SummaryStatistics();
@@ -166,7 +167,7 @@ public abstract class ClientThread imple
                         logger.info("Sleep interrupted");
                     }
                 }
-                
+
                 // Fire the request and measure response time
                 lastStart = System.currentTimeMillis();
                 start = System.nanoTime();
@@ -176,17 +177,17 @@ public abstract class ClientThread imple
                 success = false;
             } finally {
                 try {
-                    //TODO: Keep times in ns here, convert stats for ms reporting
-                    responseStats.addValue((System.nanoTime() - start)/1000f/1000f); 
+                    // TODO: Keep times in ns here, convert stats for ms reporting
+                    responseStats.addValue((System.nanoTime() - start) / 1000f / 1000f);
                     successStats.addValue(success ? 1 : 0);
                     onTimeStats.addValue(onTime ? 1 : 0);
                     cleanUp();
                 } catch (Exception e) {
-                    e.printStackTrace();                    
+                    e.printStackTrace();
                 }
             }
         }
-        
+
         try {
             finish();
         } catch (Exception ex) {
@@ -194,73 +195,87 @@ public abstract class ClientThread imple
             ex.printStackTrace();
             return;
         }
-        
+
         // Use thread name as process name
         String process = Thread.currentThread().getName();
-        
+
         // Record statistics
         stats.addStatistics(responseStats, process, "latency");
         stats.addStatistics(onTimeStats, process, "on time startup rate");
         stats.addStatistics(successStats, process, "successful completion rate");
-        
+
         // Log accumulated statistics for this thread
-        logger.info(stats.displayProcessStatistics(process)); 
+        logger.info(stats.displayProcessStatistics(process));
     }
-    
+
     /** Executed once at the beginning of the run */
-    protected void init() throws Exception {}
-    
+    protected void init()
+        throws Exception {
+    }
+
     /** Executed at the beginning of each iteration */
-    protected void setUp() throws Exception {}
-    
+    protected void setUp()
+        throws Exception {
+    }
+
     /** Executed in finally block of iteration try-catch */
-    protected void cleanUp() throws Exception {}
-    
+    protected void cleanUp()
+        throws Exception {
+    }
+
     /** Executed once after the run finishes */
-    protected void finish() throws Exception {}
-    
-    /** 
-     * Core iteration code.  Timings are based on this,
-     *  so keep it tight.
+    protected void finish()
+        throws Exception {
+    }
+
+    /**
+     * Core iteration code. Timings are based on this, so keep it tight.
      */
-    public abstract void execute() throws Exception;
-    
+    public abstract void execute()
+        throws Exception;
+
     /**
-     * <p>Computes the next inter-arrival time (time to wait between requests)
-     * based on configured values for min/max delay, delay type, cycle type, 
-     * ramp type and period. Currently supports constant (always returning
-     * <code>minDelay</code> delay time), Poisson and Gaussian distributed
-     * random time delays, linear and random ramps, and oscillating / 
-     * non-oscillating cycle types.</p>
-     * 
-     * <p><strong>loadType</strong> determines whether returned times are
-     * deterministic or random. If <code>loadType</code> is not "constant",
-     * a random value with the specified distribution and mean determined by
-     * the other parameters is returned. For "gaussian" <code>loadType</code>,
-     * <code>sigma</code> is used as used as the standard deviation. </p>
-     * 
-     * <p><strong>cycleType</strong> determines how the returned times vary
-     * over time. "oscillating", means times ramp up and down between 
-     * <code>minDelay</code> and <code>maxDelay.</code> Ramp type is controlled
-     * by <code>rampType.</code>  Linear <code>rampType</code> means the means
-     * increase or decrease linearly over the time of the period.  Random
-     * makes random jumps up or down toward the next peak or trough. "None" for
-     * <code>rampType</code> under oscillating <code>cycleType</code> makes the
-     * means alternate between peak (<code>minDelay</code>) and trough 
-     *(<code>maxDelay</code>) with no ramp between. </p>
-     * 
-     * <p>Oscillating loads cycle through RAMPING_UP, PEAK_LOAD, RAMPING_DOWN
-     * and TROUGH_LOAD states, with the amount of time spent in each state
-     * determined by <code>rampPeriod</code> (time spent increasing on the way
-     * up and decreasing on the way down), <code>peakPeriod</code> (time spent
-     * at peak load, i.e., <code>minDelay</code> mean delay) and 
-     * <code>troughPeriod</code> (time spent at minimum load, i.e., 
-     * <code>maxDelay</code> mean delay). All times are specified in
-     * milliseconds. </p>
+     * <p>
+     * Computes the next inter-arrival time (time to wait between requests) based on configured
+     * values for min/max delay, delay type, cycle type, ramp type and period. Currently supports
+     * constant (always returning <code>minDelay</code> delay time), Poisson and Gaussian
+     * distributed random time delays, linear and random ramps, and oscillating / non-oscillating
+     * cycle types.
+     * </p>
+     * 
+     * <p>
+     * <strong>loadType</strong> determines whether returned times are deterministic or random. If
+     * <code>loadType</code> is not "constant", a random value with the specified distribution and
+     * mean determined by the other parameters is returned. For "gaussian" <code>loadType</code>,
+     * <code>sigma</code> is used as used as the standard deviation.
+     * </p>
+     * 
+     * <p>
+     * <strong>cycleType</strong> determines how the returned times vary over time. "oscillating",
+     * means times ramp up and down between <code>minDelay</code> and <code>maxDelay.</code> Ramp
+     * type is controlled by <code>rampType.</code> Linear <code>rampType</code> means the means
+     * increase or decrease linearly over the time of the period. Random makes random jumps up or
+     * down toward the next peak or trough. "None" for <code>rampType</code> under oscillating
+     * <code>cycleType</code> makes the means alternate between peak (<code>minDelay</code>) and
+     * trough (<code>maxDelay</code>) with no ramp between.
+     * </p>
+     * 
+     * <p>
+     * Oscillating loads cycle through RAMPING_UP, PEAK_LOAD, RAMPING_DOWN and TROUGH_LOAD states,
+     * with the amount of time spent in each state determined by <code>rampPeriod</code> (time spent
+     * increasing on the way up and decreasing on the way down), <code>peakPeriod</code> (time spent
+     * at peak load, i.e., <code>minDelay</code> mean delay) and <code>troughPeriod</code> (time
+     * spent at minimum load, i.e., <code>maxDelay</code> mean delay). All times are specified in
+     * milliseconds.
+     * </p>
+     * 
+     * <p>
+     * <strong>Examples:</strong>
+     * <ol>
      * 
-     * <p><strong>Examples:</strong><ol>
+     * <li>Given
      * 
-     * <li>Given<pre>
+     * <pre>
      * delayType = "constant"
      * minDelay = 250
      * maxDelay = 500
@@ -268,14 +283,18 @@ public abstract class ClientThread imple
      * rampType = "linear" 
      * rampPeriod = 10000
      * peakPeriod = 20000
-     * troughPeriod = 30000</pre> load will start at one request every 500 ms,
-     * which is "trough load." Load then ramps up linearly over the next 10
-     * seconds unil it reaches one request per 250 milliseconds, which is 
-     * "peak load."  Peak load is sustained for 20 seconds and then load ramps
-     * back down, again taking 10 seconds to get down to "trough load," which
-     * is sustained for 30 seconds.  The cycle then repeats.</li>
+     * troughPeriod = 30000
+     * </pre>
      * 
-     * <li><pre>
+     * load will start at one request every 500 ms, which is "trough load." Load then ramps up
+     * linearly over the next 10 seconds unil it reaches one request per 250 milliseconds, which is
+     * "peak load." Peak load is sustained for 20 seconds and then load ramps back down, again
+     * taking 10 seconds to get down to "trough load," which is sustained for 30 seconds. The cycle
+     * then repeats.</li>
+     * 
+     * <li>
+     * 
+     * <pre>
      * delayType = "gaussian"
      * minDelay = 250
      * maxDelay = 500
@@ -284,54 +303,62 @@ public abstract class ClientThread imple
      * rampPeriod = 10000
      * peakPeriod = 20000
      * troughPeriod = 30000
-     * sigma = 100 </pre> produces a load pattern similar to example 1, but in
-     * this case the computed delay value is fed into a gaussian random number
-     * generator as the mean and 100 as the standard deviation - i.e., 
-     * <code>nextDelay</code> returns random, gaussian distributed values with
-     * means moving according to the cyclic pattern in example 1.</li>
+     * sigma = 100
+     * </pre>
+     * 
+     * produces a load pattern similar to example 1, but in this case the computed delay value is
+     * fed into a gaussian random number generator as the mean and 100 as the standard deviation -
+     * i.e., <code>nextDelay</code> returns random, gaussian distributed values with means moving
+     * according to the cyclic pattern in example 1.</li>
      * 
-     * <li><pre>
+     * <li>
+     * 
+     * <pre>
      * delayType = "constant"
      * minDelay = 250
      * maxDelay = 500
      * cycleType = "none"
      * rampType = "linear" 
-     * rampPeriod = 10000</pre> produces a load pattern that increases linearly
-     * from one request every 500ms to one request every 250ms and then stays
-     * constant at that level until the run is over.  Other parameters are
+     * rampPeriod = 10000
+     * </pre>
+     * 
+     * produces a load pattern that increases linearly from one request every 500ms to one request
+     * every 250ms and then stays constant at that level until the run is over. Other parameters are
      * ignored in this case.</li>
      * 
-     * <li><pre>
+     * <li>
+     * 
+     * <pre>
      * delayType = "poisson"
      * minDelay = 250
      * maxDelay = 500
      * cycleType = "none"
-     * rampType = "none" 
-     * </pre> produces inter-arrival times that are poisson distributed with
-     * mean 250ms. Note that when rampType is "none," the value of 
-     * <code>minDelay</code> is used as the (constant) mean delay.</li></ol>
+     * rampType = "none"
+     * </pre>
+     * 
+     * produces inter-arrival times that are poisson distributed with mean 250ms. Note that when
+     * rampType is "none," the value of <code>minDelay</code> is used as the (constant) mean delay.</li>
+     * </ol>
      * 
      * @return next value for delay
      */
-    protected long nextDelay() throws ConfigurationException {
-        double targetDelay = 0; 
-        final double dMinDelay = (double) minDelay;
-        final double dMaxDelay = (double) maxDelay;
+    protected long nextDelay()
+        throws ConfigurationException {
+        double targetDelay = 0;
+        final double dMinDelay = minDelay;
+        final double dMaxDelay = maxDelay;
         final double delayDifference = dMaxDelay - dMinDelay;
         final long currentTime = System.currentTimeMillis();
         if (cycleType.equals("none")) {
-            if (rampType.equals("none") || 
-                    (currentTime - startTime) > rampPeriod) { // ramped up
+            if (rampType.equals("none") || (currentTime - startTime) > rampPeriod) { // ramped up
                 targetDelay = dMinDelay;
             } else if (rampType.equals("linear")) { // single period linear
-                double prop = 
-                    (double) (currentTime - startTime) / (double) rampPeriod;
-                targetDelay =  dMaxDelay - delayDifference * prop;
+                double prop = (double) (currentTime - startTime) / (double) rampPeriod;
+                targetDelay = dMaxDelay - delayDifference * prop;
             } else { // Random jumps down to delay - single period
                 // TODO: govern size of jumps as in oscillating
                 // Where we last were as proportion of way down to minDelay
-                final double lastProp = 
-                    (dMaxDelay - lastMean) / delayDifference;
+                final double lastProp = (dMaxDelay - lastMean) / delayDifference;
                 // Make a random jump toward 1 (1 = all the way down)
                 final double prop = randomData.nextUniform(lastProp, 1);
                 targetDelay = dMaxDelay - delayDifference * prop;
@@ -339,17 +366,15 @@ public abstract class ClientThread imple
         } else if (cycleType.equals("oscillating")) {
             // First change cycle state if we need to
             adjustState(currentTime);
-            targetDelay = computeCyclicDelay(
-                    currentTime, dMinDelay, dMaxDelay);
+            targetDelay = computeCyclicDelay(currentTime, dMinDelay, dMaxDelay);
         } else {
-            throw new ConfigurationException(
-                    "Cycle type not supported: " + cycleType);
+            throw new ConfigurationException("Cycle type not supported: " + cycleType);
         }
 
         // Remember last mean for ramp up / down
         lastMean = targetDelay;
 
-        if (delayType.equals("constant")) { 
+        if (delayType.equals("constant")) {
             return Math.round(targetDelay);
         }
 
@@ -358,82 +383,78 @@ public abstract class ClientThread imple
             return Math.round(randomData.nextGaussian(targetDelay, sigma));
         } else { // must be Poisson
             return randomData.nextPoisson(targetDelay);
-        } 
+        }
     }
-    
+
     /**
-     * Adjusts cycleState, periodStart and lastMean if a cycle state
-     * transition needs to happen.
+     * Adjusts cycleState, periodStart and lastMean if a cycle state transition needs to happen.
      * 
      * @param currentTime current time
      */
     protected void adjustState(long currentTime) {
         long timeInPeriod = currentTime - periodStart;
-        if ( ((cycleState == RAMPING_UP || cycleState == RAMPING_DOWN) && 
-                timeInPeriod < rampPeriod) ||
-             (cycleState == PEAK_LOAD && timeInPeriod < peakPeriod) ||
-             (cycleState == TROUGH_LOAD && timeInPeriod < troughPeriod)) {
+        if (((cycleState == RAMPING_UP || cycleState == RAMPING_DOWN) && timeInPeriod < rampPeriod) ||
+            (cycleState == PEAK_LOAD && timeInPeriod < peakPeriod) ||
+            (cycleState == TROUGH_LOAD && timeInPeriod < troughPeriod)) {
             return; // No state change
         }
         switch (cycleState) {
-            case RAMPING_UP: 
+            case RAMPING_UP:
                 if (peakPeriod > 0) {
                     cycleState = PEAK_LOAD;
                 } else {
                     cycleState = RAMPING_DOWN;
                 }
-                lastMean = (double) minDelay;
+                lastMean = minDelay;
                 periodStart = currentTime;
                 break;
-            
-            case RAMPING_DOWN: 
+
+            case RAMPING_DOWN:
                 if (troughPeriod > 0) {
                     cycleState = TROUGH_LOAD;
                 } else {
                     cycleState = RAMPING_UP;
                 }
-                lastMean = (double) maxDelay;
+                lastMean = maxDelay;
                 periodStart = currentTime;
                 break;
-            
-            case PEAK_LOAD: 
+
+            case PEAK_LOAD:
                 if (rampPeriod > 0) {
                     cycleState = RAMPING_DOWN;
-                    lastMean = (double) minDelay;
+                    lastMean = minDelay;
                 } else {
                     cycleState = TROUGH_LOAD;
-                    lastMean = (double) maxDelay;
+                    lastMean = maxDelay;
                 }
                 periodStart = currentTime;
                 break;
-            
-            case TROUGH_LOAD: 
+
+            case TROUGH_LOAD:
                 if (rampPeriod > 0) {
                     cycleState = RAMPING_UP;
-                    lastMean = (double) maxDelay;
+                    lastMean = maxDelay;
                 } else {
                     cycleState = PEAK_LOAD;
-                    lastMean = (double) minDelay;
+                    lastMean = minDelay;
                 }
                 periodStart = currentTime;
                 break;
-            
-            default: 
-                throw new IllegalStateException(
-                        "Illegal cycle state: " + cycleState);
+
+            default:
+                throw new IllegalStateException("Illegal cycle state: " + cycleState);
         }
     }
-    
-    protected double computeCyclicDelay(
-            long currentTime, double min, double max) {
-        
+
+    protected double computeCyclicDelay(long currentTime, double min, double max) {
+
         // Constant load states
-        if (cycleState == PEAK_LOAD) { 
+        if (cycleState == PEAK_LOAD) {
             return min;
-        } 
+        }
         if (cycleState == TROUGH_LOAD) {
             return max;
-        } 
+        }
 
         // No ramp - stay at min or max load during ramp
         if (rampType.equals("none")) { // min or max, no ramp
@@ -442,32 +463,27 @@ public abstract class ClientThread imple
             } else {
                 return min;
             }
-        } 
+        }
 
         // Linear ramp type and ramping up or down
         double diff = max - min;
         if (rampType.equals("linear")) {
-            double prop = 
-                (double)(currentTime - periodStart) / (double) rampPeriod;
+            double prop = (double) (currentTime - periodStart) / (double) rampPeriod;
             if (cycleState == RAMPING_UP) {
-                return max - diff * prop; 
+                return max - diff * prop;
             } else {
                 return min + diff * prop;
             }
         } else { // random jumps down, then back up
             // Where we last were as proportion of way down to minDelay
-            double lastProp = 
-                (max - lastMean) / diff;
+            double lastProp = (max - lastMean) / diff;
             // Where we would be if this were a linear ramp
-            double linearProp = 
-                (double)(currentTime - periodStart) / (double) rampPeriod;
+            double linearProp = (double) (currentTime - periodStart) / (double) rampPeriod;
             // Need to govern size of jumps, otherwise "convergence"
             // can be too fast - use linear ramp as governor
-            if ((cycleState == RAMPING_UP && (lastProp > linearProp)) || 
-                    (cycleState == RAMPING_DOWN && 
-                            ((1 - lastProp) > linearProp))) 
-                lastProp = (cycleState == RAMPING_UP) ? linearProp : 
-                    (1 - linearProp);
+            if ((cycleState == RAMPING_UP && (lastProp > linearProp)) ||
+                (cycleState == RAMPING_DOWN && ((1 - lastProp) > linearProp)))
+                lastProp = (cycleState == RAMPING_UP) ? linearProp : (1 - linearProp);
             double prop = 0;
             if (cycleState == RAMPING_UP) { // Random jump toward 1
                 prop = randomData.nextUniform(lastProp, 1);
@@ -606,5 +622,5 @@ public abstract class ClientThread imple
     public void setTroughPeriod(long troughPeriod) {
         this.troughPeriod = troughPeriod;
     }
-    
+
 }

Modified: commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/Statistics.java
URL: http://svn.apache.org/viewvc/commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/Statistics.java?rev=1580595&r1=1580594&r2=1580595&view=diff
==============================================================================
--- commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/Statistics.java (original)
+++ commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/Statistics.java Sun Mar 23 20:31:36 2014
@@ -16,73 +16,74 @@
  */
 package org.apache.commons.performance;
 
+import java.io.Serializable;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
-import java.io.Serializable;
-import org.apache.commons.math.stat.descriptive.AggregateSummaryStatistics;
-import org.apache.commons.math.stat.descriptive.SummaryStatistics;
-import org.apache.commons.math.stat.descriptive.StatisticalSummaryValues;
+
+import org.apache.commons.math3.stat.descriptive.AggregateSummaryStatistics;
+import org.apache.commons.math3.stat.descriptive.StatisticalSummaryValues;
+import org.apache.commons.math3.stat.descriptive.SummaryStatistics;
 
 /**
- * <p>Container for {@link SummaryStatistics} accumulated during 
- * {@link ClientThread} executions.</p>
+ * <p>
+ * Container for {@link SummaryStatistics} accumulated during {@link ClientThread} executions.
+ * </p>
+ * 
+ * <p>
+ * Maintains a HashMap of {@link SummaryStatistics} instances with a composite key of the form
+ * (process,type). "Process" typically identifies the client thread and "type" identifies the metric
+ * - e.g., "latency", "numActive."
+ * </p>
  * 
- * <p>Maintains a HashMap of {@link SummaryStatistics} instances with a composite
- * key of the form (process,type).  "Process" typically identifies the client
- * thread and "type" identifies the metric - e.g., "latency", "numActive."</p>
+ * <p>
+ * {@link ClientThread#run()} adds one <code>SummaryStatistics</code> instance, with key = (current
+ * thread id,"latency").
+ * </p>
  * 
- * <p>{@link ClientThread#run()} adds one <code>SummaryStatistics</code>
- * instance, with key = (current thread id,"latency").</p>
- *
  */
-public class Statistics implements Serializable {
-    
+public class Statistics
+    implements Serializable {
+
     /**
-     * Map of SummaryStatistics keyed on <process,type>, where process corresponds
-     * to a thread being monitored and type is a user-supplied characteristic being
-     * measured and tracked.  For example, <thread name, "latency">.
-     */
-    private HashMap<StatisticsKey,SummaryStatistics> data = 
-        new HashMap <StatisticsKey,SummaryStatistics>();
-    
+     * Map of SummaryStatistics keyed on <process,type>, where process corresponds to a thread being
+     * monitored and type is a user-supplied characteristic being measured and tracked. For example,
+     * <thread name, "latency">.
+     */
+    private HashMap<StatisticsKey, SummaryStatistics> data = new HashMap<StatisticsKey, SummaryStatistics>();
+
     /**
-     * Adds the results of the given SummaryStatistics instance under
-     * the key <process,type>
+     * Adds the results of the given SummaryStatistics instance under the key <process,type>
      * 
      * @param stats the SummaryStatistics whose results we are adding
      * @param process name of the associated process
      * @param type description of the associated metric
      */
-    public synchronized void addStatistics(SummaryStatistics stats,
-            String process, String type) {
+    public synchronized void addStatistics(SummaryStatistics stats, String process, String type) {
         StatisticsKey key = new StatisticsKey(process, type);
         data.put(key, stats);
     }
-    
+
     /**
-     * Retrieves the SummaryStatistics corresponding to the given
-     * process and type, if this exists; null otherwise.
+     * Retrieves the SummaryStatistics corresponding to the given process and type, if this exists;
+     * null otherwise.
      * 
      * @param process name of the associated process
      * @param type description of the associated metric
-     * @return SummaryStatistics for the given <process,type>; null if there is
-     * no such element in the container
+     * @return SummaryStatistics for the given <process,type>; null if there is no such element in
+     *         the container
      */
-    public synchronized SummaryStatistics getStatistics(String process,
-            String type) {
+    public synchronized SummaryStatistics getStatistics(String process, String type) {
         StatisticsKey key = new StatisticsKey(process, type);
         return data.get(key);
     }
-    
+
     /**
-     * Returns the full list of SummaryStatistics corresponding to
-     * the given <code>type</code> - i.e, the list of statistics of the 
-     * given type across processes.  For example, 
-     * <code>getStatisticsByType("latency")</code> will return a list of latency
-     * summaries, one for each process, assuming "latency" is the name of 
-     * an accumulated metric.
+     * Returns the full list of SummaryStatistics corresponding to the given <code>type</code> -
+     * i.e, the list of statistics of the given type across processes. For example,
+     * <code>getStatisticsByType("latency")</code> will return a list of latency summaries, one for
+     * each process, assuming "latency" is the name of an accumulated metric.
      * 
      * @param type the type value to get statistics for
      * @return the List of SummaryStatistics stored under the given type
@@ -98,17 +99,15 @@ public class Statistics implements Seria
         }
         return result;
     }
-    
+
     /**
-     * Returns the full list of SummaryStatistics corresponding to
-     * the given <code>process</code> - i.e, the list of statistics of
-     * of different types maintained for the given process. 
+     * Returns the full list of SummaryStatistics corresponding to the given <code>process</code> -
+     * i.e, the list of statistics of of different types maintained for the given process.
      * 
      * @param process the process to get statistics for
      * @return the List of SummaryStatistics for the given process
      */
-    public synchronized List<SummaryStatistics> getStatisticsByProcess(
-            String process) {
+    public synchronized List<SummaryStatistics> getStatisticsByProcess(String process) {
         ArrayList<SummaryStatistics> result = new ArrayList<SummaryStatistics>();
         Iterator<StatisticsKey> it = data.keySet().iterator();
         while (it.hasNext()) {
@@ -119,22 +118,23 @@ public class Statistics implements Seria
         }
         return result;
     }
-    
+
     /**
-     * <p>Returns a SummaryStatistics instance describing the mean of the given
-     * metric across processes - i.e., the "mean of the means", the 
-     * "min of the means" etc. More precisely, the returned SummaryStatistics
-     * describes the distribution of the individual process means for the given
-     * metric.</p>
-     * 
-     * <p>The same results could be obtained by iterating over the result of 
-     * {{@link #getStatisticsByType(String)} for the given <code>type</code>,
-     * extracting the mean and adding its value to a SummaryStatistics
-     * instance.</p>
+     * <p>
+     * Returns a SummaryStatistics instance describing the mean of the given metric across processes
+     * - i.e., the "mean of the means", the "min of the means" etc. More precisely, the returned
+     * SummaryStatistics describes the distribution of the individual process means for the given
+     * metric.
+     * </p>
+     * 
+     * <p>
+     * The same results could be obtained by iterating over the result of {
+     * {@link #getStatisticsByType(String)} for the given <code>type</code>, extracting the mean and
+     * adding its value to a SummaryStatistics instance.
+     * </p>
      * 
      * @param type the metric to get summary mean statistics for
-     * @return a SummaryStatistics instance describing the process means for
-     * the given metric
+     * @return a SummaryStatistics instance describing the process means for the given metric
      */
     public synchronized SummaryStatistics getMeanSummary(String type) {
         SummaryStatistics result = new SummaryStatistics();
@@ -147,14 +147,13 @@ public class Statistics implements Seria
         }
         return result;
     }
-    
+
     /**
-     * Returns SummaryStatistics for the standard deviation of the given metric
-     * across processes.
+     * Returns SummaryStatistics for the standard deviation of the given metric across processes.
      * 
      * @param type the metric to get summary standard deviation statistics for
-     * @return a SummaryStatistics instance describing the process standard
-     * deviations for the given metric
+     * @return a SummaryStatistics instance describing the process standard deviations for the given
+     *         metric
      * @see #getMeanSummary(String)
      */
     public synchronized SummaryStatistics getStdSummary(String type) {
@@ -168,14 +167,12 @@ public class Statistics implements Seria
         }
         return result;
     }
-    
+
     /**
-     * Returns SummaryStatistics for the minimum of the given metric across
-     * processes.
+     * Returns SummaryStatistics for the minimum of the given metric across processes.
      * 
      * @param type the metric to get summary minimum statistics for
-     * @return a SummaryStatistics instance describing the process minima
-     * for the given metric
+     * @return a SummaryStatistics instance describing the process minima for the given metric
      * @see #getMeanSummary(String)
      */
     public synchronized SummaryStatistics getMinSummary(String type) {
@@ -189,14 +186,12 @@ public class Statistics implements Seria
         }
         return result;
     }
-    
+
     /**
-     * Returns SummaryStatistics for the maximum of the given metric across
-     * processes.
+     * Returns SummaryStatistics for the maximum of the given metric across processes.
      * 
      * @param type the metric to get summary maximum statistics for
-     * @return a SummaryStatistics describing the process maxima
-     * for the given metric
+     * @return a SummaryStatistics describing the process maxima for the given metric
      * @see #getMeanSummary(String)
      */
     public synchronized SummaryStatistics getMaxSummary(String type) {
@@ -210,14 +205,13 @@ public class Statistics implements Seria
         }
         return result;
     }
-    
+
     /**
-     * Returns overall SummaryStatistics, aggregating the results for metrics
-     * of the given type across processes.
+     * Returns overall SummaryStatistics, aggregating the results for metrics of the given type
+     * across processes.
      * 
      * @param type the metric to get overall statistics for
-     * @return a SummaryStatistics instance summarizing the combined dataset
-     * for the given metric
+     * @return a SummaryStatistics instance summarizing the combined dataset for the given metric
      */
     public synchronized StatisticalSummaryValues getOverallSummary(String type) {
         ArrayList<SummaryStatistics> contributingStats = new ArrayList<SummaryStatistics>();
@@ -230,7 +224,7 @@ public class Statistics implements Seria
         }
         return AggregateSummaryStatistics.aggregate(contributingStats);
     }
-    
+
     /**
      * Returns the List of processes corresponding to statistics.
      * 
@@ -247,7 +241,7 @@ public class Statistics implements Seria
         }
         return result;
     }
-    
+
     /**
      * Returns the List of types corresponding to statistics.
      * 
@@ -264,13 +258,13 @@ public class Statistics implements Seria
         }
         return result;
     }
-    
+
     /**
-     * Computes and formats display of summary statistics by type, as means of means, etc.
-     * with the process as the unit of observation.  Not currently displayed.
-     * TODO: Make inclusion of this report configurable.
+     * Computes and formats display of summary statistics by type, as means of means, etc. with the
+     * process as the unit of observation. Not currently displayed. TODO: Make inclusion of this
+     * report configurable.
      * 
-     * @return String representing summaries for each metric 
+     * @return String representing summaries for each metric
      */
     public synchronized String displayProcessLevelSummary() {
         Iterator<String> metricsIterator = getTypes().iterator();
@@ -301,8 +295,7 @@ public class Statistics implements Seria
     }
 
     /**
-     * Displays overall statistics for each metric, aggregating data
-     * across threads.
+     * Displays overall statistics for each metric, aggregating data across threads.
      * 
      * @return overall statistics report
      */
@@ -321,13 +314,12 @@ public class Statistics implements Seria
         }
         return buffer.toString();
     }
-    
+
     /**
      * Displays statistics for the given process
      * 
      * @param process the process to retrieve metrics for
-     * @return String representing all currently defined statistics for the
-     * given process
+     * @return String representing all currently defined statistics for the given process
      */
     public synchronized String displayProcessStatistics(String process) {
         Iterator<String> metricsIterator = getTypes().iterator();
@@ -344,33 +336,40 @@ public class Statistics implements Seria
         }
         return buffer.toString();
     }
-    
-    
+
     /**
      * Composite key (<process,type>).
      */
-    private static class StatisticsKey implements Serializable {
+    private static class StatisticsKey
+        implements Serializable {
+
         public StatisticsKey(String process, String type) {
             this.process = process;
             this.type = type;
         }
+
         private String process = null;
         private String type = null;
+
+        @Override
         public boolean equals(Object obj) {
             if (!(obj instanceof StatisticsKey) || obj == null) {
                 return false;
             } else {
                 StatisticsKey other = (StatisticsKey) obj;
-                return (other.process.equals(this.process)) &&
-                    (other.type.equals(this.type));  
+                return (other.process.equals(this.process)) && (other.type.equals(this.type));
             }
         }
+
+        @Override
         public int hashCode() {
             return 7 + 11 * process.hashCode() + 17 * type.hashCode();
-        } 
+        }
+
         public String getType() {
             return type;
         }
+
         public String getProcess() {
             return process;
         }

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=1580595&r1=1580594&r2=1580595&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 20:31:36 2014
@@ -17,48 +17,48 @@
 
 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 javax.sql.DataSource;
+
 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.math3.random.RandomDataGenerator;
+import org.apache.commons.performance.ClientThread;
+import org.apache.commons.performance.ConfigurationException;
+import org.apache.commons.performance.LoadGenerator;
+import org.apache.commons.performance.Statistics;
 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;
 import org.apache.tomcat.jdbc.pool.PoolProperties;
- 
+
 /**
- * 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.
- *
+ * 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 {
+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;
@@ -80,19 +80,21 @@ public class DBCPSoak extends LoadGenera
     private int maxIdle;
     private int minIdle;
     private long maxWait;
-    
+
     // DataSource type
     private String dataSourceType;
-    
+
     // Instance variables
-    private GenericObjectPool connectionPool; 
+    private GenericObjectPool connectionPool;
     private DataSource dataSource;
-    
+
     /**
      * Create connection pool and, if necessary, test table.
      */
-    protected void init() throws Exception {
-        
+    @Override
+    protected void init()
+        throws Exception {
+
         if (dataSourceType.equals("BasicDataSource")) {
             org.apache.commons.dbcp.BasicDataSource bds = new org.apache.commons.dbcp.BasicDataSource();
             bds.setDefaultAutoCommit(autocommit);
@@ -114,13 +116,13 @@ public class DBCPSoak extends LoadGenera
             bds.setTimeBetweenEvictionRunsMillis(timeBetweenEvictions);
             bds.setValidationQuery(validationQuery);
             if (poolType.equals("AbandonedObjectPool")) {
-                    bds.setRemoveAbandoned(true);
+                bds.setRemoveAbandoned(true);
             }
-            dataSource = bds; 
+            dataSource = bds;
             checkDatabase();
             return;
         }
-        
+
         if (dataSourceType.equals("BasicDataSource2")) {
             org.apache.commons.dbcp2.BasicDataSource bds = new org.apache.commons.dbcp2.BasicDataSource();
             bds.setDefaultAutoCommit(autocommit);
@@ -129,9 +131,9 @@ public class DBCPSoak extends LoadGenera
             bds.setUsername(connectUser);
             bds.setDriverClassName(driverClass);
             bds.setMinEvictableIdleTimeMillis(idleTimeout);
-            bds.setMaxActive(maxActive);
+            bds.setMaxTotal(maxActive);
             bds.setMaxIdle(maxIdle);
-            bds.setMaxWait(maxWait);
+            bds.setMaxWaitMillis(maxWait);
             bds.setMinIdle(minIdle);
             bds.setPoolPreparedStatements(poolPreparedStatements);
             bds.setDefaultReadOnly(readOnly);
@@ -142,13 +144,13 @@ public class DBCPSoak extends LoadGenera
             bds.setTimeBetweenEvictionRunsMillis(timeBetweenEvictions);
             bds.setValidationQuery(validationQuery);
             if (poolType.equals("AbandonedObjectPool")) {
-                    bds.setRemoveAbandoned(true);
+                bds.setRemoveAbandonedOnBorrow(true);
             }
-            dataSource = bds; 
+            dataSource = bds;
             checkDatabase();
             return;
         }
-        
+
         if (dataSourceType.equals("tomcat-jdbc-pool")) {
             PoolProperties config = new PoolProperties();
             config.setDefaultAutoCommit(autocommit);
@@ -173,71 +175,66 @@ public class DBCPSoak extends LoadGenera
         }
 
         Class.forName(driverClass);
-        
+
         // Create object pool
         if (poolType.equals("GenericObjectPool")) {
-            connectionPool = new org.apache.commons.pool.impl.GenericObjectPool(
-                    null, maxActive, exhaustedAction,
-                    maxWait, maxIdle, minIdle, testOnBorrow, testOnReturn,
-                    timeBetweenEvictions, testsPerEviction, idleTimeout,
-                    testWhileIdle);
+            connectionPool = new org.apache.commons.pool.impl.GenericObjectPool(null, maxActive, exhaustedAction,
+                                                                                maxWait, maxIdle, minIdle,
+                                                                                testOnBorrow, testOnReturn,
+                                                                                timeBetweenEvictions, testsPerEviction,
+                                                                                idleTimeout, testWhileIdle);
         } else if (poolType.equals("AbandonedObjectPool")) {
-            connectionPool = new org.apache.commons.dbcp.AbandonedObjectPool(null,abandonedConfig);
+            connectionPool = new org.apache.commons.dbcp.AbandonedObjectPool(null, abandonedConfig);
         } else {
-            throw new ConfigurationException(
-                    "invalid pool type configuration: " + poolType);
+            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);
+            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);
+            connectionFactory = new DriverConnectionFactory((Driver) Class.forName(driverClass).newInstance(),
+                                                            connectUrl, props);
         } else {
-            throw new ConfigurationException(
-            "Bad config setting for driver type"); 
-        } 
-   
+            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
+            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);
+            poolableConnectionFactory = new PoolableConnectionFactory(connectionFactory, connectionPool,
+                                                                      statementPoolFactory, validationQuery, readOnly,
+                                                                      autocommit);
         } else if (factoryType.equals("CPDSConnectionFactory")) {
-            throw new ConfigurationException(
-            "CPDSConnectionFactory not implemented yet");
+            throw new ConfigurationException("CPDSConnectionFactory not implemented yet");
         } else {
-            throw new ConfigurationException(
-                    "Invalid factory type: " + factoryType);
+            throw new ConfigurationException("Invalid factory type: " + factoryType);
         }
-        
+
         // Create DataSource
-        dataSource = new PoolingDataSource(connectionPool); 
-        checkDatabase();   
+        dataSource = new PoolingDataSource(connectionPool);
+        checkDatabase();
     }
-    
-    protected void checkDatabase() throws Exception {
-        // Try to connect and query test_table. If "test_table" appears in 
-        // exception message, assume table needs to be created. 
+
+    protected void checkDatabase()
+        throws Exception {
+        // 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();
@@ -255,11 +252,13 @@ public class DBCPSoak extends LoadGenera
             conn.close();
         }
     }
-    
+
     /**
      * Close connection pool
      */
-    protected void cleanUp() throws Exception {
+    @Override
+    protected void cleanUp()
+        throws Exception {
         if (dataSourceType.equals("BasicDataSource")) {
             ((org.apache.commons.dbcp.BasicDataSource) dataSource).close();
         } else if (dataSourceType.equals("tomcat-jdbc-pool")) {
@@ -268,57 +267,49 @@ public class DBCPSoak extends LoadGenera
             ((org.apache.commons.dbcp2.BasicDataSource) dataSource).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);
+
+    @Override
+    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) {
+    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 configureDataSource(String type) {
         this.dataSourceType = type;
     }
-    
-    public void configureConnectionFactory(String type,
-            String autoCommit, String readOnly, String validationQuery) {
+
+    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) {
+
+    public void configurePoolableConnectionFactory(String type, String poolPreparedStatements, String maxOpenStatements) {
         this.factoryType = type;
-        this.poolPreparedStatements = 
-            Boolean.parseBoolean(poolPreparedStatements);
+        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 { 
+
+    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);
@@ -336,54 +327,45 @@ public class DBCPSoak extends LoadGenera
             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) {
+        } 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));
+        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>
+     * 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);
+    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)";
+            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();
+            RandomDataGenerator randomData = new RandomDataGenerator();
             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 + ");";
+                sqlText = "INSERT INTO test_table (indexed, text, not_indexed)" + "VALUES (" + indexed + "," + "'" +
+                          text + "'," + not_indexed + ");";
                 sql.executeUpdate(sqlText);
             }
             sql.close();
@@ -391,82 +373,56 @@ public class DBCPSoak extends LoadGenera
             db.close();
         }
     }
-    
+
     /**
-     * Add dbcp configuration to parameters loaded by super.
-     * Also set config file name.
+     * Add dbcp configuration to parameters loaded by super. Also set config file name.
      */
-    protected void configure() throws Exception {
-        
+    @Override
+    protected void configure()
+        throws Exception {
+
         super.configure();
-        
-        digester.addCallMethod("configuration/database",
-                "configureDataBase", 5);
+
+        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", "configureDataSource", 1);
         digester.addCallParam("configuration/datasource-type", 0);
-        
-        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);
-        
+
+        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";
     }
 }

Modified: commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/pool/PoolClientThread.java
URL: http://svn.apache.org/viewvc/commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/pool/PoolClientThread.java?rev=1580595&r1=1580594&r2=1580595&view=diff
==============================================================================
--- commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/pool/PoolClientThread.java (original)
+++ commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/pool/PoolClientThread.java Sun Mar 23 20:31:36 2014
@@ -25,59 +25,62 @@ import java.util.logging.Logger;
 //import org.apache.commons.pool2.ObjectPool;
 //import org.apache.commons.pool.KeyedObjectPool;
 //import org.apache.commons.pool2.KeyedObjectPool;
-import org.apache.commons.math.random.RandomData;
-import org.apache.commons.math.random.RandomDataImpl;
-import org.apache.commons.math.stat.descriptive.SummaryStatistics;
+import org.apache.commons.math3.random.RandomDataGenerator;
+import org.apache.commons.math3.stat.descriptive.SummaryStatistics;
 import org.apache.commons.performance.ClientThread;
 import org.apache.commons.performance.Statistics;
 
 /**
- * <p>Client thread that borrows and returns objects from a pool in a loop.
- * See {@link ClientThread ClientThread javadoc} for a description
- * of how times between requests are computed.  In addition to request latency,
- * pool numIdle and numActive statistics and stats on instance idle time are tracked.
- * Constructors are provided for both 1.x and version 2 simple and keyed pools.</p>
+ * <p>
+ * Client thread that borrows and returns objects from a pool in a loop. See {@link ClientThread
+ * ClientThread javadoc} for a description of how times between requests are computed. In addition
+ * to request latency, pool numIdle and numActive statistics and stats on instance idle time are
+ * tracked. Constructors are provided for both 1.x and version 2 simple and keyed pools.
+ * </p>
  * 
- * <p>Note that this class is *not* threadsafe.</p>
+ * <p>
+ * Note that this class is *not* threadsafe.
+ * </p>
  */
-public class PoolClientThread extends ClientThread {
-    
+public class PoolClientThread
+    extends ClientThread {
+
     /** Version 1.x object pool (if keyed = false) */
     private final org.apache.commons.pool.ObjectPool pool;
-    
+
     /** Version 1.x keyed pool (if keyed = true) */
     private final org.apache.commons.pool.KeyedObjectPool keyedPool;
-    
+
     /** Version 2 object pool (if keyed = false) */
     private final org.apache.commons.pool2.ObjectPool<Waiter> pool2;
-    
+
     /** Version 2 keyed pool (if keyed = true) */
     private final org.apache.commons.pool2.KeyedObjectPool<Integer, Waiter> keyedPool2;
-    
+
     /** Whether or not pool being tested is keyed */
     private boolean keyed;
-    
+
     /** Randomly generated keys (if keyed = true) */
-    private List<Integer> keys; 
-    
+    private List<Integer> keys;
+
     /** Source of randomness (for keys, if keyed = true) */
-    private final RandomData randomData = new RandomDataImpl(); 
-    
+    private final RandomDataGenerator randomData = new RandomDataGenerator();
+
     /** Statistics on numActive */
     private SummaryStatistics numActiveStats = new SummaryStatistics();
-    
+
     /** Statistics on numIdle */
     private SummaryStatistics numIdleStats = new SummaryStatistics();
-    
+
     /** Sampling rate for numActive, numIdle */
     private double samplingRate;
-    
+
     /** Statistics on instance idle time */
     private SummaryStatistics instanceIdleTimeStats = new SummaryStatistics();
-    
+
     /** Just-borrowed Waiter instance (used to grab idle time stats in cleanUp) */
     private Waiter waiter = null;
-     
+
     /**
      * Create a pool client thread for a version 1.x ObjectPool.
      * 
@@ -93,18 +96,16 @@ public class PoolClientThread extends Cl
      * @param logger common logger shared by all clients
      * @param stats Statistics container
      * @param pool ObjectPool
-     * @param samplingRate proportion of requests for which numIdle and numActive
-     * will be sampled for statistical analysis
+     * @param samplingRate proportion of requests for which numIdle and numActive will be sampled
+     *        for statistical analysis
      */
-    public PoolClientThread(long iterations, long minDelay, long maxDelay,
-            double sigma, String delayType, long rampPeriod, long peakPeriod,
-            long troughPeriod, String cycleType, String rampType, Logger logger, 
-            Statistics stats, org.apache.commons.pool.ObjectPool pool,
-            double samplingRate) {
-        
-        super(iterations, minDelay, maxDelay, sigma, delayType, rampPeriod,
-                peakPeriod, troughPeriod, cycleType,rampType, logger, 
-                stats); 
+    public PoolClientThread(long iterations, long minDelay, long maxDelay, double sigma, String delayType,
+                            long rampPeriod, long peakPeriod, long troughPeriod, String cycleType, String rampType,
+                            Logger logger, Statistics stats, org.apache.commons.pool.ObjectPool pool,
+                            double samplingRate) {
+
+        super(iterations, minDelay, maxDelay, sigma, delayType, rampPeriod, peakPeriod, troughPeriod, cycleType,
+              rampType, logger, stats);
         this.pool = pool;
         this.pool2 = null;
         this.keyedPool2 = null;
@@ -112,7 +113,7 @@ public class PoolClientThread extends Cl
         this.keyed = false;
         this.samplingRate = samplingRate;
     }
-    
+
     /**
      * Create a pool client thread for a version 1.x KeyedObjectPool.
      * 
@@ -126,21 +127,19 @@ public class PoolClientThread extends Cl
      * @param cycleType type of cycle for mean delay
      * @param rampType type of ramp (linear or random jumps)
      * @param logger common logger shared by all clients
-     * @param stats Statistics container 
+     * @param stats Statistics container
      * @param keyedPool KeyedObjectPool
-     * @param samplingRate proportion of requests for which numIdle and numActive
-     * will be sampled for statistical analysis
+     * @param samplingRate proportion of requests for which numIdle and numActive will be sampled
+     *        for statistical analysis
      */
-    public PoolClientThread(long iterations, long minDelay, long maxDelay,
-            double sigma, String delayType, long rampPeriod, long peakPeriod,
-            long troughPeriod, String cycleType, String rampType, Logger logger, 
-            Statistics stats, org.apache.commons.pool.KeyedObjectPool keyedPool,
-            double samplingRate) {
-        
-        super(iterations, minDelay, maxDelay, sigma, delayType, rampPeriod,
-                peakPeriod, troughPeriod, cycleType,rampType, logger, 
-                stats); 
-        
+    public PoolClientThread(long iterations, long minDelay, long maxDelay, double sigma, String delayType,
+                            long rampPeriod, long peakPeriod, long troughPeriod, String cycleType, String rampType,
+                            Logger logger, Statistics stats, org.apache.commons.pool.KeyedObjectPool keyedPool,
+                            double samplingRate) {
+
+        super(iterations, minDelay, maxDelay, sigma, delayType, rampPeriod, peakPeriod, troughPeriod, cycleType,
+              rampType, logger, stats);
+
         this.keyedPool = keyedPool;
         this.pool = null;
         this.pool2 = null;
@@ -148,11 +147,11 @@ public class PoolClientThread extends Cl
         this.keyed = true;
         this.samplingRate = samplingRate;
         keys = new ArrayList<Integer>();
-        for (int i = 0; i < 20; i++) { //TODO: make number of keys configurable
+        for (int i = 0; i < 20; i++) { // TODO: make number of keys configurable
             keys.add(new Integer(i));
         }
     }
-    
+
     /**
      * Create a pool client thread for a version 1.x ObjectPool.
      * 
@@ -168,18 +167,16 @@ public class PoolClientThread extends Cl
      * @param logger common logger shared by all clients
      * @param stats Statistics container
      * @param pool ObjectPool
-     * @param samplingRate proportion of requests for which numIdle and numActive
-     * will be sampled for statistical analysis
+     * @param samplingRate proportion of requests for which numIdle and numActive will be sampled
+     *        for statistical analysis
      */
-    public PoolClientThread(long iterations, long minDelay, long maxDelay,
-            double sigma, String delayType, long rampPeriod, long peakPeriod,
-            long troughPeriod, String cycleType, String rampType, Logger logger, 
-            Statistics stats, org.apache.commons.pool2.ObjectPool<Waiter> pool,
-            double samplingRate) {
-        
-        super(iterations, minDelay, maxDelay, sigma, delayType, rampPeriod,
-                peakPeriod, troughPeriod, cycleType,rampType, logger, 
-                stats); 
+    public PoolClientThread(long iterations, long minDelay, long maxDelay, double sigma, String delayType,
+                            long rampPeriod, long peakPeriod, long troughPeriod, String cycleType, String rampType,
+                            Logger logger, Statistics stats, org.apache.commons.pool2.ObjectPool<Waiter> pool,
+                            double samplingRate) {
+
+        super(iterations, minDelay, maxDelay, sigma, delayType, rampPeriod, peakPeriod, troughPeriod, cycleType,
+              rampType, logger, stats);
         this.pool2 = pool;
         this.pool = null;
         this.keyedPool2 = null;
@@ -187,7 +184,7 @@ public class PoolClientThread extends Cl
         this.keyed = false;
         this.samplingRate = samplingRate;
     }
-    
+
     /**
      * Create a pool client thread for a version 1.x KeyedObjectPool.
      * 
@@ -201,21 +198,19 @@ public class PoolClientThread extends Cl
      * @param cycleType type of cycle for mean delay
      * @param rampType type of ramp (linear or random jumps)
      * @param logger common logger shared by all clients
-     * @param stats Statistics container 
+     * @param stats Statistics container
      * @param keyedPool KeyedObjectPool
-     * @param samplingRate proportion of requests for which numIdle and numActive
-     * will be sampled for statistical analysis
+     * @param samplingRate proportion of requests for which numIdle and numActive will be sampled
+     *        for statistical analysis
      */
-    public PoolClientThread(long iterations, long minDelay, long maxDelay,
-            double sigma, String delayType, long rampPeriod, long peakPeriod,
-            long troughPeriod, String cycleType, String rampType, Logger logger, 
-            Statistics stats, org.apache.commons.pool2.KeyedObjectPool<Integer, Waiter> keyedPool,
-            double samplingRate) {
-        
-        super(iterations, minDelay, maxDelay, sigma, delayType, rampPeriod,
-                peakPeriod, troughPeriod, cycleType,rampType, logger, 
-                stats); 
-        
+    public PoolClientThread(long iterations, long minDelay, long maxDelay, double sigma, String delayType,
+                            long rampPeriod, long peakPeriod, long troughPeriod, String cycleType, String rampType,
+                            Logger logger, Statistics stats,
+                            org.apache.commons.pool2.KeyedObjectPool<Integer, Waiter> keyedPool, double samplingRate) {
+
+        super(iterations, minDelay, maxDelay, sigma, delayType, rampPeriod, peakPeriod, troughPeriod, cycleType,
+              rampType, logger, stats);
+
         this.keyedPool2 = keyedPool;
         this.pool = null;
         this.pool2 = null;
@@ -223,48 +218,46 @@ public class PoolClientThread extends Cl
         this.keyed = true;
         this.samplingRate = samplingRate;
         keys = new ArrayList<Integer>();
-        for (int i = 0; i < 20; i++) { //TODO: make number of keys configurable
+        for (int i = 0; i < 20; i++) { // TODO: make number of keys configurable
             keys.add(new Integer(i));
         }
     }
-    
+
     /** Borrow and return */
-    public void execute() throws Exception {
-       if (keyed) {
-           Integer key = keys.get(randomData.nextInt(0, 19));
-           waiter = keyedPool2 == null ? (Waiter) keyedPool.borrowObject(key) :
-               keyedPool2.borrowObject(key);
-           waiter.doWait();
-           if (keyedPool2 == null) {
-               keyedPool.returnObject(key, waiter);
-           } else {
-               keyedPool2.returnObject(key, waiter);
-           }
-       } else {
-           waiter = pool2 == null ? (Waiter) pool.borrowObject() :
-               pool2.borrowObject(); 
-           waiter.doWait();
-           if (pool2 == null) {
-               pool.returnObject(waiter);
-           } else {
-               pool2.returnObject(waiter);
-           }
-       }
+    @Override
+    public void execute()
+        throws Exception {
+        if (keyed) {
+            Integer key = keys.get(randomData.nextInt(0, 19));
+            waiter = keyedPool2 == null ? (Waiter) keyedPool.borrowObject(key) : keyedPool2.borrowObject(key);
+            waiter.doWait();
+            if (keyedPool2 == null) {
+                keyedPool.returnObject(key, waiter);
+            } else {
+                keyedPool2.returnObject(key, waiter);
+            }
+        } else {
+            waiter = pool2 == null ? (Waiter) pool.borrowObject() : pool2.borrowObject();
+            waiter.doWait();
+            if (pool2 == null) {
+                pool.returnObject(waiter);
+            } else {
+                pool2.returnObject(waiter);
+            }
+        }
     }
-    
-    protected void cleanUp() throws Exception {
-        // Capture pool metrics 
+
+    @Override
+    protected void cleanUp()
+        throws Exception {
+        // Capture pool metrics
         if (randomData.nextUniform(0, 1) < samplingRate) {
             if (keyed) {
-                numIdleStats.addValue(keyedPool2 == null ? keyedPool.getNumIdle() :
-                    keyedPool2.getNumIdle());
-                numActiveStats.addValue(keyedPool2 == null ? keyedPool.getNumActive() :
-                    keyedPool2.getNumActive());
+                numIdleStats.addValue(keyedPool2 == null ? keyedPool.getNumIdle() : keyedPool2.getNumIdle());
+                numActiveStats.addValue(keyedPool2 == null ? keyedPool.getNumActive() : keyedPool2.getNumActive());
             } else {
-                numIdleStats.addValue(pool2 == null ? pool.getNumIdle() :
-                    pool2.getNumIdle());
-                numActiveStats.addValue(pool2 == null ? pool.getNumActive() :
-                    pool2.getNumActive());
+                numIdleStats.addValue(pool2 == null ? pool.getNumIdle() : pool2.getNumIdle());
+                numActiveStats.addValue(pool2 == null ? pool.getNumActive() : pool2.getNumActive());
             }
         }
         if (waiter != null) {
@@ -272,14 +265,13 @@ public class PoolClientThread extends Cl
         }
         waiter = null;
     }
-    
-    protected void finish() throws Exception {
+
+    @Override
+    protected void finish()
+        throws Exception {
         // Add metrics to stats
-        stats.addStatistics(
-                numIdleStats, Thread.currentThread().getName(), "numIdle");
-        stats.addStatistics(
-                numActiveStats, Thread.currentThread().getName(), "numActive");
-        stats.addStatistics(
-                instanceIdleTimeStats, Thread.currentThread().getName(), "instance idle time");
+        stats.addStatistics(numIdleStats, Thread.currentThread().getName(), "numIdle");
+        stats.addStatistics(numActiveStats, Thread.currentThread().getName(), "numActive");
+        stats.addStatistics(instanceIdleTimeStats, Thread.currentThread().getName(), "instance idle time");
     }
 }