You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jmeter.apache.org by pm...@apache.org on 2018/11/21 12:37:01 UTC

svn commit: r1847095 - in /jmeter/trunk: src/protocol/jdbc/org/apache/jmeter/protocol/jdbc/AbstractJDBCTestElement.java xdocs/changes.xml xdocs/usermanual/component_reference.xml

Author: pmouawad
Date: Wed Nov 21 12:37:01 2018
New Revision: 1847095

URL: http://svn.apache.org/viewvc?rev=1847095&view=rev
Log:
Bug 62934 Add compatibility for JDBC drivers that do not support QueryTimeout 
Bugzilla Id: 62934

Modified:
    jmeter/trunk/src/protocol/jdbc/org/apache/jmeter/protocol/jdbc/AbstractJDBCTestElement.java
    jmeter/trunk/xdocs/changes.xml
    jmeter/trunk/xdocs/usermanual/component_reference.xml

Modified: jmeter/trunk/src/protocol/jdbc/org/apache/jmeter/protocol/jdbc/AbstractJDBCTestElement.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/protocol/jdbc/org/apache/jmeter/protocol/jdbc/AbstractJDBCTestElement.java?rev=1847095&r1=1847094&r2=1847095&view=diff
==============================================================================
--- jmeter/trunk/src/protocol/jdbc/org/apache/jmeter/protocol/jdbc/AbstractJDBCTestElement.java (original)
+++ jmeter/trunk/src/protocol/jdbc/org/apache/jmeter/protocol/jdbc/AbstractJDBCTestElement.java Wed Nov 21 12:37:01 2018
@@ -44,6 +44,7 @@ import java.util.List;
 import java.util.Map;
 
 import org.apache.commons.io.IOUtils;
+import org.apache.commons.lang3.StringUtils;
 import org.apache.jmeter.samplers.SampleResult;
 import org.apache.jmeter.save.CSVSaveService;
 import org.apache.jmeter.testelement.AbstractTestElement;
@@ -166,7 +167,7 @@ public abstract class AbstractJDBCTestEl
         String currentQueryType = getQueryType();
         if (SELECT.equals(currentQueryType)) {
             try (Statement stmt = conn.createStatement()) {
-                stmt.setQueryTimeout(getIntegerQueryTimeout());
+                setQueryTimeout(stmt, getIntegerQueryTimeout());
                 ResultSet rs = null;
                 try {
                     rs = stmt.executeQuery(getQuery());
@@ -188,7 +189,7 @@ public abstract class AbstractJDBCTestEl
             }
         } else if (UPDATE.equals(currentQueryType)) {
             try (Statement stmt = conn.createStatement()) {
-                stmt.setQueryTimeout(getIntegerQueryTimeout());
+                setQueryTimeout(stmt, getIntegerQueryTimeout());
                 stmt.executeUpdate(getQuery());
                 sample.latencyEnd();
                 int updateCount = stmt.getUpdateCount();
@@ -495,9 +496,20 @@ public abstract class AbstractJDBCTestEl
         } else {
             pstmt = conn.prepareStatement(getQuery()); // NOSONAR closed by caller
         }
-        pstmt.setQueryTimeout(getIntegerQueryTimeout());
+        setQueryTimeout(pstmt, getIntegerQueryTimeout());
         return pstmt;
     }
+    
+    /**
+     * @param stmt {@link Statement} Statement for which we want to set timeout
+     * @param timeout int timeout value in seconds, if < 0 setQueryTimeout will not be called
+     * @throws SQLException
+     */
+    private static void setQueryTimeout(Statement stmt, int timeout) throws SQLException {
+        if(timeout >= 0) {
+            stmt.setQueryTimeout(timeout);
+        }
+    }
 
     /**
      * Gets a Data object from a ResultSet.
@@ -617,10 +629,14 @@ public abstract class AbstractJDBCTestEl
      */
     public int getIntegerQueryTimeout() {
         int timeout = 0;
-        try {
-            timeout = Integer.parseInt(queryTimeout);
-        } catch (NumberFormatException nfe) {
-            timeout = 0;
+        if(StringUtils.isEmpty(queryTimeout)) {
+            return 0;
+        } else {
+            try {
+                timeout = Integer.parseInt(queryTimeout);
+            } catch (NumberFormatException nfe) {
+                timeout = 0;
+            }
         }
         return timeout;
     }

Modified: jmeter/trunk/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/jmeter/trunk/xdocs/changes.xml?rev=1847095&r1=1847094&r2=1847095&view=diff
==============================================================================
--- jmeter/trunk/xdocs/changes.xml [utf-8] (original)
+++ jmeter/trunk/xdocs/changes.xml [utf-8] Wed Nov 21 12:37:01 2018
@@ -83,6 +83,7 @@ of previous time slot as a base. Startin
 
 <h3>Other samplers</h3>
 <ul>
+    <li><bug>62934</bug>Add compatibility for JDBC drivers that do not support QueryTimeout </li>
 </ul>
 
 <h3>Controllers</h3>

Modified: jmeter/trunk/xdocs/usermanual/component_reference.xml
URL: http://svn.apache.org/viewvc/jmeter/trunk/xdocs/usermanual/component_reference.xml?rev=1847095&r1=1847094&r2=1847095&view=diff
==============================================================================
--- jmeter/trunk/xdocs/usermanual/component_reference.xml (original)
+++ jmeter/trunk/xdocs/usermanual/component_reference.xml Wed Nov 21 12:37:01 2018
@@ -595,6 +595,8 @@ the additional variables for rows four,
         Each map contains the column name as the key and the column data as the value. Usage:<br></br>
         <source>columnValue = vars.getObject("resultObject").get(0).get("Column Name");</source>
         </property>
+        <property name="Query timeout(s)" required="No">Set a timeout in seconds for query, empty value means 0 which is infinite. <code>-1</code> means don't set any query timeout
+which might be needed for use case or when certain drivers don't support timeout. Defaults to 0.</property>
         <property name="Handle ResultSet" required="No">Defines how ResultSet returned from callable statements be handled:
             <ul>
                 <li><code>Store As String</code> (default) - All variables on Variable Names list are stored as strings, will not iterate through a <code>ResultSet</code> when present on the list. <code>CLOB</code>s will be converted to Strings. <code>BLOB</code>s will be converted to Strings as if they were an UTF-8 encoded byte-array. Both <code>CLOB</code>s and <code>BLOB</code>s will be cut off after <code>jdbcsampler.max_retain_result_size</code> bytes.</li>