Author: sebb Date: Sat Sep 17 15:50:29 2011 New Revision: 1172004 URL: http://svn.apache.org/viewvc?rev=1172004&view=rev Log: Beanshell Sampler now supports Interruptible interface
Modified: jakarta/jmeter/trunk/bin/BeanShellSampler.bshrc jakarta/jmeter/trunk/src/protocol/java/org/apache/jmeter/protocol/java/sampler/BeanShellSampler.java jakarta/jmeter/trunk/xdocs/changes.xml jakarta/jmeter/trunk/xdocs/usermanual/component_reference.xml Modified: jakarta/jmeter/trunk/bin/BeanShellSampler.bshrc URL: http://svn.apache.org/viewvc/jakarta/jmeter/trunk/bin/BeanShellSampler.bshrc?rev=1172004&r1=1172003&r2=1172004&view=diff ============================================================================== --- jakarta/jmeter/trunk/bin/BeanShellSampler.bshrc (original) +++ jakarta/jmeter/trunk/bin/BeanShellSampler.bshrc Sat Sep 17 15:50:29 2011 @@ -1,4 +1,6 @@ // Sample BeanShell Sampler initialisation file +// To enable, define the JMeter property: +// beanshell.sampler.init=BeanShellSampler.bshrc /* * Licensed to the Apache Software Foundation (ASF) under one or more @@ -58,4 +60,10 @@ String getVariables(){ // Create a listi return sb.toString(); } +// Interruptible interface + +interrupt() { + print("Interrupt detected"); +} + //print("Initialisation complete"); Modified: jakarta/jmeter/trunk/src/protocol/java/org/apache/jmeter/protocol/java/sampler/BeanShellSampler.java URL: http://svn.apache.org/viewvc/jakarta/jmeter/trunk/src/protocol/java/org/apache/jmeter/protocol/java/sampler/BeanShellSampler.java?rev=1172004&r1=1172003&r2=1172004&view=diff ============================================================================== --- jakarta/jmeter/trunk/src/protocol/java/org/apache/jmeter/protocol/java/sampler/BeanShellSampler.java (original) +++ jakarta/jmeter/trunk/src/protocol/java/org/apache/jmeter/protocol/java/sampler/BeanShellSampler.java Sat Sep 17 15:50:29 2011 @@ -19,18 +19,20 @@ package org.apache.jmeter.protocol.java.sampler; import org.apache.jmeter.samplers.Entry; +import org.apache.jmeter.samplers.Interruptible; import org.apache.jmeter.samplers.SampleResult; import org.apache.jmeter.samplers.Sampler; import org.apache.jmeter.util.BeanShellInterpreter; import org.apache.jmeter.util.BeanShellTestElement; import org.apache.jorphan.logging.LoggingManager; +import org.apache.jorphan.util.JMeterException; import org.apache.log.Logger; /** * A sampler which understands BeanShell * */ -public class BeanShellSampler extends BeanShellTestElement implements Sampler +public class BeanShellSampler extends BeanShellTestElement implements Sampler, Interruptible { private static final Logger log = LoggingManager.getLoggerForClass(); @@ -46,6 +48,8 @@ public class BeanShellSampler extends Be public static final String RESET_INTERPRETER = "BeanShellSampler.resetInterpreter"; //$NON-NLS-1$ + private volatile BeanShellInterpreter savedBsh = null; + @Override protected String getInitFileProperty() { return INIT_FILE; @@ -104,7 +108,9 @@ public class BeanShellSampler extends Be res.setDataType(SampleResult.TEXT); // assume text output - script can override if necessary + savedBsh = bshInterpreter; Object bshOut = processFileOrScript(bshInterpreter); + savedBsh = null; if (bshOut != null) {// Set response data String out = bshOut.toString(); @@ -134,6 +140,8 @@ public class BeanShellSampler extends Be log.warn(ex.toString()); res.setResponseCode("500");//$NON-NLS-1$ res.setResponseMessage(ex.toString()); + } finally { + savedBsh = null; } res.sampleEnd(); @@ -143,4 +151,16 @@ public class BeanShellSampler extends Be return res; } + + public boolean interrupt() { + if (savedBsh != null) { + try { + savedBsh.evalNoLog("interrupt()"); // $NON-NLS-1$ + } catch (JMeterException ignored) { + log.debug(getClass().getName() + " : " + ignored.getLocalizedMessage()); // $NON-NLS-1$ + } + return true; + } + return false; + } } Modified: jakarta/jmeter/trunk/xdocs/changes.xml URL: http://svn.apache.org/viewvc/jakarta/jmeter/trunk/xdocs/changes.xml?rev=1172004&r1=1172003&r2=1172004&view=diff ============================================================================== --- jakarta/jmeter/trunk/xdocs/changes.xml (original) +++ jakarta/jmeter/trunk/xdocs/changes.xml Sat Sep 17 15:50:29 2011 @@ -130,6 +130,7 @@ This can be overridden by setting the JM <h3>Other samplers</h3> <ul> +<li>Beanshell Sampler now supports Interruptible interface</li> </ul> <h3>Controllers</h3> Modified: jakarta/jmeter/trunk/xdocs/usermanual/component_reference.xml URL: http://svn.apache.org/viewvc/jakarta/jmeter/trunk/xdocs/usermanual/component_reference.xml?rev=1172004&r1=1172003&r2=1172004&view=diff ============================================================================== --- jakarta/jmeter/trunk/xdocs/usermanual/component_reference.xml (original) +++ jakarta/jmeter/trunk/xdocs/usermanual/component_reference.xml Sat Sep 17 15:50:29 2011 @@ -914,10 +914,14 @@ to configure this via the GUI, so it can <b>For full details on using BeanShell, please see the <a href="http://www.beanshell.org/">BeanShell website.</a></b> </p> <p> -The test element supports the ThreadListener and TestListener methods. -These should be defined in the initialisation file. +The test element supports the ThreadListener and TestListener interface methods. +These must be defined in the initialisation file. See the file BeanShellListeners.bshrc for example definitions. </p> +<p> +From JMeter version 2.5.1, the BeanShell sampler also supports the Interruptible interface. +The interrupt() method can be defined in the script or the init file. +</p> </description> <properties> <property name="Name" required="No">Descriptive name for this controller that is shown in the tree. --------------------------------------------------------------------- To unsubscribe, e-mail: notifications-unsubscr...@jakarta.apache.org For additional commands, e-mail: notifications-h...@jakarta.apache.org