Author: pmouawad
Date: Sat May 27 15:06:20 2017
New Revision: 1796408
URL: http://svn.apache.org/viewvc?rev=1796408&view=rev
Log:
Bug 60889 - JMeter JDBC sample calls SELECT USER() when testing with MySQL JDBC
due to Connection#toString call for response headers
Bugzilla Id: 60889
Modified:
jmeter/trunk/src/protocol/jdbc/org/apache/jmeter/protocol/jdbc/config/DataSourceElement.java
jmeter/trunk/src/protocol/jdbc/org/apache/jmeter/protocol/jdbc/sampler/JDBCSampler.java
jmeter/trunk/xdocs/changes.xml
Modified:
jmeter/trunk/src/protocol/jdbc/org/apache/jmeter/protocol/jdbc/config/DataSourceElement.java
URL:
http://svn.apache.org/viewvc/jmeter/trunk/src/protocol/jdbc/org/apache/jmeter/protocol/jdbc/config/DataSourceElement.java?rev=1796408&r1=1796407&r2=1796408&view=diff
==============================================================================
---
jmeter/trunk/src/protocol/jdbc/org/apache/jmeter/protocol/jdbc/config/DataSourceElement.java
(original)
+++
jmeter/trunk/src/protocol/jdbc/org/apache/jmeter/protocol/jdbc/config/DataSourceElement.java
Sat May 27 15:06:20 2017
@@ -141,6 +141,20 @@ public class DataSourceElement extends A
return el;
}
+ /**
+ * @param poolName Pool name
+ * @return Connection information on poolName
+ */
+ public static String getConnectionInfo(String poolName) throws
SQLException{
+ Object poolObject =
+
JMeterContextService.getContext().getVariables().getObject(poolName);
+ if (poolObject instanceof DataSourceComponentImpl) {
+ DataSourceComponentImpl pool = (DataSourceComponentImpl)
poolObject;
+ return pool.getConnectionInfo();
+ } else {
+ return "Object:"+poolName+" is not of expected type
'"+DataSourceComponentImpl.class.getName()+"'";
+ }
+ }
/*
* Utility routine to get the connection from the pool.
* Purpose:
@@ -268,6 +282,27 @@ public class DataSourceElement extends A
DataSourceComponentImpl(BasicDataSource p_dsc){
sharedDSC=p_dsc;
}
+
+ /**
+ * @return String connection information
+ */
+ public String getConnectionInfo() {
+ BasicDataSource dsc;
+ boolean shared = false;
+ if (sharedDSC != null){ // i.e. shared pool
+ dsc = sharedDSC;
+ shared = true;
+ } else {
+ Map<String, BasicDataSource> poolMap = perThreadPoolMap.get();
+ dsc = poolMap.get(getDataSourceName());
+ }
+ StringBuilder builder = new StringBuilder(100);
+ builder.append("shared:").append(shared)
+ .append(", driver:").append(dsc.getDriverClassName())
+ .append(", url:").append(dsc.getUrl())
+ .append(", user:").append(dsc.getUsername());
+ return builder.toString();
+ }
/**
* @return Connection
Modified:
jmeter/trunk/src/protocol/jdbc/org/apache/jmeter/protocol/jdbc/sampler/JDBCSampler.java
URL:
http://svn.apache.org/viewvc/jmeter/trunk/src/protocol/jdbc/org/apache/jmeter/protocol/jdbc/sampler/JDBCSampler.java?rev=1796408&r1=1796407&r2=1796408&view=diff
==============================================================================
---
jmeter/trunk/src/protocol/jdbc/org/apache/jmeter/protocol/jdbc/sampler/JDBCSampler.java
(original)
+++
jmeter/trunk/src/protocol/jdbc/org/apache/jmeter/protocol/jdbc/sampler/JDBCSampler.java
Sat May 27 15:06:20 2017
@@ -80,7 +80,7 @@ public class JDBCSampler extends Abstrac
} finally {
res.connectEnd();
}
- res.setResponseHeaders(conn.toString());
+
res.setResponseHeaders(DataSourceElement.getConnectionInfo(getDataSource()));
res.setResponseData(execute(conn, res));
} catch (SQLException ex) {
final String errCode = Integer.toString(ex.getErrorCode());
Modified: jmeter/trunk/xdocs/changes.xml
URL:
http://svn.apache.org/viewvc/jmeter/trunk/xdocs/changes.xml?rev=1796408&r1=1796407&r2=1796408&view=diff
==============================================================================
--- jmeter/trunk/xdocs/changes.xml [utf-8] (original)
+++ jmeter/trunk/xdocs/changes.xml [utf-8] Sat May 27 15:06:20 2017
@@ -139,6 +139,7 @@ Summary
<h3>Other Samplers</h3>
<ul>
+ <li><bug>60889</bug>JMeter JDBC sample calls SELECT USER() when testing
with MySQL JDBC due to Connection#toString call for response headers.</li>
</ul>
<h3>Controllers</h3>