jmeter-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pmoua...@apache.org
Subject svn commit: r1358733 - in /jmeter/trunk: src/components/org/apache/jmeter/assertions/ src/components/org/apache/jmeter/extractor/ src/components/org/apache/jmeter/modifiers/ src/components/org/apache/jmeter/timers/ src/components/org/apache/jmeter/visu...
Date Sun, 08 Jul 2012 13:05:15 GMT
Author: pmouawad
Date: Sun Jul  8 13:05:15 2012
New Revision: 1358733

URL: http://svn.apache.org/viewvc?rev=1358733&view=rev
Log:
Bug 53365 - JSR223TestElement should cache ScriptEngineManager
Bugzilla Id: 53365

Modified:
    jmeter/trunk/src/components/org/apache/jmeter/assertions/JSR223Assertion.java
    jmeter/trunk/src/components/org/apache/jmeter/extractor/JSR223PostProcessor.java
    jmeter/trunk/src/components/org/apache/jmeter/modifiers/JSR223PreProcessor.java
    jmeter/trunk/src/components/org/apache/jmeter/timers/JSR223Timer.java
    jmeter/trunk/src/components/org/apache/jmeter/visualizers/JSR223Listener.java
    jmeter/trunk/src/core/org/apache/jmeter/util/JSR223TestElement.java
    jmeter/trunk/src/protocol/java/org/apache/jmeter/protocol/java/sampler/JSR223Sampler.java
    jmeter/trunk/xdocs/changes.xml

Modified: jmeter/trunk/src/components/org/apache/jmeter/assertions/JSR223Assertion.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/components/org/apache/jmeter/assertions/JSR223Assertion.java?rev=1358733&r1=1358732&r2=1358733&view=diff
==============================================================================
--- jmeter/trunk/src/components/org/apache/jmeter/assertions/JSR223Assertion.java (original)
+++ jmeter/trunk/src/components/org/apache/jmeter/assertions/JSR223Assertion.java Sun Jul
 8 13:05:15 2012
@@ -20,7 +20,7 @@ package org.apache.jmeter.assertions;
 
 import java.io.IOException;
 
-import javax.script.ScriptEngineManager;
+import javax.script.ScriptEngine;
 import javax.script.ScriptException;
 
 import org.apache.jmeter.samplers.SampleResult;
@@ -38,23 +38,17 @@ public class JSR223Assertion extends JSR
     public AssertionResult getResult(SampleResult response) {
         AssertionResult result = new AssertionResult(getName());
         try {
-            ScriptEngineManager mgr = getManager();
-            if (mgr == null) {
-                result.setFailure(true);
-                result.setError(true);
-                result.setFailureMessage("JSR223 Manager not found");
-                return result;
-            }
-            mgr.put("SampleResult", response);
-            mgr.put("AssertionResult", result);
-            processFileOrScript(mgr);
+            ScriptEngine scriptEngine = getScriptEngine();
+            scriptEngine.put("SampleResult", response);
+            scriptEngine.put("AssertionResult", result);
+            processFileOrScript(scriptEngine);
             result.setError(false);
         } catch (IOException e) {
-            log.warn("Problem in JSR223 script "+e);
+            log.warn("Problem in JSR223 script ", e);
             result.setError(true);
             result.setFailureMessage(e.toString());
         } catch (ScriptException e) {
-            log.warn("Problem in JSR223 script "+e);
+            log.warn("Problem in JSR223 script ", e);
             result.setError(true);
             result.setFailureMessage(e.toString());
         }

Modified: jmeter/trunk/src/components/org/apache/jmeter/extractor/JSR223PostProcessor.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/components/org/apache/jmeter/extractor/JSR223PostProcessor.java?rev=1358733&r1=1358732&r2=1358733&view=diff
==============================================================================
--- jmeter/trunk/src/components/org/apache/jmeter/extractor/JSR223PostProcessor.java (original)
+++ jmeter/trunk/src/components/org/apache/jmeter/extractor/JSR223PostProcessor.java Sun Jul
 8 13:05:15 2012
@@ -20,7 +20,7 @@ package org.apache.jmeter.extractor;
 
 import java.io.IOException;
 
-import javax.script.ScriptEngineManager;
+import javax.script.ScriptEngine;
 import javax.script.ScriptException;
 
 import org.apache.jmeter.processor.PostProcessor;
@@ -36,15 +36,13 @@ public class JSR223PostProcessor extends
     private static final long serialVersionUID = 232L;
 
     public void process() {
-
         try {
-            ScriptEngineManager sem = getManager();
-            if(sem == null) { return; }
-            processFileOrScript(sem);
+            ScriptEngine scriptEngine = getScriptEngine();
+            processFileOrScript(scriptEngine);
         } catch (ScriptException e) {
-            log.warn("Problem in JSR223 script "+e);
+            log.warn("Problem in JSR223 script ", e);
         } catch (IOException e) {
-            log.warn("Problem in JSR223 script "+e);
+            log.warn("Problem in JSR223 script ", e);
         }
     }
 }

