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/11/06 19:08:14 UTC
svn commit: r1406257 - in /jmeter/trunk:
src/core/org/apache/jmeter/util/JSR223TestElement.java xdocs/changes.xml
Author: pmouawad
Date: Tue Nov 6 18:08:13 2012
New Revision: 1406257
URL: http://svn.apache.org/viewvc?rev=1406257&view=rev
Log:
Bug 54106 - JSR223TestElement should check for file existence when a filename is set instead of using Text Area content
Bugzilla Id: 54106
Modified:
jmeter/trunk/src/core/org/apache/jmeter/util/JSR223TestElement.java
jmeter/trunk/xdocs/changes.xml
Modified: jmeter/trunk/src/core/org/apache/jmeter/util/JSR223TestElement.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/util/JSR223TestElement.java?rev=1406257&r1=1406256&r2=1406257&view=diff
==============================================================================
--- jmeter/trunk/src/core/org/apache/jmeter/util/JSR223TestElement.java (original)
+++ jmeter/trunk/src/core/org/apache/jmeter/util/JSR223TestElement.java Tue Nov 6 18:08:13 2012
@@ -36,6 +36,7 @@ import javax.script.ScriptException;
import org.apache.commons.collections.map.LRUMap;
import org.apache.commons.io.IOUtils;
+import org.apache.commons.lang3.StringUtils;
import org.apache.jmeter.samplers.SampleResult;
import org.apache.jmeter.samplers.Sampler;
import org.apache.jmeter.testelement.AbstractTestElement;
@@ -171,42 +172,48 @@ public abstract class JSR223TestElement
// Hack as in bsh-2.0b5.jar BshScriptEngine implements Compilable but throws new Error
boolean supportsCompilable = scriptEngine instanceof Compilable
&& !(scriptEngine.getClass().getName().equals("bsh.engine.BshScriptEngine"));
- if (scriptFile.exists()) {
- BufferedReader fileReader = null;
- try {
- if(supportsCompilable) {
- String cacheKey =
- getScriptLanguage()+"#"+
- scriptFile.getAbsolutePath()+"#"+
- scriptFile.lastModified();
- CompiledScript compiledScript =
- compiledScriptsCache.get(cacheKey);
- if(compiledScript==null) {
- synchronized (compiledScriptsCache) {
- compiledScript =
- compiledScriptsCache.get(cacheKey);
- if(compiledScript==null) {
- // TODO Charset ?
- fileReader = new BufferedReader(new FileReader(scriptFile),
- (int)scriptFile.length());
+ if (!StringUtils.isEmpty(getFilename())) {
+ if(scriptFile.exists() && scriptFile.canRead()) {
+ BufferedReader fileReader = null;
+ try {
+ if(supportsCompilable) {
+ String cacheKey =
+ getScriptLanguage()+"#"+
+ scriptFile.getAbsolutePath()+"#"+
+ scriptFile.lastModified();
+ CompiledScript compiledScript =
+ compiledScriptsCache.get(cacheKey);
+ if(compiledScript==null) {
+ synchronized (compiledScriptsCache) {
compiledScript =
- ((Compilable) scriptEngine).compile(fileReader);
- compiledScriptsCache.put(cacheKey, compiledScript);
+ compiledScriptsCache.get(cacheKey);
+ if(compiledScript==null) {
+ // TODO Charset ?
+ fileReader = new BufferedReader(new FileReader(scriptFile),
+ (int)scriptFile.length());
+ compiledScript =
+ ((Compilable) scriptEngine).compile(fileReader);
+ compiledScriptsCache.put(cacheKey, compiledScript);
+ }
}
}
+ return compiledScript.eval(bindings);
+ } else {
+ // TODO Charset ?
+ fileReader = new BufferedReader(new FileReader(scriptFile),
+ (int)scriptFile.length());
+ return scriptEngine.eval(fileReader, bindings);
}
- return compiledScript.eval(bindings);
- } else {
- // TODO Charset ?
- fileReader = new BufferedReader(new FileReader(scriptFile),
- (int)scriptFile.length());
- return scriptEngine.eval(fileReader, bindings);
+ } finally {
+ IOUtils.closeQuietly(fileReader);
}
- } finally {
- IOUtils.closeQuietly(fileReader);
+ } else {
+ throw new ScriptException("Script file '"+scriptFile.getAbsolutePath()+"' does not exist or is unreadable for element:"+getName());
}
- } else {
+ } else if(!StringUtils.isEmpty(getScript())){
return scriptEngine.eval(getScript(), bindings);
+ } else {
+ throw new ScriptException("Both script file and script text are empty for element:"+getName());
}
}
Modified: jmeter/trunk/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/jmeter/trunk/xdocs/changes.xml?rev=1406257&r1=1406256&r2=1406257&view=diff
==============================================================================
--- jmeter/trunk/xdocs/changes.xml (original)
+++ jmeter/trunk/xdocs/changes.xml Tue Nov 6 18:08:13 2012
@@ -90,6 +90,7 @@ This does not affect JMeter operation.
map which held the PreparedStatement for SQL queries. This limitation provoked a bug <bugzilla>53995</bugzilla>.
It has been removed so now size of these 2 maps is not limited anymore. This change changes behaviour as starting from this version no PreparedStatement will be closed during the test.</p>
+<p>Starting with this version JSR223 Test Elements that have an invalid filename (not existing or unreadable) will make test fail instead of making the element silently work</p>
<!-- =================== Bug fixes =================== -->
<h2>Bug fixes</h2>
@@ -146,6 +147,7 @@ and right angle bracket (>) in search
<h3>Other samplers</h3>
<ul>
<li><bugzilla>54004</bugzilla> - Webservice Sampler : Allow adding headers to request with Header Manager</li>
+<li><bugzilla>54106</bugzilla> - JSR223TestElement should check for file existence when a filename is set instead of using Text Area content </li>
</ul>
<h3>Controllers</h3>
Re: svn commit: r1406257 - in /jmeter/trunk: src/core/org/apache/jmeter/util/JSR223TestElement.java
xdocs/changes.xml
Posted by Philippe Mouawad <ph...@gmail.com>.
Fixed
On Tue, Nov 6, 2012 at 8:08 PM, Milamber <mi...@apache.org> wrote:
>
>
> Le 06/11/2012 18:08, pmouawad@apache.org a ecrit :
>
> Author: pmouawad
>> Date: Tue Nov 6 18:08:13 2012
>> New Revision: 1406257
>>
>> URL: http://svn.apache.org/viewvc?**rev=1406257&view=rev<http://svn.apache.org/viewvc?rev=1406257&view=rev>
>> Log:
>> Bug 54106 - JSR223TestElement should check for file existence when a
>> filename is set instead of using Text Area content
>> Bugzilla Id: 54106
>>
>> Modified:
>> jmeter/trunk/src/core/org/**apache/jmeter/util/**
>> JSR223TestElement.java
>> jmeter/trunk/xdocs/changes.xml
>>
>> Modified: jmeter/trunk/src/core/org/**apache/jmeter/util/**
>> JSR223TestElement.java
>> URL: http://svn.apache.org/viewvc/**jmeter/trunk/src/core/org/**
>> apache/jmeter/util/**JSR223TestElement.java?rev=**
>> 1406257&r1=1406256&r2=1406257&**view=diff<http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/util/JSR223TestElement.java?rev=1406257&r1=1406256&r2=1406257&view=diff>
>> ==============================**==============================**
>> ==================
>> --- jmeter/trunk/src/core/org/**apache/jmeter/util/**JSR223TestElement.java
>> (original)
>> +++ jmeter/trunk/src/core/org/**apache/jmeter/util/**JSR223TestElement.java
>> Tue Nov 6 18:08:13 2012
>> @@ -36,6 +36,7 @@ import javax.script.ScriptException;
>>
>> import org.apache.commons.**collections.map.LRUMap;
>> import org.apache.commons.io.IOUtils;
>> +import org.apache.commons.lang3.**StringUtils;
>> import org.apache.jmeter.samplers.**SampleResult;
>> import org.apache.jmeter.samplers.**Sampler;
>> import org.apache.jmeter.testelement.**AbstractTestElement;
>> @@ -171,42 +172,48 @@ public abstract class JSR223TestElement
>> // Hack as in bsh-2.0b5.jar BshScriptEngine implements
>> Compilable but throws new Error
>> boolean supportsCompilable = scriptEngine instanceof Compilable
>> && !(scriptEngine.getClass().**
>> getName().equals("bsh.engine.**BshScriptEngine"));
>> - if (scriptFile.exists()) {
>> - BufferedReader fileReader = null;
>> - try {
>> - if(supportsCompilable) {
>> - String cacheKey =
>> - getScriptLanguage()+"#"+
>> - scriptFile.getAbsolutePath()+"**#"+
>> - scriptFile.lastModified();
>> - CompiledScript compiledScript =
>> - compiledScriptsCache.get(**cacheKey);
>> - if(compiledScript==null) {
>> - synchronized (compiledScriptsCache) {
>> - compiledScript =
>> - compiledScriptsCache.get(**
>> cacheKey);
>> - if(compiledScript==null) {
>> - // TODO Charset ?
>> - fileReader = new BufferedReader(new
>> FileReader(scriptFile),
>> - (int)scriptFile.length());
>>
> For example:
>
>> + if (!StringUtils.isEmpty(**getFilename())) {
>>
> ^^^ ok
>
>> + if(scriptFile.exists()&& scriptFile.canRead()) {
>>
> ^^^ not ok
>
> Please, take care to formatting the code: one space between if and (
>
> http://wiki.apache.org/jmeter/**JMeterEclipse<http://wiki.apache.org/jmeter/JMeterEclipse>
>
>
>
>
> + BufferedReader fileReader = null;
>> + try {
>> + if(supportsCompilable) {
>> + String cacheKey =
>> + getScriptLanguage()+"#"+
>> + scriptFile.getAbsolutePath()+"**#"+
>> + scriptFile.lastModified();
>> + CompiledScript compiledScript =
>> + compiledScriptsCache.get(**cacheKey);
>> + if(compiledScript==null) {
>> + synchronized (compiledScriptsCache) {
>> compiledScript =
>> - ((Compilable)
>> scriptEngine).compile(**fileReader);
>> - compiledScriptsCache.put(**cacheKey,
>> compiledScript);
>> + compiledScriptsCache.get(**
>> cacheKey);
>> + if(compiledScript==null) {
>> + // TODO Charset ?
>> + fileReader = new BufferedReader(new
>> FileReader(scriptFile),
>> + (int)scriptFile.length());
>> + compiledScript =
>> + ((Compilable)
>> scriptEngine).compile(**fileReader);
>> + compiledScriptsCache.put(**cacheKey,
>> compiledScript);
>> + }
>> }
>> }
>> + return compiledScript.eval(bindings);
>> + } else {
>> + // TODO Charset ?
>> + fileReader = new BufferedReader(new
>> FileReader(scriptFile),
>> + (int)scriptFile.length());
>> + return scriptEngine.eval(fileReader, bindings);
>> }
>> - return compiledScript.eval(bindings);
>> - } else {
>> - // TODO Charset ?
>> - fileReader = new BufferedReader(new
>> FileReader(scriptFile),
>> - (int)scriptFile.length());
>> - return scriptEngine.eval(fileReader, bindings);
>> + } finally {
>> + IOUtils.closeQuietly(**fileReader);
>> }
>> - } finally {
>> - IOUtils.closeQuietly(**fileReader);
>> + } else {
>> + throw new ScriptException("Script file
>> '"+scriptFile.getAbsolutePath(**)+"' does not exist or is unreadable for
>> element:"+getName());
>> }
>> - } else {
>> + } else if(!StringUtils.isEmpty(**getScript())){
>> return scriptEngine.eval(getScript(), bindings);
>> + } else {
>> + throw new ScriptException("Both script file and script text
>> are empty for element:"+getName());
>> }
>> }
>>
>>
>> Modified: jmeter/trunk/xdocs/changes.xml
>> URL: http://svn.apache.org/viewvc/**jmeter/trunk/xdocs/changes.**
>> xml?rev=1406257&r1=1406256&r2=**1406257&view=diff<http://svn.apache.org/viewvc/jmeter/trunk/xdocs/changes.xml?rev=1406257&r1=1406256&r2=1406257&view=diff>
>> ==============================**==============================**
>> ==================
>> --- jmeter/trunk/xdocs/changes.xml (original)
>> +++ jmeter/trunk/xdocs/changes.xml Tue Nov 6 18:08:13 2012
>> @@ -90,6 +90,7 @@ This does not affect JMeter operation.
>> map which held the PreparedStatement for SQL queries. This limitation
>> provoked a bug<bugzilla>53995</bugzilla>.
>> It has been removed so now size of these 2 maps is not limited anymore.
>> This change changes behaviour as starting from this version no
>> PreparedStatement will be closed during the test.</p>
>>
>> +<p>Starting with this version JSR223 Test Elements that have an invalid
>> filename (not existing or unreadable) will make test fail instead of making
>> the element silently work</p>
>> <!-- =================== Bug fixes =================== -->
>>
>> <h2>Bug fixes</h2>
>> @@ -146,6 +147,7 @@ and right angle bracket (>) in search
>> <h3>Other samplers</h3>
>> <ul>
>> <li><bugzilla>54004</bugzilla> - Webservice Sampler : Allow adding
>> headers to request with Header Manager</li>
>> +<li><bugzilla>54106</**bugzilla> - JSR223TestElement should check for
>> file existence when a filename is set instead of using Text Area
>> content</li>
>> </ul>
>>
>> <h3>Controllers</h3>
>>
>>
>>
>>
>
--
Cordialement.
Philippe Mouawad.
Re: svn commit: r1406257 - in /jmeter/trunk: src/core/org/apache/jmeter/util/JSR223TestElement.java
xdocs/changes.xml
Posted by Milamber <mi...@apache.org>.
Le 06/11/2012 18:08, pmouawad@apache.org a ecrit :
> Author: pmouawad
> Date: Tue Nov 6 18:08:13 2012
> New Revision: 1406257
>
> URL: http://svn.apache.org/viewvc?rev=1406257&view=rev
> Log:
> Bug 54106 - JSR223TestElement should check for file existence when a filename is set instead of using Text Area content
> Bugzilla Id: 54106
>
> Modified:
> jmeter/trunk/src/core/org/apache/jmeter/util/JSR223TestElement.java
> jmeter/trunk/xdocs/changes.xml
>
> Modified: jmeter/trunk/src/core/org/apache/jmeter/util/JSR223TestElement.java
> URL: http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/util/JSR223TestElement.java?rev=1406257&r1=1406256&r2=1406257&view=diff
> ==============================================================================
> --- jmeter/trunk/src/core/org/apache/jmeter/util/JSR223TestElement.java (original)
> +++ jmeter/trunk/src/core/org/apache/jmeter/util/JSR223TestElement.java Tue Nov 6 18:08:13 2012
> @@ -36,6 +36,7 @@ import javax.script.ScriptException;
>
> import org.apache.commons.collections.map.LRUMap;
> import org.apache.commons.io.IOUtils;
> +import org.apache.commons.lang3.StringUtils;
> import org.apache.jmeter.samplers.SampleResult;
> import org.apache.jmeter.samplers.Sampler;
> import org.apache.jmeter.testelement.AbstractTestElement;
> @@ -171,42 +172,48 @@ public abstract class JSR223TestElement
> // Hack as in bsh-2.0b5.jar BshScriptEngine implements Compilable but throws new Error
> boolean supportsCompilable = scriptEngine instanceof Compilable
> && !(scriptEngine.getClass().getName().equals("bsh.engine.BshScriptEngine"));
> - if (scriptFile.exists()) {
> - BufferedReader fileReader = null;
> - try {
> - if(supportsCompilable) {
> - String cacheKey =
> - getScriptLanguage()+"#"+
> - scriptFile.getAbsolutePath()+"#"+
> - scriptFile.lastModified();
> - CompiledScript compiledScript =
> - compiledScriptsCache.get(cacheKey);
> - if(compiledScript==null) {
> - synchronized (compiledScriptsCache) {
> - compiledScript =
> - compiledScriptsCache.get(cacheKey);
> - if(compiledScript==null) {
> - // TODO Charset ?
> - fileReader = new BufferedReader(new FileReader(scriptFile),
> - (int)scriptFile.length());
For example:
> + if (!StringUtils.isEmpty(getFilename())) {
^^^ ok
> + if(scriptFile.exists()&& scriptFile.canRead()) {
^^^ not ok
Please, take care to formatting the code: one space between if and (
http://wiki.apache.org/jmeter/JMeterEclipse
> + BufferedReader fileReader = null;
> + try {
> + if(supportsCompilable) {
> + String cacheKey =
> + getScriptLanguage()+"#"+
> + scriptFile.getAbsolutePath()+"#"+
> + scriptFile.lastModified();
> + CompiledScript compiledScript =
> + compiledScriptsCache.get(cacheKey);
> + if(compiledScript==null) {
> + synchronized (compiledScriptsCache) {
> compiledScript =
> - ((Compilable) scriptEngine).compile(fileReader);
> - compiledScriptsCache.put(cacheKey, compiledScript);
> + compiledScriptsCache.get(cacheKey);
> + if(compiledScript==null) {
> + // TODO Charset ?
> + fileReader = new BufferedReader(new FileReader(scriptFile),
> + (int)scriptFile.length());
> + compiledScript =
> + ((Compilable) scriptEngine).compile(fileReader);
> + compiledScriptsCache.put(cacheKey, compiledScript);
> + }
> }
> }
> + return compiledScript.eval(bindings);
> + } else {
> + // TODO Charset ?
> + fileReader = new BufferedReader(new FileReader(scriptFile),
> + (int)scriptFile.length());
> + return scriptEngine.eval(fileReader, bindings);
> }
> - return compiledScript.eval(bindings);
> - } else {
> - // TODO Charset ?
> - fileReader = new BufferedReader(new FileReader(scriptFile),
> - (int)scriptFile.length());
> - return scriptEngine.eval(fileReader, bindings);
> + } finally {
> + IOUtils.closeQuietly(fileReader);
> }
> - } finally {
> - IOUtils.closeQuietly(fileReader);
> + } else {
> + throw new ScriptException("Script file '"+scriptFile.getAbsolutePath()+"' does not exist or is unreadable for element:"+getName());
> }
> - } else {
> + } else if(!StringUtils.isEmpty(getScript())){
> return scriptEngine.eval(getScript(), bindings);
> + } else {
> + throw new ScriptException("Both script file and script text are empty for element:"+getName());
> }
> }
>
>
> Modified: jmeter/trunk/xdocs/changes.xml
> URL: http://svn.apache.org/viewvc/jmeter/trunk/xdocs/changes.xml?rev=1406257&r1=1406256&r2=1406257&view=diff
> ==============================================================================
> --- jmeter/trunk/xdocs/changes.xml (original)
> +++ jmeter/trunk/xdocs/changes.xml Tue Nov 6 18:08:13 2012
> @@ -90,6 +90,7 @@ This does not affect JMeter operation.
> map which held the PreparedStatement for SQL queries. This limitation provoked a bug<bugzilla>53995</bugzilla>.
> It has been removed so now size of these 2 maps is not limited anymore. This change changes behaviour as starting from this version no PreparedStatement will be closed during the test.</p>
>
> +<p>Starting with this version JSR223 Test Elements that have an invalid filename (not existing or unreadable) will make test fail instead of making the element silently work</p>
> <!-- =================== Bug fixes =================== -->
>
> <h2>Bug fixes</h2>
> @@ -146,6 +147,7 @@ and right angle bracket (>) in search
> <h3>Other samplers</h3>
> <ul>
> <li><bugzilla>54004</bugzilla> - Webservice Sampler : Allow adding headers to request with Header Manager</li>
> +<li><bugzilla>54106</bugzilla> - JSR223TestElement should check for file existence when a filename is set instead of using Text Area content</li>
> </ul>
>
> <h3>Controllers</h3>
>
>
>