Skip to content

Commit

Permalink
Bug 62934 Add compatibility for JDBC drivers that do not support Quer…
Browse files Browse the repository at this point in the history
…yTimeout

Bugzilla Id: 62934

git-svn-id: https://svn.apache.org/repos/asf/jmeter/trunk@1847095 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
pmouawad committed Nov 21, 2018
1 parent cc55d68 commit c9defe6
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 7 deletions.
Expand Up @@ -44,6 +44,7 @@
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;
Expand Down Expand Up @@ -166,7 +167,7 @@ protected byte[] execute(Connection conn, SampleResult sample) throws SQLExcepti
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());
Expand All @@ -188,7 +189,7 @@ protected byte[] execute(Connection conn, SampleResult sample) throws SQLExcepti
}
} 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();
Expand Down Expand Up @@ -495,9 +496,20 @@ private PreparedStatement getPreparedStatement(Connection conn, boolean callable
} 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.
Expand Down Expand Up @@ -617,10 +629,14 @@ public static void close(ResultSet rs) {
*/
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;
}
Expand Down
1 change: 1 addition & 0 deletions xdocs/changes.xml
Expand Up @@ -83,6 +83,7 @@ of previous time slot as a base. Starting with this version, each time slot is i

<h3>Other samplers</h3>
<ul>
<li><bug>62934</bug>Add compatibility for JDBC drivers that do not support QueryTimeout </li>
</ul>

<h3>Controllers</h3>
Expand Down
2 changes: 2 additions & 0 deletions xdocs/usermanual/component_reference.xml
Expand Up @@ -595,6 +595,8 @@ the additional variables for rows four, five and six will be removed.
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>
Expand Down

0 comments on commit c9defe6

Please sign in to comment.