Modified: jmeter/trunk/src/components/org/apache/jmeter/modifiers/JSR223PreProcessor.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/components/org/apache/jmeter/modifiers/JSR223PreProcessor.java?rev=1358733&r1=1358732&r2=1358733&view=diff
==============================================================================
--- jmeter/trunk/src/components/org/apache/jmeter/modifiers/JSR223PreProcessor.java (original)
+++ jmeter/trunk/src/components/org/apache/jmeter/modifiers/JSR223PreProcessor.java Sun Jul
 8 13:05:15 2012
@@ -20,7 +20,7 @@ package org.apache.jmeter.modifiers;
 
 import java.io.IOException;
 
-import javax.script.ScriptEngineManager;
+import javax.script.ScriptEngine;
 import javax.script.ScriptException;
 
 import org.apache.jmeter.processor.PreProcessor;
@@ -36,15 +36,13 @@ public class JSR223PreProcessor extends 
     private static final long serialVersionUID = 232L;
 
     public void process() {
-
         try {
-            ScriptEngineManager sem = getManager();
-            if(sem == null) { return; }
-            processFileOrScript(sem);
+            ScriptEngine scriptEngine = getScriptEngine();
+            processFileOrScript(scriptEngine);
         } catch (ScriptException e) {
-            log.warn("Problem in JSR223 script "+e);
+            log.warn("Problem in JSR223 script ", e);
         } catch (IOException e) {
-            log.warn("Problem in JSR223 script "+e);
+            log.warn("Problem in JSR223 script ", e);
         }
     }
 }

Modified: jmeter/trunk/src/components/org/apache/jmeter/timers/JSR223Timer.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/components/org/apache/jmeter/timers/JSR223Timer.java?rev=1358733&r1=1358732&r2=1358733&view=diff
==============================================================================
--- jmeter/trunk/src/components/org/apache/jmeter/timers/JSR223Timer.java (original)
+++ jmeter/trunk/src/components/org/apache/jmeter/timers/JSR223Timer.java Sun Jul  8 13:05:15
2012
@@ -20,7 +20,7 @@ package org.apache.jmeter.timers;
 
 import java.io.IOException;
 
-import javax.script.ScriptEngineManager;
+import javax.script.ScriptEngine;
 import javax.script.ScriptException;
 
 import org.apache.jmeter.testbeans.TestBean;
@@ -37,22 +37,19 @@ public class JSR223Timer extends JSR223T
     public long delay() {
         long delay = 0;
         try {
-            ScriptEngineManager mgr = getManager();
-            if (mgr == null) {
-                return 0; 
-            }
-            Object o = processFileOrScript(mgr);
+            ScriptEngine scriptEngine = getScriptEngine();
+            Object o = processFileOrScript(scriptEngine);
             if (o == null) {
                 log.warn("Script did not return a value");
                 return 0;
             }
             delay = Long.valueOf(o.toString()).longValue();
         } catch (NumberFormatException e) {
-            log.warn("Problem in JSR223 script "+e);
+            log.warn("Problem in JSR223 script ", e);
         } catch (IOException e) {
-            log.warn("Problem in JSR223 script "+e);
+            log.warn("Problem in JSR223 script ", e);
         } catch (ScriptException e) {
-            log.warn("Problem in JSR223 script "+e);
+            log.warn("Problem in JSR223 script ", e);
         }
         return delay;
     }

