Author: sebb Date: Sat Jun 9 14:51:13 2007 New Revision: 545799 URL: http://svn.apache.org/viewvc?view=rev&rev=545799 Log: Add TestListener and ThreadListener support to BeanShell test elements
Added: jakarta/jmeter/branches/rel-2-2/bin/BeanShellListeners.bshrc Modified: jakarta/jmeter/branches/rel-2-2/src/components/org/apache/jmeter/assertions/BeanShellAssertion.java jakarta/jmeter/branches/rel-2-2/src/components/org/apache/jmeter/extractor/BeanShellPostProcessor.java jakarta/jmeter/branches/rel-2-2/src/components/org/apache/jmeter/modifiers/BeanShellPreProcessor.java jakarta/jmeter/branches/rel-2-2/src/components/org/apache/jmeter/timers/BeanShellTimer.java jakarta/jmeter/branches/rel-2-2/src/protocol/java/org/apache/jmeter/protocol/java/sampler/BeanShellSampler.java jakarta/jmeter/branches/rel-2-2/xdocs/changes.xml jakarta/jmeter/branches/rel-2-2/xdocs/usermanual/component_reference.xml Added: jakarta/jmeter/branches/rel-2-2/bin/BeanShellListeners.bshrc URL: http://svn.apache.org/viewvc/jakarta/jmeter/branches/rel-2-2/bin/BeanShellListeners.bshrc?view=auto&rev=545799 ============================================================================== --- jakarta/jmeter/branches/rel-2-2/bin/BeanShellListeners.bshrc (added) +++ jakarta/jmeter/branches/rel-2-2/bin/BeanShellListeners.bshrc Sat Jun 9 14:51:13 2007 @@ -0,0 +1,29 @@ +# Example BeanShell Listener definitions + +# ThreadListener methods + +threadStarted(){ + print("threadStarted"); +} + +threadFinished(){ + print("threadFinished"); +} + +# TestListener methods + +testStarted(){ + print("testStarted"); +} + +testEnded(){ + print("testEnded"); +} + +testStarted(String s){ + print("testStarted "+s); +} + +testEnded(String s){ + print("testEnded "+s); +} \ No newline at end of file Modified: jakarta/jmeter/branches/rel-2-2/src/components/org/apache/jmeter/assertions/BeanShellAssertion.java URL: http://svn.apache.org/viewvc/jakarta/jmeter/branches/rel-2-2/src/components/org/apache/jmeter/assertions/BeanShellAssertion.java?view=diff&rev=545799&r1=545798&r2=545799 ============================================================================== --- jakarta/jmeter/branches/rel-2-2/src/components/org/apache/jmeter/assertions/BeanShellAssertion.java (original) +++ jakarta/jmeter/branches/rel-2-2/src/components/org/apache/jmeter/assertions/BeanShellAssertion.java Sat Jun 9 14:51:13 2007 @@ -21,8 +21,11 @@ import java.io.IOException; import java.io.Serializable; +import org.apache.jmeter.engine.event.LoopIterationEvent; import org.apache.jmeter.samplers.SampleResult; import org.apache.jmeter.testelement.AbstractTestElement; +import org.apache.jmeter.testelement.TestListener; +import org.apache.jmeter.testelement.ThreadListener; import org.apache.jmeter.threads.JMeterContext; import org.apache.jmeter.threads.JMeterContextService; import org.apache.jmeter.threads.JMeterVariables; @@ -36,9 +39,8 @@ /** * A sampler which understands BeanShell * - * @version $Revision$ Updated on: $Date$ */ -public class BeanShellAssertion extends AbstractTestElement implements Serializable, Assertion { +public class BeanShellAssertion extends AbstractTestElement implements Serializable, Assertion, ThreadListener, TestListener { private static final Logger log = LoggingManager.getLoggerForClass(); public static final String FILENAME = "BeanShellAssertion.filename"; //$NON-NLS-1$ @@ -172,5 +174,69 @@ } return result; + } + + public void threadStarted() { + if (bshInterpreter == null) return; + try { + bshInterpreter.eval("threadStarted()"); // $NON-NLS-1$ + } catch (JMeterException ignored) { + log.debug(ignored.getLocalizedMessage()); + } + } + + public void threadFinished() { + if (bshInterpreter == null) return; + try { + bshInterpreter.eval("threadFinished()"); // $NON-NLS-1$ + } catch (JMeterException ignored) { + log.debug(ignored.getLocalizedMessage()); + } + } + + public void testEnded() { + if (bshInterpreter == null) return; + try { + bshInterpreter.eval("testEnded()"); // $NON-NLS-1$ + } catch (JMeterException ignored) { + log.debug(ignored.getLocalizedMessage()); + } + } + + public void testEnded(String host) { + if (bshInterpreter == null) return; + try { + bshInterpreter.eval((new StringBuffer("testEnded(")) // $NON-NLS-1$ + .append(host) + .append(")") // $NON-NLS-1$ + .toString()); // $NON-NLS-1$ + } catch (JMeterException ignored) { + log.debug(ignored.getLocalizedMessage()); + } + } + + public void testIterationStart(LoopIterationEvent event) { + // Not implemented + } + + public void testStarted() { + if (bshInterpreter == null) return; + try { + bshInterpreter.eval("testStarted()"); // $NON-NLS-1$ + } catch (JMeterException ignored) { + log.debug(ignored.getLocalizedMessage()); + } + } + + public void testStarted(String host) { + if (bshInterpreter == null) return; + try { + bshInterpreter.eval((new StringBuffer("testStarted(")) // $NON-NLS-1$ + .append(host) + .append(")") // $NON-NLS-1$ + .toString()); // $NON-NLS-1$ + } catch (JMeterException ignored) { + log.debug(ignored.getLocalizedMessage()); + } } } Modified: jakarta/jmeter/branches/rel-2-2/src/components/org/apache/jmeter/extractor/BeanShellPostProcessor.java URL: http://svn.apache.org/viewvc/jakarta/jmeter/branches/rel-2-2/src/components/org/apache/jmeter/extractor/BeanShellPostProcessor.java?view=diff&rev=545799&r1=545798&r2=545799 ============================================================================== --- jakarta/jmeter/branches/rel-2-2/src/components/org/apache/jmeter/extractor/BeanShellPostProcessor.java (original) +++ jakarta/jmeter/branches/rel-2-2/src/components/org/apache/jmeter/extractor/BeanShellPostProcessor.java Sat Jun 9 14:51:13 2007 @@ -20,10 +20,13 @@ import java.io.Serializable; +import org.apache.jmeter.engine.event.LoopIterationEvent; import org.apache.jmeter.processor.PostProcessor; import org.apache.jmeter.samplers.SampleResult; import org.apache.jmeter.testbeans.TestBean; import org.apache.jmeter.testelement.AbstractTestElement; +import org.apache.jmeter.testelement.TestListener; +import org.apache.jmeter.testelement.ThreadListener; import org.apache.jmeter.threads.JMeterContext; import org.apache.jmeter.threads.JMeterContextService; import org.apache.jmeter.threads.JMeterVariables; @@ -33,7 +36,9 @@ import org.apache.jorphan.util.JMeterException; import org.apache.log.Logger; -public class BeanShellPostProcessor extends AbstractTestElement implements PostProcessor, Serializable, TestBean { +public class BeanShellPostProcessor extends AbstractTestElement + implements PostProcessor, Serializable, TestBean, ThreadListener, TestListener +{ private static final Logger log = LoggingManager.getLoggerForClass(); private static final long serialVersionUID = 3; @@ -97,4 +102,67 @@ public void setScript(String s){ script=s; } + public void threadStarted() { + if (bshInterpreter == null) return; + try { + bshInterpreter.eval("threadStarted()"); // $NON-NLS-1$ + } catch (JMeterException ignored) { + log.debug(ignored.getLocalizedMessage()); + } + } + + public void threadFinished() { + if (bshInterpreter == null) return; + try { + bshInterpreter.eval("threadFinished()"); // $NON-NLS-1$ + } catch (JMeterException ignored) { + log.debug(ignored.getLocalizedMessage()); + } + } + + public void testEnded() { + if (bshInterpreter == null) return; + try { + bshInterpreter.eval("testEnded()"); // $NON-NLS-1$ + } catch (JMeterException ignored) { + log.debug(ignored.getLocalizedMessage()); + } + } + + public void testEnded(String host) { + if (bshInterpreter == null) return; + try { + bshInterpreter.eval((new StringBuffer("testEnded(")) // $NON-NLS-1$ + .append(host) + .append(")") // $NON-NLS-1$ + .toString()); // $NON-NLS-1$ + } catch (JMeterException ignored) { + log.debug(ignored.getLocalizedMessage()); + } + } + + public void testIterationStart(LoopIterationEvent event) { + // Not implemented + } + + public void testStarted() { + if (bshInterpreter == null) return; + try { + bshInterpreter.eval("testStarted()"); // $NON-NLS-1$ + } catch (JMeterException ignored) { + log.debug(ignored.getLocalizedMessage()); + } + } + + public void testStarted(String host) { + if (bshInterpreter == null) return; + try { + bshInterpreter.eval((new StringBuffer("testStarted(")) // $NON-NLS-1$ + .append(host) + .append(")") // $NON-NLS-1$ + .toString()); // $NON-NLS-1$ + } catch (JMeterException ignored) { + log.debug(ignored.getLocalizedMessage()); + } + } } Modified: jakarta/jmeter/branches/rel-2-2/src/components/org/apache/jmeter/modifiers/BeanShellPreProcessor.java URL: http://svn.apache.org/viewvc/jakarta/jmeter/branches/rel-2-2/src/components/org/apache/jmeter/modifiers/BeanShellPreProcessor.java?view=diff&rev=545799&r1=545798&r2=545799 ============================================================================== --- jakarta/jmeter/branches/rel-2-2/src/components/org/apache/jmeter/modifiers/BeanShellPreProcessor.java (original) +++ jakarta/jmeter/branches/rel-2-2/src/components/org/apache/jmeter/modifiers/BeanShellPreProcessor.java Sat Jun 9 14:51:13 2007 @@ -20,11 +20,14 @@ import java.io.Serializable; +import org.apache.jmeter.engine.event.LoopIterationEvent; import org.apache.jmeter.processor.PreProcessor; import org.apache.jmeter.samplers.SampleResult; import org.apache.jmeter.samplers.Sampler; import org.apache.jmeter.testbeans.TestBean; import org.apache.jmeter.testelement.AbstractTestElement; +import org.apache.jmeter.testelement.TestListener; +import org.apache.jmeter.testelement.ThreadListener; import org.apache.jmeter.threads.JMeterContext; import org.apache.jmeter.threads.JMeterContextService; import org.apache.jmeter.threads.JMeterVariables; @@ -34,7 +37,9 @@ import org.apache.jorphan.util.JMeterException; import org.apache.log.Logger; -public class BeanShellPreProcessor extends AbstractTestElement implements PreProcessor, Serializable, TestBean { +public class BeanShellPreProcessor extends AbstractTestElement + implements PreProcessor, Serializable, TestBean, ThreadListener, TestListener +{ private static final Logger log = LoggingManager.getLoggerForClass(); private static final long serialVersionUID = 3; @@ -98,4 +103,68 @@ public void setScript(String s){ script=s; } + + public void threadStarted() { + if (bshInterpreter == null) return; + try { + bshInterpreter.eval("threadStarted()"); // $NON-NLS-1$ + } catch (JMeterException ignored) { + log.debug(ignored.getLocalizedMessage()); + } + } + + public void threadFinished() { + if (bshInterpreter == null) return; + try { + bshInterpreter.eval("threadFinished()"); // $NON-NLS-1$ + } catch (JMeterException ignored) { + log.debug(ignored.getLocalizedMessage()); + } + } + + public void testEnded() { + if (bshInterpreter == null) return; + try { + bshInterpreter.eval("testEnded()"); // $NON-NLS-1$ + } catch (JMeterException ignored) { + log.debug(ignored.getLocalizedMessage()); + } + } + + public void testEnded(String host) { + if (bshInterpreter == null) return; + try { + bshInterpreter.eval((new StringBuffer("testEnded(")) // $NON-NLS-1$ + .append(host) + .append(")") // $NON-NLS-1$ + .toString()); // $NON-NLS-1$ + } catch (JMeterException ignored) { + log.debug(ignored.getLocalizedMessage()); + } + } + + public void testIterationStart(LoopIterationEvent event) { + // Not implemented + } + + public void testStarted() { + if (bshInterpreter == null) return; + try { + bshInterpreter.eval("testStarted()"); // $NON-NLS-1$ + } catch (JMeterException ignored) { + log.debug(ignored.getLocalizedMessage()); + } + } + + public void testStarted(String host) { + if (bshInterpreter == null) return; + try { + bshInterpreter.eval((new StringBuffer("testStarted(")) // $NON-NLS-1$ + .append(host) + .append(")") // $NON-NLS-1$ + .toString()); // $NON-NLS-1$ + } catch (JMeterException ignored) { + log.debug(ignored.getLocalizedMessage()); + } + } } Modified: jakarta/jmeter/branches/rel-2-2/src/components/org/apache/jmeter/timers/BeanShellTimer.java URL: http://svn.apache.org/viewvc/jakarta/jmeter/branches/rel-2-2/src/components/org/apache/jmeter/timers/BeanShellTimer.java?view=diff&rev=545799&r1=545798&r2=545799 ============================================================================== --- jakarta/jmeter/branches/rel-2-2/src/components/org/apache/jmeter/timers/BeanShellTimer.java (original) +++ jakarta/jmeter/branches/rel-2-2/src/components/org/apache/jmeter/timers/BeanShellTimer.java Sat Jun 9 14:51:13 2007 @@ -20,8 +20,11 @@ import java.io.Serializable; +import org.apache.jmeter.engine.event.LoopIterationEvent; import org.apache.jmeter.testbeans.TestBean; import org.apache.jmeter.testelement.AbstractTestElement; +import org.apache.jmeter.testelement.TestListener; +import org.apache.jmeter.testelement.ThreadListener; import org.apache.jmeter.threads.JMeterContext; import org.apache.jmeter.threads.JMeterContextService; import org.apache.jmeter.threads.JMeterVariables; @@ -31,7 +34,7 @@ import org.apache.jorphan.util.JMeterException; import org.apache.log.Logger; -public class BeanShellTimer extends AbstractTestElement implements Timer, Serializable, TestBean { +public class BeanShellTimer extends AbstractTestElement implements Timer, Serializable, TestBean, ThreadListener, TestListener { private static final Logger log = LoggingManager.getLoggerForClass(); private static final long serialVersionUID = 2; @@ -104,4 +107,68 @@ public void setScript(String s){ script=s; } + + public void threadStarted() { + if (bshInterpreter == null) return; + try { + bshInterpreter.eval("threadStarted()"); // $NON-NLS-1$ + } catch (JMeterException ignored) { + log.debug(ignored.getLocalizedMessage()); + } + } + + public void threadFinished() { + if (bshInterpreter == null) return; + try { + bshInterpreter.eval("threadFinished()"); // $NON-NLS-1$ + } catch (JMeterException ignored) { + log.debug(ignored.getLocalizedMessage()); + } + } + + public void testEnded() { + if (bshInterpreter == null) return; + try { + bshInterpreter.eval("testEnded()"); // $NON-NLS-1$ + } catch (JMeterException ignored) { + log.debug(ignored.getLocalizedMessage()); + } + } + + public void testEnded(String host) { + if (bshInterpreter == null) return; + try { + bshInterpreter.eval((new StringBuffer("testEnded(")) // $NON-NLS-1$ + .append(host) + .append(")") // $NON-NLS-1$ + .toString()); // $NON-NLS-1$ + } catch (JMeterException ignored) { + log.debug(ignored.getLocalizedMessage()); + } + } + + public void testIterationStart(LoopIterationEvent event) { + // Not implemented + } + + public void testStarted() { + if (bshInterpreter == null) return; + try { + bshInterpreter.eval("testStarted()"); // $NON-NLS-1$ + } catch (JMeterException ignored) { + log.debug(ignored.getLocalizedMessage()); + } + } + + public void testStarted(String host) { + if (bshInterpreter == null) return; + try { + bshInterpreter.eval((new StringBuffer("testStarted(")) // $NON-NLS-1$ + .append(host) + .append(")") // $NON-NLS-1$ + .toString()); // $NON-NLS-1$ + } catch (JMeterException ignored) { + log.debug(ignored.getLocalizedMessage()); + } + } } Modified: jakarta/jmeter/branches/rel-2-2/src/protocol/java/org/apache/jmeter/protocol/java/sampler/BeanShellSampler.java URL: http://svn.apache.org/viewvc/jakarta/jmeter/branches/rel-2-2/src/protocol/java/org/apache/jmeter/protocol/java/sampler/BeanShellSampler.java?view=diff&rev=545799&r1=545798&r2=545799 ============================================================================== --- jakarta/jmeter/branches/rel-2-2/src/protocol/java/org/apache/jmeter/protocol/java/sampler/BeanShellSampler.java (original) +++ jakarta/jmeter/branches/rel-2-2/src/protocol/java/org/apache/jmeter/protocol/java/sampler/BeanShellSampler.java Sat Jun 9 14:51:13 2007 @@ -20,9 +20,12 @@ import java.io.IOException; +import org.apache.jmeter.engine.event.LoopIterationEvent; import org.apache.jmeter.samplers.AbstractSampler; import org.apache.jmeter.samplers.Entry; import org.apache.jmeter.samplers.SampleResult; +import org.apache.jmeter.testelement.TestListener; +import org.apache.jmeter.testelement.ThreadListener; import org.apache.jmeter.threads.JMeterContext; import org.apache.jmeter.threads.JMeterContextService; import org.apache.jmeter.threads.JMeterVariables; @@ -36,9 +39,10 @@ /** * A sampler which understands BeanShell * - * @version $Revision$ Updated on: $Date$ */ -public class BeanShellSampler extends AbstractSampler { +public class BeanShellSampler extends AbstractSampler + implements ThreadListener, TestListener +{ private static final Logger log = LoggingManager.getLoggerForClass(); public static final String FILENAME = "BeanShellSampler.filename"; //$NON-NLS-1$ @@ -176,5 +180,69 @@ res.setSuccessful(isSuccessful); return res; + } + + public void threadStarted() { + if (bshInterpreter == null) return; + try { + bshInterpreter.eval("threadStarted()"); // $NON-NLS-1$ + } catch (JMeterException ignored) { + log.debug(ignored.getLocalizedMessage()); + } + } + + public void threadFinished() { + if (bshInterpreter == null) return; + try { + bshInterpreter.eval("threadFinished()"); // $NON-NLS-1$ + } catch (JMeterException ignored) { + log.debug(ignored.getLocalizedMessage()); + } + } + + public void testEnded() { + if (bshInterpreter == null) return; + try { + bshInterpreter.eval("testEnded()"); // $NON-NLS-1$ + } catch (JMeterException ignored) { + log.debug(ignored.getLocalizedMessage()); + } + } + + public void testEnded(String host) { + if (bshInterpreter == null) return; + try { + bshInterpreter.eval((new StringBuffer("testEnded(")) // $NON-NLS-1$ + .append(host) + .append(")") // $NON-NLS-1$ + .toString()); // $NON-NLS-1$ + } catch (JMeterException ignored) { + log.debug(ignored.getLocalizedMessage()); + } + } + + public void testIterationStart(LoopIterationEvent event) { + // Not implemented + } + + public void testStarted() { + if (bshInterpreter == null) return; + try { + bshInterpreter.eval("testStarted()"); // $NON-NLS-1$ + } catch (JMeterException ignored) { + log.debug(ignored.getLocalizedMessage()); + } + } + + public void testStarted(String host) { + if (bshInterpreter == null) return; + try { + bshInterpreter.eval((new StringBuffer("testStarted(")) // $NON-NLS-1$ + .append(host) + .append(")") // $NON-NLS-1$ + .toString()); // $NON-NLS-1$ + } catch (JMeterException ignored) { + log.debug(ignored.getLocalizedMessage()); + } } } Modified: jakarta/jmeter/branches/rel-2-2/xdocs/changes.xml URL: http://svn.apache.org/viewvc/jakarta/jmeter/branches/rel-2-2/xdocs/changes.xml?view=diff&rev=545799&r1=545798&r2=545799 ============================================================================== --- jakarta/jmeter/branches/rel-2-2/xdocs/changes.xml (original) +++ jakarta/jmeter/branches/rel-2-2/xdocs/changes.xml Sat Jun 9 14:51:13 2007 @@ -44,6 +44,7 @@ <li>FTP Sampler supports Ascii/Binary mode and upload</li> <li>Transaction Controller now generates Sample with subresults</li> <li>HTTPS session contexts are now per-thread, rather than shared. This gives better emulation of multiple users</li> +<li>BeanShell elements now support ThreadListener and TestListener interfaces</li> </ul> <p> The main bug fixes are: @@ -164,6 +165,7 @@ <li>Improve loading of CSV files: if possible, use header to determine format; guess timestamp format if not milliseconds</li> <li>Bug 41913 - TransactionController now creates samples as sub-samples of the transaction</li> <li>Bug 42506 - JMeter threads all use the same SSL session</li> +<li>BeanShell elements now support ThreadListener and TestListener interfaces</li> </ul> <h4>Non-functional improvements:</h4> Modified: jakarta/jmeter/branches/rel-2-2/xdocs/usermanual/component_reference.xml URL: http://svn.apache.org/viewvc/jakarta/jmeter/branches/rel-2-2/xdocs/usermanual/component_reference.xml?view=diff&rev=545799&r1=545798&r2=545799 ============================================================================== --- jakarta/jmeter/branches/rel-2-2/xdocs/usermanual/component_reference.xml (original) +++ jakarta/jmeter/branches/rel-2-2/xdocs/usermanual/component_reference.xml Sat Jun 9 14:51:13 2007 @@ -672,6 +672,11 @@ <br></br> For full details on using BeanShell, please see the BeanShell web-site at http://www.beanshell.org/.</b> </p> +<p> +The test element supports the ThreadListener and TestListener methods. +These should be defined in the initialisation file. +See the file BeanShellListeners.bshrc for example definitions. +</p> </description> <properties> <property name="Name" required="no">Descriptive name for this controller that is shown in the tree.</property> @@ -1808,11 +1813,16 @@ <description> <p> The BeanShell Listener allows the use of BeanShell for processing samples for saving etc. +</p> <p> <b>Please note that the BeanShell jar file is not included with JMeter; it needs to be separately downloaded. <br></br> For full details on using BeanShell, please see the BeanShell web-site at http://www.beanshell.org/.</b> </p> +<p> +The test element supports the ThreadListener and TestListener methods. +These should be defined in the initialisation file. +See the file BeanShellListeners.bshrc for example definitions. </p> </description> <properties> @@ -2466,6 +2476,11 @@ as the name of a sourced file. This can be used to define common methods and variables. There is a sample init file in the bin directory: BeanShellAssertion.bshrc </p> +<p> +The test element supports the ThreadListener and TestListener methods. +These should be defined in the initialisation file. +See the file BeanShellListeners.bshrc for example definitions. +</p> </description> <properties> @@ -2692,6 +2707,11 @@ <br></br> For full details on using BeanShell, please see the BeanShell web-site at http://www.beanshell.org/.</b> </p> +<p> +The test element supports the ThreadListener and TestListener methods. +These should be defined in the initialisation file. +See the file BeanShellListeners.bshrc for example definitions. +</p> </description> <properties> <property name="Name" required="">Descriptive name for this element that is shown in the tree.</property> @@ -2910,6 +2930,11 @@ <br></br> For full details on using BeanShell, please see the BeanShell web-site at http://www.beanshell.org/.</b> </p> +<p> +The test element supports the ThreadListener and TestListener methods. +These should be defined in the initialisation file. +See the file BeanShellListeners.bshrc for example definitions. +</p> </description> <properties> <property name="Name" required="">Descriptive name for this element that is shown in the tree.</property> @@ -3095,6 +3120,11 @@ <b>Please note that the BeanShell jar file is not included with JMeter; it needs to be separately downloaded. <br></br> For full details on using BeanShell, please see the BeanShell web-site at http://www.beanshell.org/.</b> +</p> +<p> +The test element supports the ThreadListener and TestListener methods. +These should be defined in the initialisation file. +See the file BeanShellListeners.bshrc for example definitions. </p> </description> <properties> --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]