BeanShell Server commands in Jmeter
In this article we are going to see the Bean Shell server commands which
can be enabled. To enable BeanShell server command files , see my this post.
When we enable , following files are set to use for initialization. These are located in \bin directory.
BeanShellAssertion.bshrc
BeanShellFunction.bshrc
BeanShellSampler.bshrc
Note : In bin directory, we will see BeanShellListeners.bshrc also. The file contains sample definitions of Test and Thread Listeners. Not command to be installed. When ever we need to monitor listeners, we will need that.
Note :The Following functions will be installed Commonly for
-BeanShellSampler.bshrc , BeanShellFunction.bshrc , BeanShellAssertion.bshrc
import org.apache.jmeter.util.JMeterUtils;
i = j = k = 0; // for counters
getprop(p) // get a JMeter property
{
return JMeterUtils.getPropDefault(p,"");
}
getprop(p,d)// get a JMeter property with default
{
return JMeterUtils.getPropDefault(p,d);
}
setprop(p,v)// set a JMeter property
{
JMeterUtils.setProperty(p, v);
}
---Common ended---
When beanshell.sampler.init=BeanShellSampler.bshrc is enabled , following functions will be installed with functions from common section.
stopEngine()// Stop the JMeter test
{
org.apache.jmeter.engine.StandardJMeterEngine.stopEngine();
}
stopThread(t)// Stop a JMeter thread
{
org.apache.jmeter.engine.StandardJMeterEngine.stopThread(t);
}
String getVariables() // Create a listing of the thread variables
{
StringBuffer myStringBuffer= new StringBuffer(100);
Iterator i = vars.getIterator();
while(i.hasNext())
{
Map.Entry me = i.next();
if(String.class.equals(me.getValue().getClass())){
myStringBuffer.append(me.toString()).append("\n");
}
}
return sb.toString();
}
interrupt() // Interruptible interface
{
print("Interrupt detected");
}
When beanshell.function.init=BeanShellFunction.bshrc is enabled , following functions will be installed with the functions mentioned in common section
stopTest()// to stop the test or the current thread
{
org.apache.jmeter.engine.StandardJMeterEngine.stopEngine();
}
stopThread()// Stop current JMeter thread
{
org.apache.jmeter.engine.StandardJMeterEngine.stopThread(Thread.currentThread().getName());
}
String fixAmps(s)// Fix ampersands in a string
{
return s.replaceAll("&","&");
}
String fixAmpsInVar(String varname)
{
return fixAmps(vars.get(varname));
}
When beanshell.assertion.init=BeanShellAssertion.bshrc is enabled , Common functions will be installed only.
Note : With the necessary of functions, we need to choose BeanShell Sampler file to initialize.
I will try to use BeanShell in my example section of jmeter so that it can be easy to understand.
..Thanks...:)
When we enable , following files are set to use for initialization. These are located in \bin directory.
BeanShellAssertion.bshrc
BeanShellFunction.bshrc
BeanShellSampler.bshrc
Note : In bin directory, we will see BeanShellListeners.bshrc also. The file contains sample definitions of Test and Thread Listeners. Not command to be installed. When ever we need to monitor listeners, we will need that.
Note :The Following functions will be installed Commonly for
-BeanShellSampler.bshrc , BeanShellFunction.bshrc , BeanShellAssertion.bshrc
import org.apache.jmeter.util.JMeterUtils;
i = j = k = 0; // for counters
getprop(p) // get a JMeter property
{
return JMeterUtils.getPropDefault(p,"");
}
getprop(p,d)// get a JMeter property with default
{
return JMeterUtils.getPropDefault(p,d);
}
setprop(p,v)// set a JMeter property
{
JMeterUtils.setProperty(p, v);
}
---Common ended---
When beanshell.sampler.init=BeanShellSampler.bshrc is enabled , following functions will be installed with functions from common section.
stopEngine()// Stop the JMeter test
{
org.apache.jmeter.engine.StandardJMeterEngine.stopEngine();
}
stopThread(t)// Stop a JMeter thread
{
org.apache.jmeter.engine.StandardJMeterEngine.stopThread(t);
}
String getVariables() // Create a listing of the thread variables
{
StringBuffer myStringBuffer= new StringBuffer(100);
Iterator i = vars.getIterator();
while(i.hasNext())
{
Map.Entry me = i.next();
if(String.class.equals(me.getValue().getClass())){
myStringBuffer.append(me.toString()).append("\n");
}
}
return sb.toString();
}
interrupt() // Interruptible interface
{
print("Interrupt detected");
}
When beanshell.function.init=BeanShellFunction.bshrc is enabled , following functions will be installed with the functions mentioned in common section
stopTest()// to stop the test or the current thread
{
org.apache.jmeter.engine.StandardJMeterEngine.stopEngine();
}
stopThread()// Stop current JMeter thread
{
org.apache.jmeter.engine.StandardJMeterEngine.stopThread(Thread.currentThread().getName());
}
String fixAmps(s)// Fix ampersands in a string
{
return s.replaceAll("&","&");
}
String fixAmpsInVar(String varname)
{
return fixAmps(vars.get(varname));
}
When beanshell.assertion.init=BeanShellAssertion.bshrc is enabled , Common functions will be installed only.
Note : With the necessary of functions, we need to choose BeanShell Sampler file to initialize.
I will try to use BeanShell in my example section of jmeter so that it can be easy to understand.
..Thanks...:)
No comments:
Post a Comment