Author: psteitz
Date: Fri Apr 2 22:25:36 2021
New Revision: 1888320
URL: http://svn.apache.org/viewvc?rev=1888320&view=rev
Log:
Reformat
Modified:
commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/dbcp/DBCPSoak.java
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=1888320&r1=1888319&r2=1888320&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
Fri Apr 2 22:25:36 2021
@@ -1,18 +1,15 @@
/*
* 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.
+ * 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;
@@ -45,41 +42,66 @@ import org.apache.commons.pool.impl.Gene
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 {
+ 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;
+
private double samplingRate;
// DataSource type
@@ -87,6 +109,7 @@ public class DBCPSoak
// Instance variables
private GenericObjectPool connectionPool;
+
private DataSource dataSource;
/**
@@ -179,27 +202,38 @@ public class DBCPSoak
// 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");
}
@@ -209,22 +243,31 @@ public class DBCPSoak
KeyedObjectPoolFactory statementPoolFactory = null;
if (poolPreparedStatements) { // Use same defaults as BasicDataSource
statementPoolFactory = new GenericKeyedObjectPoolFactory(null, -1,
// unlimited
-
// maxActive (per
+
// maxActive
+
// (per
// key)
-
GenericKeyedObjectPool.WHEN_EXHAUSTED_FAIL, 0, // maxWait
- 1, //
maxIdle (per key)
+
GenericKeyedObjectPool.WHEN_EXHAUSTED_FAIL,
+ 0, //
maxWait
+ 1, //
maxIdle
+ // (per
+ // key)
maxOpenStatements); // TODO:
-
// make all
+
// make
+
// all
// configurable
}
if (factoryType.equals("PoolableConnectionFactory")) {
- poolableConnectionFactory = new
PoolableConnectionFactory(connectionFactory, connectionPool,
-
statementPoolFactory, validationQuery, readOnly,
+ 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);
+ throw new ConfigurationException("Invalid factory type: " +
+ factoryType);
}
// Create DataSource
@@ -270,12 +313,16 @@ public class DBCPSoak
}
@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,
+ 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,
samplingRate);
}
@@ -283,7 +330,8 @@ public class DBCPSoak
// 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;
@@ -295,22 +343,32 @@ public class DBCPSoak
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, String
samplingRate)
+ 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,
+ String samplingRate)
throws ConfigurationException {
this.maxActive = Integer.parseInt(maxActive);
this.maxIdle = Integer.parseInt(maxIdle);
@@ -330,20 +388,26 @@ public class DBCPSoak
} else if (exhaustedAction.equals("grow")) {
this.exhaustedAction = GenericObjectPool.WHEN_EXHAUSTED_GROW;
} else {
- throw new ConfigurationException("Bad configuration setting for
exhausted action: " + exhaustedAction);
+ throw new ConfigurationException("Bad configuration setting for
exhausted action: " +
+ exhaustedAction);
}
this.samplingRate = Double.parseDouble(samplingRate);
}
- public void configureAbandonedConfig(String logAbandoned, String
removeAbandoned, String abandonedTimeout) {
+ 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:
+ * 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>
@@ -355,10 +419,12 @@ public class DBCPSoak
protected void makeTable()
throws Exception {
Class.forName(driverClass);
- Connection db = DriverManager.getConnection(connectUrl, connectUser,
connectPassword);
+ 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);
@@ -367,8 +433,9 @@ public class DBCPSoak
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();
@@ -378,7 +445,8 @@ public class DBCPSoak
}
/**
- * 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.
*/
@Override
protected void configure()
@@ -386,7 +454,8 @@ public class DBCPSoak
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);
@@ -396,16 +465,26 @@ public class DBCPSoak
digester.addCallMethod("configuration", "configureDataSource", 1);
digester.addCallParam("configuration/datasource-type", 0);
- digester.addCallMethod("configuration/connection-factory",
"configureConnectionFactory", 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/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
+ .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", 13);
digester.addCallParam("configuration/pool/max-active", 0);
@@ -422,10 +501,15 @@ public class DBCPSoak
digester.addCallParam("configuration/pool/type", 11);
digester.addCallParam("configuration/pool/sampling-rate", 12);
- 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/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";
}