From 8b6438ad9bde1e342eee11099900d39fd1aab28f Mon Sep 17 00:00:00 2001 From: Philippe Mouawad Date: Sun, 9 Jun 2013 13:07:32 +0000 Subject: [PATCH] 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 --- .../jdbc/AbstractJDBCTestElement.java | 41 ++++++++++++++++++- .../jdbc/JDBCTestElementBeanInfoSupport.java | 17 +++++--- .../sampler/JDBCSamplerResources.properties | 3 +- .../JDBCSamplerResources_fr.properties | 2 + xdocs/changes.xml | 1 + 5 files changed, 56 insertions(+), 8 deletions(-) diff --git a/src/protocol/jdbc/org/apache/jmeter/protocol/jdbc/AbstractJDBCTestElement.java b/src/protocol/jdbc/org/apache/jmeter/protocol/jdbc/AbstractJDBCTestElement.java index cd6b0bc9a7..6483b4dcdf 100644 --- a/src/protocol/jdbc/org/apache/jmeter/protocol/jdbc/AbstractJDBCTestElement.java +++ b/src/protocol/jdbc/org/apache/jmeter/protocol/jdbc/AbstractJDBCTestElement.java @@ -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() { diff --git a/src/protocol/jdbc/org/apache/jmeter/protocol/jdbc/JDBCTestElementBeanInfoSupport.java b/src/protocol/jdbc/org/apache/jmeter/protocol/jdbc/JDBCTestElementBeanInfoSupport.java index 1f8682efa5..243044a30b 100644 --- a/src/protocol/jdbc/org/apache/jmeter/protocol/jdbc/JDBCTestElementBeanInfoSupport.java +++ b/src/protocol/jdbc/org/apache/jmeter/protocol/jdbc/JDBCTestElementBeanInfoSupport.java @@ -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); } diff --git a/src/protocol/jdbc/org/apache/jmeter/protocol/jdbc/sampler/JDBCSamplerResources.properties b/src/protocol/jdbc/org/apache/jmeter/protocol/jdbc/sampler/JDBCSamplerResources.properties index 015621be28..631c47553b 100644 --- a/src/protocol/jdbc/org/apache/jmeter/protocol/jdbc/sampler/JDBCSamplerResources.properties +++ b/src/protocol/jdbc/org/apache/jmeter/protocol/jdbc/sampler/JDBCSamplerResources.properties @@ -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 \ No newline at end of file diff --git a/src/protocol/jdbc/org/apache/jmeter/protocol/jdbc/sampler/JDBCSamplerResources_fr.properties b/src/protocol/jdbc/org/apache/jmeter/protocol/jdbc/sampler/JDBCSamplerResources_fr.properties index c19d225b2b..4e2b8fe646 100644 --- a/src/protocol/jdbc/org/apache/jmeter/protocol/jdbc/sampler/JDBCSamplerResources_fr.properties +++ b/src/protocol/jdbc/org/apache/jmeter/protocol/jdbc/sampler/JDBCSamplerResources_fr.properties @@ -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 \ No newline at end of file diff --git a/xdocs/changes.xml b/xdocs/changes.xml index 06a99bd70f..98a7ee5ed9 100644 --- a/xdocs/changes.xml +++ b/xdocs/changes.xml @@ -174,6 +174,7 @@ Transaction Controller now sets Response Code of Generated Parent Sampler (if Ge
  • 54798 - Using subject from EML-file for SMTP Sampler
  • 54759 - SSLPeerUnverifiedException using HTTPS , property documented
  • 54896 - JUnit sampler gives only “failed to create an instance of the class” message with constructor problems
  • +
  • 55084 - Add timeout support for JDBC Request
  • Controllers