Modified: jmeter/trunk/src/components/org/apache/jmeter/visualizers/JSR223Listener.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/components/org/apache/jmeter/visualizers/JSR223Listener.java?rev=1358733&r1=1358732&r2=1358733&view=diff
==============================================================================
--- jmeter/trunk/src/components/org/apache/jmeter/visualizers/JSR223Listener.java (original)
+++ jmeter/trunk/src/components/org/apache/jmeter/visualizers/JSR223Listener.java Sun Jul
 8 13:05:15 2012
@@ -20,7 +20,7 @@ package org.apache.jmeter.visualizers;
 
 import java.io.IOException;
 
-import javax.script.ScriptEngineManager;
+import javax.script.ScriptEngine;
 import javax.script.ScriptException;
 
 import org.apache.jmeter.samplers.SampleEvent;
@@ -41,15 +41,14 @@ public class JSR223Listener extends JSR2
 
     public void sampleOccurred(SampleEvent event) {
         try {
-            ScriptEngineManager sem = getManager();
-            if (sem == null) { return; }
-            sem.put("sampleEvent", event);
-            sem.put("sampleResult", event.getResult());
-            processFileOrScript(sem);
+            ScriptEngine scriptEngine = getScriptEngine();
+            scriptEngine.put("sampleEvent", event);
+            scriptEngine.put("sampleResult", event.getResult());
+            processFileOrScript(scriptEngine);
         } catch (ScriptException e) {
-            log.warn("Problem in JSR223 script "+e);
+            log.warn("Problem in JSR223 script ", e);
         } catch (IOException e) {
-            log.warn("Problem in JSR223 script "+e);
+            log.warn("Problem in JSR223 script ", e);
         }
     }
 

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=1358733&r1=1358732&r2=1358733&view=diff
==============================================================================
--- jmeter/trunk/src/core/org/apache/jmeter/util/JSR223TestElement.java (original)
+++ jmeter/trunk/src/core/org/apache/jmeter/util/JSR223TestElement.java Sun Jul  8 13:05:15
2012
@@ -43,6 +43,20 @@ import org.apache.log.Logger;
 public abstract class JSR223TestElement extends AbstractTestElement
     implements Serializable, Cloneable
 {
+    /**
+     * Initialization On Demand Holder pattern
+     */
+    private static class LazyHolder {
+        public static final ScriptEngineManager INSTANCE = new ScriptEngineManager();
+    }
+ 
+    /**
+     * @return ScriptEngineManager singleton
+     */
+    public static ScriptEngineManager getInstance() {
+            return LazyHolder.INSTANCE;
+    }
+    
     private static final long serialVersionUID = 233L;
 
     //++ For TestBean implementations only
@@ -79,13 +93,19 @@ public abstract class JSR223TestElement 
        return o;
     }
 
-    protected ScriptEngineManager getManager() {
-        ScriptEngineManager sem = new ScriptEngineManager();
-        initManager(sem);
-        return sem;
+    protected ScriptEngine getScriptEngine() throws ScriptException {
+        final String lang = getScriptLanguage();
+
+        ScriptEngine scriptEngine = getInstance().getEngineByName(lang);
+        if (scriptEngine == null) {
+            throw new ScriptException("Cannot find engine named: "+lang);
+        }
+
+        initScriptEngine(scriptEngine);
+        return scriptEngine;
     }
 
-    protected void initManager(ScriptEngineManager sem) {
+    protected void initScriptEngine(ScriptEngine sem) {
         final String label = getName();
         final String fileName = getFilename();
         final String scriptParameters = getParameters();
@@ -116,15 +136,8 @@ public abstract class JSR223TestElement 
     }
 
 
-    protected Object processFileOrScript(ScriptEngineManager sem) throws IOException, ScriptException
{
-
-        final String lang = getScriptLanguage();
-        ScriptEngine scriptEngine = sem.getEngineByName(lang);
-        if (scriptEngine == null) {
-            throw new ScriptException("Cannot find engine named: "+lang);
-        }
-
-        File scriptFile = new File(getFilename());
+    protected Object processFileOrScript(ScriptEngine scriptEngine) throws IOException, ScriptException
{
+        File scriptFile = new File(getFilename());        
         if (scriptFile.exists()) {
             BufferedReader fileReader = null;
             try {
@@ -136,7 +149,6 @@ public abstract class JSR223TestElement 
         } else {
             return scriptEngine.eval(getScript());
         }
-
     }
 
     /**
@@ -184,5 +196,4 @@ public abstract class JSR223TestElement 
     public void setScriptLanguage(String s) {
         scriptLanguage = s;
     }
-
-}
+}
\ No newline at end of file

Modified: jmeter/trunk/src/protocol/java/org/apache/jmeter/protocol/java/sampler/JSR223Sampler.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/protocol/java/org/apache/jmeter/protocol/java/sampler/JSR223Sampler.java?rev=1358733&r1=1358732&r2=1358733&view=diff
==============================================================================
--- jmeter/trunk/src/protocol/java/org/apache/jmeter/protocol/java/sampler/JSR223Sampler.java
(original)
+++ jmeter/trunk/src/protocol/java/org/apache/jmeter/protocol/java/sampler/JSR223Sampler.java
Sun Jul  8 13:05:15 2012
@@ -23,7 +23,7 @@ import java.util.Arrays;
 import java.util.HashSet;
 import java.util.Set;
 
-import javax.script.ScriptEngineManager;
+import javax.script.ScriptEngine;
 import javax.script.ScriptException;
 
 import org.apache.jmeter.config.ConfigTestElement;
@@ -58,15 +58,9 @@ public class JSR223Sampler extends JSR22
         result.setDataType(SampleResult.TEXT);
         result.sampleStart();
         try {
-            ScriptEngineManager mgr = getManager();
-            if (mgr == null) {
-                result.setSuccessful(false);
-                result.setResponseCode("500"); // $NON-NLS-1$
-                result.setResponseMessage("Could not instantiate ScriptManager");
-                return result;
-            }
-            mgr.put("SampleResult",result);
-            Object ret = processFileOrScript(mgr);
+            ScriptEngine scriptEngine = getScriptEngine();
+            scriptEngine.put("SampleResult",result);
+            Object ret = processFileOrScript(scriptEngine);
             result.setSuccessful(true);
             result.setResponseCodeOK();
             result.setResponseMessageOK();
@@ -74,12 +68,12 @@ public class JSR223Sampler extends JSR22
                 result.setResponseData(ret.toString(), null);
             }
         } catch (IOException e) {
-            log.warn("Problem in JSR223 script "+e);
+            log.warn("Problem in JSR223 script "+e, e);
             result.setSuccessful(false);
             result.setResponseCode("500"); // $NON-NLS-1$
             result.setResponseMessage(e.toString());
         } catch (ScriptException e) {
-            log.warn("Problem in JSR223 script "+e);
+            log.warn("Problem in JSR223 script "+e, e);
             result.setSuccessful(false);
             result.setResponseCode("500"); // $NON-NLS-1$
             result.setResponseMessage(e.toString());

Modified: jmeter/trunk/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/jmeter/trunk/xdocs/changes.xml?rev=1358733&r1=1358732&r2=1358733&view=diff
==============================================================================
--- jmeter/trunk/xdocs/changes.xml (original)
+++ jmeter/trunk/xdocs/changes.xml Sun Jul  8 13:05:15 2012
@@ -56,6 +56,13 @@ or a Debug Sampler with all fields set t
 <p>
 When using CacheManager, JMeter now caches responses with header Cache-Control=private,max-age=XX
as described in specification, see <bugzilla>53521</bugzilla>. 
 </p>
+
+<p>
+A major change has occured on JSR223 Test Elements, previously variables set up before script
execution where stored in ScriptEngineManager which was created once per execution, 
+now ScriptEngineManager is a singleton shared by all JSR223 elements and only ScriptEngine
is created once per execution, variables set up before script execution are now stored 
+in ScriptEngine context, see <bugzilla>53365</bugzilla>. 
+</p>
+
 <!-- =================== Bug fixes =================== -->
 
 <h2>Bug fixes</h2>
@@ -95,6 +102,7 @@ When using CacheManager, JMeter now cach
 
 <h3>General</h3>
 <ul>
+<li><bugzilla>53365</bugzilla> - JSR223TestElement should cache ScriptEngineManager</li>
 </ul>
 
 <!-- =================== Improvements =================== -->



Mime
View raw message