mirror of https://github.com/apache/jmeter.git
				
				
				
			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:
		
							parent
							
								
									c1c64f6324
								
							
						
					
					
						commit
						a26ea01b0d
					
				|  | @ -35,6 +35,7 @@ import java.util.List; | ||||||
| import java.util.Map; | import java.util.Map; | ||||||
| import java.util.concurrent.ConcurrentHashMap; | import java.util.concurrent.ConcurrentHashMap; | ||||||
| 
 | 
 | ||||||
|  | import org.apache.commons.lang3.StringUtils; | ||||||
| import org.apache.jmeter.samplers.SampleResult; | import org.apache.jmeter.samplers.SampleResult; | ||||||
| import org.apache.jmeter.save.CSVSaveService; | import org.apache.jmeter.save.CSVSaveService; | ||||||
| import org.apache.jmeter.testelement.AbstractTestElement; | 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 queryArguments = ""; // $NON-NLS-1$ | ||||||
|     private String queryArgumentsTypes = ""; // $NON-NLS-1$ |     private String queryArgumentsTypes = ""; // $NON-NLS-1$ | ||||||
|     private String variableNames = ""; // $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 |      *  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(); |             String _queryType = getQueryType(); | ||||||
|             if (SELECT.equals(_queryType)) { |             if (SELECT.equals(_queryType)) { | ||||||
|                 stmt = conn.createStatement(); |                 stmt = conn.createStatement(); | ||||||
|  |                 stmt.setQueryTimeout(getIntegerQueryTimeout()); | ||||||
|                 ResultSet rs = null; |                 ResultSet rs = null; | ||||||
|                 try { |                 try { | ||||||
|                     rs = stmt.executeQuery(getQuery()); |                     rs = stmt.executeQuery(getQuery()); | ||||||
|  | @ -159,6 +162,7 @@ public abstract class AbstractJDBCTestElement extends AbstractTestElement implem | ||||||
|                 return sb.getBytes(ENCODING); |                 return sb.getBytes(ENCODING); | ||||||
|             } else if (UPDATE.equals(_queryType)) { |             } else if (UPDATE.equals(_queryType)) { | ||||||
|                 stmt = conn.createStatement(); |                 stmt = conn.createStatement(); | ||||||
|  |                 stmt.setQueryTimeout(getIntegerQueryTimeout()); | ||||||
|                 stmt.executeUpdate(getQuery()); |                 stmt.executeUpdate(getQuery()); | ||||||
|                 int updateCount = stmt.getUpdateCount(); |                 int updateCount = stmt.getUpdateCount(); | ||||||
|                 String results = updateCount + " updates"; |                 String results = updateCount + " updates"; | ||||||
|  | @ -332,9 +336,15 @@ public abstract class AbstractJDBCTestElement extends AbstractTestElement implem | ||||||
|             } else { |             } else { | ||||||
|                 pstmt = conn.prepareStatement(getQuery()); |                 pstmt = conn.prepareStatement(getQuery()); | ||||||
|             } |             } | ||||||
|  |             pstmt.setQueryTimeout(getIntegerQueryTimeout()); | ||||||
|             // PreparedStatementMap is associated to one connection so  |             // PreparedStatementMap is associated to one connection so  | ||||||
|             //  2 threads cannot use the same PreparedStatement map at the same time |             //  2 threads cannot use the same PreparedStatement map at the same time | ||||||
|             preparedStatementMap.put(getQuery(), pstmt); |             preparedStatementMap.put(getQuery(), pstmt); | ||||||
|  |         } else { | ||||||
|  |             int timeoutInS = getIntegerQueryTimeout(); | ||||||
|  |             if(pstmt.getQueryTimeout() != timeoutInS) { | ||||||
|  |                 pstmt.setQueryTimeout(getIntegerQueryTimeout()); | ||||||
|  |             } | ||||||
|         } |         } | ||||||
|         pstmt.clearParameters(); |         pstmt.clearParameters(); | ||||||
|         return pstmt; |         return pstmt; | ||||||
|  | @ -459,6 +469,35 @@ public abstract class AbstractJDBCTestElement extends AbstractTestElement implem | ||||||
|         } |         } | ||||||
|     }     |     }     | ||||||
|      |      | ||||||
|  |     /** | ||||||
|  |      * @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() { |     public String getQuery() { | ||||||
|         return query; |         return query; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  | @ -42,26 +42,31 @@ public abstract class JDBCTestElementBeanInfoSupport extends BeanInfoSupport { | ||||||
|                 "queryArgumentsTypes", // $NON-NLS-1$ |                 "queryArgumentsTypes", // $NON-NLS-1$ | ||||||
|                 "variableNames", // $NON-NLS-1$ |                 "variableNames", // $NON-NLS-1$ | ||||||
|                 "resultVariable", // $NON-NLS-1$ |                 "resultVariable", // $NON-NLS-1$ | ||||||
|  |                 "queryTimeout" // $NON-NLS-1$ | ||||||
|                 }); |                 }); | ||||||
| 
 | 
 | ||||||
|         PropertyDescriptor p = property("dataSource"); // $NON-NLS-1$ |         PropertyDescriptor p = property("dataSource"); // $NON-NLS-1$ | ||||||
|         p.setValue(NOT_UNDEFINED, Boolean.TRUE); |         p.setValue(NOT_UNDEFINED, Boolean.TRUE); | ||||||
|         p.setValue(DEFAULT, ""); |         p.setValue(DEFAULT, ""); // $NON-NLS-1$ | ||||||
| 
 | 
 | ||||||
|         p = property("queryArguments"); // $NON-NLS-1$ |         p = property("queryArguments"); // $NON-NLS-1$ | ||||||
|         p.setValue(NOT_UNDEFINED, Boolean.TRUE); |         p.setValue(NOT_UNDEFINED, Boolean.TRUE); | ||||||
|         p.setValue(DEFAULT, ""); |         p.setValue(DEFAULT, ""); // $NON-NLS-1$ | ||||||
| 
 | 
 | ||||||
|         p = property("queryArgumentsTypes"); // $NON-NLS-1$ |         p = property("queryArgumentsTypes"); // $NON-NLS-1$ | ||||||
|         p.setValue(NOT_UNDEFINED, Boolean.TRUE); |         p.setValue(NOT_UNDEFINED, Boolean.TRUE); | ||||||
|         p.setValue(DEFAULT, ""); |         p.setValue(DEFAULT, ""); // $NON-NLS-1$ | ||||||
| 
 | 
 | ||||||
|         p = property("variableNames"); // $NON-NLS-1$ |         p = property("variableNames"); // $NON-NLS-1$ | ||||||
|         p.setValue(NOT_UNDEFINED, Boolean.TRUE); |         p.setValue(NOT_UNDEFINED, Boolean.TRUE); | ||||||
|         p.setValue(DEFAULT, ""); |         p.setValue(DEFAULT, ""); // $NON-NLS-1$ | ||||||
| 
 | 
 | ||||||
|         p = property("resultVariable"); // $NON-NLS-1$ |         p = property("resultVariable"); // $NON-NLS-1$ | ||||||
|         p.setValue(NOT_UNDEFINED, Boolean.TRUE); |         p.setValue(NOT_UNDEFINED, Boolean.TRUE); | ||||||
|  |         p.setValue(DEFAULT, ""); // $NON-NLS-1$ | ||||||
|  | 
 | ||||||
|  |         p = property("queryTimeout"); // $NON-NLS-1$ | ||||||
|  |         p.setValue(NOT_UNDEFINED, Boolean.TRUE); | ||||||
|         p.setValue(DEFAULT, ""); |         p.setValue(DEFAULT, ""); | ||||||
|          |          | ||||||
|         p = property("queryType"); // $NON-NLS-1$ |         p = property("queryType"); // $NON-NLS-1$ | ||||||
|  | @ -82,7 +87,7 @@ public abstract class JDBCTestElementBeanInfoSupport extends BeanInfoSupport { | ||||||
| 
 | 
 | ||||||
|         p = property("query"); // $NON-NLS-1$ |         p = property("query"); // $NON-NLS-1$ | ||||||
|         p.setValue(NOT_UNDEFINED, Boolean.TRUE); |         p.setValue(NOT_UNDEFINED, Boolean.TRUE); | ||||||
|         p.setValue(DEFAULT, ""); |         p.setValue(DEFAULT, ""); // $NON-NLS-1$ | ||||||
|         p.setPropertyEditorClass(TextAreaEditor.class); |         p.setPropertyEditorClass(TextAreaEditor.class); | ||||||
| 
 | 
 | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  | @ -30,4 +30,5 @@ variableNames.displayName=Variable names | ||||||
| variableNames.shortDescription=Output variable names for each column  (comma separated) | variableNames.shortDescription=Output variable names for each column  (comma separated) | ||||||
| resultVariable.displayName=Result variable name | 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. | 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 | ||||||
|  | @ -31,3 +31,5 @@ sql.displayName=Requ\u00EAte SQL | ||||||
| varName.displayName=Nom de liaison avec le pool | varName.displayName=Nom de liaison avec le pool | ||||||
| variableNames.displayName=Noms des variables  | variableNames.displayName=Noms des variables  | ||||||
| variableNames.shortDescription=Noms des variables en sortie pour chaque colonne (s\u00E9par\u00E9s par des virgules) | 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 | ||||||
|  | @ -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>54798</bugzilla> - Using subject from EML-file for SMTP Sampler</li> | ||||||
| <li><bugzilla>54759</bugzilla> - SSLPeerUnverifiedException using HTTPS , property documented</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>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> | </ul> | ||||||
| 
 | 
 | ||||||
| <h3>Controllers</h3> | <h3>Controllers</h3> | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue