Bug 55084 - Add timeout support for JDBC Request

Bugzilla Id: 55084

git-svn-id: https://svn.apache.org/repos/asf/jmeter/trunk@1491213 13f79535-47bb-0310-9956-ffa450edef68

Former-commit-id: 8b6438ad9b
This commit is contained in:
Philippe Mouawad 2013-06-09 13:07:32 +00:00
parent c1c64f6324
commit a26ea01b0d
5 changed files with 56 additions and 8 deletions

View File

@ -35,6 +35,7 @@ import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import org.apache.commons.lang3.StringUtils;
import org.apache.jmeter.samplers.SampleResult;
import org.apache.jmeter.save.CSVSaveService;
import org.apache.jmeter.testelement.AbstractTestElement;
@ -111,7 +112,8 @@ public abstract class AbstractJDBCTestElement extends AbstractTestElement implem
private String queryArguments = ""; // $NON-NLS-1$
private String queryArgumentsTypes = ""; // $NON-NLS-1$
private String variableNames = ""; // $NON-NLS-1$
private String resultVariable = "";
private String resultVariable = ""; // $NON-NLS-1$
private String queryTimeout = ""; // $NON-NLS-1$
/**
* Cache of PreparedStatements stored in a per-connection basis. Each entry of this
@ -142,6 +144,7 @@ public abstract class AbstractJDBCTestElement extends AbstractTestElement implem
String _queryType = getQueryType();
if (SELECT.equals(_queryType)) {
stmt = conn.createStatement();
stmt.setQueryTimeout(getIntegerQueryTimeout());
ResultSet rs = null;
try {
rs = stmt.executeQuery(getQuery());
@ -159,6 +162,7 @@ public abstract class AbstractJDBCTestElement extends AbstractTestElement implem
return sb.getBytes(ENCODING);
} else if (UPDATE.equals(_queryType)) {
stmt = conn.createStatement();
stmt.setQueryTimeout(getIntegerQueryTimeout());
stmt.executeUpdate(getQuery());
int updateCount = stmt.getUpdateCount();
String results = updateCount + " updates";
@ -332,9 +336,15 @@ public abstract class AbstractJDBCTestElement extends AbstractTestElement implem
} else {
pstmt = conn.prepareStatement(getQuery());
}
pstmt.setQueryTimeout(getIntegerQueryTimeout());
// PreparedStatementMap is associated to one connection so
// 2 threads cannot use the same PreparedStatement map at the same time
preparedStatementMap.put(getQuery(), pstmt);
} else {
int timeoutInS = getIntegerQueryTimeout();
if(pstmt.getQueryTimeout() != timeoutInS) {
pstmt.setQueryTimeout(getIntegerQueryTimeout());
}
}
pstmt.clearParameters();
return pstmt;
@ -457,6 +467,35 @@ public abstract class AbstractJDBCTestElement extends AbstractTestElement implem
} catch (SQLException e) {
log.warn("Error closing ResultSet", e);
}
}
/**
* @return the integer representation queryTimeout
*/
public int getIntegerQueryTimeout() {
int timeout = 0;
try {
if(StringUtils.isNumeric(query)) {
timeout = Integer.parseInt(queryTimeout);
}
} catch (NumberFormatException nfe) {
timeout = 0;
}
return timeout;
}
/**
* @return the queryTimeout
*/
public String getQueryTimeout() {
return queryTimeout ;
}
/**
* @param resultVariable the variable name in which results will be stored
*/
public void setQueryTimeout(String queryTimeout) {
this.queryTimeout = queryTimeout;
}
public String getQuery() {

View File

@ -42,28 +42,33 @@ public abstract class JDBCTestElementBeanInfoSupport extends BeanInfoSupport {
"queryArgumentsTypes", // $NON-NLS-1$
"variableNames", // $NON-NLS-1$
"resultVariable", // $NON-NLS-1$
"queryTimeout" // $NON-NLS-1$
});
PropertyDescriptor p = property("dataSource"); // $NON-NLS-1$
p.setValue(NOT_UNDEFINED, Boolean.TRUE);
p.setValue(DEFAULT, "");
p.setValue(DEFAULT, ""); // $NON-NLS-1$
p = property("queryArguments"); // $NON-NLS-1$
p.setValue(NOT_UNDEFINED, Boolean.TRUE);
p.setValue(DEFAULT, "");
p.setValue(DEFAULT, ""); // $NON-NLS-1$
p = property("queryArgumentsTypes"); // $NON-NLS-1$
p.setValue(NOT_UNDEFINED, Boolean.TRUE);
p.setValue(DEFAULT, "");
p.setValue(DEFAULT, ""); // $NON-NLS-1$
p = property("variableNames"); // $NON-NLS-1$
p.setValue(NOT_UNDEFINED, Boolean.TRUE);
p.setValue(DEFAULT, "");
p.setValue(DEFAULT, ""); // $NON-NLS-1$
p = property("resultVariable"); // $NON-NLS-1$
p.setValue(NOT_UNDEFINED, Boolean.TRUE);
p.setValue(DEFAULT, "");
p.setValue(DEFAULT, ""); // $NON-NLS-1$
p = property("queryTimeout"); // $NON-NLS-1$
p.setValue(NOT_UNDEFINED, Boolean.TRUE);
p.setValue(DEFAULT, "");
p = property("queryType"); // $NON-NLS-1$
p.setValue(NOT_UNDEFINED, Boolean.TRUE);
p.setValue(DEFAULT, AbstractJDBCTestElement.SELECT);
@ -82,7 +87,7 @@ public abstract class JDBCTestElementBeanInfoSupport extends BeanInfoSupport {
p = property("query"); // $NON-NLS-1$
p.setValue(NOT_UNDEFINED, Boolean.TRUE);
p.setValue(DEFAULT, "");
p.setValue(DEFAULT, ""); // $NON-NLS-1$
p.setPropertyEditorClass(TextAreaEditor.class);
}

View File

@ -30,4 +30,5 @@ variableNames.displayName=Variable names
variableNames.shortDescription=Output variable names for each column (comma separated)
resultVariable.displayName=Result variable name
resultVariable.shortDescription=Name of the JMeter variable that stores the result set objects in a list of maps for looking up results by column name.
queryTimeout.displayName=Query timeout
queryTimeout.shortDescription=The timeout of statement measured in seconds

View File

@ -31,3 +31,5 @@ sql.displayName=Requ\u00EAte SQL
varName.displayName=Nom de liaison avec le pool
variableNames.displayName=Noms des variables
variableNames.shortDescription=Noms des variables en sortie pour chaque colonne (s\u00E9par\u00E9s par des virgules)
queryTimeout.displayName=Timeout de la requ\u00EAte
queryTimeout.shortDescription=Timeout de le requ\u00EAte en secondes

View File

@ -174,6 +174,7 @@ Transaction Controller now sets Response Code of Generated Parent Sampler (if Ge
<li><bugzilla>54798</bugzilla> - Using subject from EML-file for SMTP Sampler</li>
<li><bugzilla>54759</bugzilla> - SSLPeerUnverifiedException using HTTPS , property documented</li>
<li><bugzilla>54896</bugzilla> - JUnit sampler gives only “failed to create an instance of the class” message with constructor problems</li>
<li><bugzilla>55084</bugzilla> - Add timeout support for JDBC Request</li>
</ul>
<h3>Controllers</h3>