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 2012/09/08 15:40:48 UTC

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

Author: pmouawad
Date: Sat Sep  8 13:40:48 2012
New Revision: 1382301

URL: http://svn.apache.org/viewvc?rev=1382301&view=rev
Log:
Bug 53844 - JDBC related elements should check class of Variable Name supposed to contain JDBC Connection Configuration to avoid ClassCastException 
Bugzilla Id: 53844

Modified:
    jmeter/trunk/src/protocol/jdbc/org/apache/jmeter/protocol/jdbc/config/DataSourceElement.java
    jmeter/trunk/xdocs/changes.xml
    jmeter/trunk/xdocs/usermanual/component_reference.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=1382301&r1=1382300&r2=1382301&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 Sep  8 13:40:48 2012
@@ -38,6 +38,7 @@ import org.apache.jmeter.testelement.Tes
 import org.apache.jmeter.threads.JMeterContextService;
 import org.apache.jmeter.threads.JMeterVariables;
 import org.apache.jorphan.logging.LoggingManager;
+import org.apache.jorphan.util.JOrphanUtils;
 import org.apache.log.Logger;
 
 public class DataSourceElement extends AbstractTestElement
@@ -91,7 +92,9 @@ public class DataSourceElement extends A
         TestBeanHelper.prepare(this);
         JMeterVariables variables = getThreadContext().getVariables();
         String poolName = getDataSource();
-        if (variables.getObject(poolName) != null) {
+        if(JOrphanUtils.isBlank(poolName)) {
+            throw new IllegalArgumentException("Variable Name must not be empty for element:"+getName());
+        } else if (variables.getObject(poolName) != null) {
             log.error("JDBC data source already defined for: "+poolName);
         } else {
             String maxPool = getPoolMax();
@@ -129,12 +132,21 @@ public class DataSourceElement extends A
      * - allows the pool storage mechanism to be changed if necessary
      */
     public static Connection getConnection(String poolName) throws SQLException{
-        DataSourceComponent pool = (DataSourceComponent)
-            JMeterContextService.getContext().getVariables().getObject(poolName);
-        if (pool == null) {
-            throw new SQLException("No pool found named: '" + poolName + "'");
+        Object poolObject = 
+                JMeterContextService.getContext().getVariables().getObject(poolName);
+        if (poolObject == null) {
+            throw new SQLException("No pool found named: '" + poolName + "', ensure Variable Name matches Variable Name of JDBC Connection Configuration");
+        } else {
+            if(poolObject instanceof DataSourceComponent) {
+                DataSourceComponent pool = (DataSourceComponent) poolObject;
+                return pool.getConnection();    
+            } else {
+                String errorMsg = "Found object stored under variable:'"+poolName
+                        +"' with class:"+poolObject.getClass().getName()+" and value: '"+poolObject+" but it's not a DataSourceComponent, check you're not already using this name as another variable";
+                log.error(errorMsg);
+                throw new SQLException(errorMsg); 
+            }
         }
-        return pool.getConnection();
     }
 
     /*

Modified: jmeter/trunk/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/jmeter/trunk/xdocs/changes.xml?rev=1382301&r1=1382300&r2=1382301&view=diff
==============================================================================
--- jmeter/trunk/xdocs/changes.xml (original)
+++ jmeter/trunk/xdocs/changes.xml Sat Sep  8 13:40:48 2012
@@ -149,6 +149,7 @@ The original behaviour can be restored b
 <li><bugzilla>53318</bugzilla> - Add Embedded URL Filter to HTTP Request Defaults Control </li>
 <li><bugzilla>53782</bugzilla> - Enhance JavaSampler handling of JavaSamplerClient cleanup to use less memory</li>
 <li><bugzilla>53168</bugzilla> - OS Process - allow specification of stdout/stderr/stdin</li>
+<li><bugzilla>53844</bugzilla> - JDBC related elements should check class of Variable Name supposed to contain JDBC Connection Configuration to avoid ClassCastException </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=1382301&r1=1382300&r2=1382301&view=diff
==============================================================================
--- jmeter/trunk/xdocs/usermanual/component_reference.xml (original)
+++ jmeter/trunk/xdocs/usermanual/component_reference.xml Sat Sep  8 13:40:48 2012
@@ -546,6 +546,7 @@ the additional variables for rows 4, 5 a
         <complink name="JDBC Connection Configuration"/>
 </links>
 <note>Versions of JMeter after 2.3.2 use UTF-8 as the character encoding. Previously the platform default was used.</note>
+<note>Ensure Variable Name is unique accross Test Plan.</note>
 </component>
 
 <component name="Java Request" index="&sect-num;.1.4"  width="563" height="347" screenshot="java_request.png">
@@ -4704,6 +4705,7 @@ For details, see <complink name="BSF Pre
 <p>
 The JDBC PreProcessor enables you to run some SQL statement just before a sample runs.
 This can be useful if your JDBC Sample requires some data to be in DataBase and you cannot compute this in a setup Thread group.
+For details, see <complink name="JDBC Request"/>.
 </p>
 <p>
 See the following Test plan: