Package org.apache.jmeter.functions
Class AbstractFunction
java.lang.Object
org.apache.jmeter.functions.AbstractFunction
- All Implemented Interfaces:
Function
- Direct Known Subclasses:
BeanShell,ChangeCase,CharFunction,CSVRead,DateTimeConvertFunction,DigestEncodeFunction,EscapeHtml,EscapeOroRegexpChars,EscapeXml,EvalFunction,EvalVarFunction,FileToString,Groovy,IntSum,IsPropDefined,IsVarDefined,IterationCounter,JavaScript,Jexl2Function,Jexl3Function,LogFunction,LogFunction2,LongSum,MachineIP,MachineName,Property,Property2,Random,RandomDate,RandomFromMultipleVars,RandomString,RegexFunction,SamplerName,SetProperty,SplitFunction,StringFromFile,StringToFile,TestPlanName,ThreadGroupName,ThreadNumber,TimeFunction,TimeShift,UnEscape,UnEscapeHtml,UrlDecode,UrlEncode,Uuid,Variable,XPath
Provides common methods for all functions
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected final voidaddVariableValue(String value, CompoundVariable[] values, int index) Utility method to store value in a variableprotected voidcheckMinParameterCount(Collection<CompoundVariable> parameters, int minimum) Utility method to check parameter counts.protected voidcheckParameterCount(Collection<CompoundVariable> parameters, int count) Utility method to check parameter counts.protected voidcheckParameterCount(Collection<CompoundVariable> parameters, int min, int max) Utility method to check parameter counts.execute()abstract Stringexecute(SampleResult previousResult, Sampler currentSampler) N.B.abstract StringReturn the name of your function.protected JMeterVariablesGives access to the JMeter variables for the current thread.abstract voidsetParameters(Collection<CompoundVariable> parameters) Note: This is always called even if no parameters are provided (versions of JMeter after 2.3.1)Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.jmeter.functions.Function
getArgumentDesc
-
Constructor Details
-
AbstractFunction
public AbstractFunction()
-
-
Method Details
-
execute
public abstract String execute(SampleResult previousResult, Sampler currentSampler) throws InvalidVariableException N.B. execute() should be synchronized if function is operating with non-thread-safe objects (e.g. operates with files).
JMeter ensures setParameters() happens-before execute(): setParameters is executed in main thread, and worker threads are started after that.- Specified by:
executein interfaceFunction- Parameters:
previousResult- The previousSampleResultcurrentSampler- The currentSampler- Returns:
- The replacement value, which was generated by the function
- Throws:
InvalidVariableException- - when the variables for the function call can't be evaluated- See Also:
-
execute
- Throws:
InvalidVariableException
-
setParameters
public abstract void setParameters(Collection<CompoundVariable> parameters) throws InvalidVariableException Note: This is always called even if no parameters are provided (versions of JMeter after 2.3.1)- Specified by:
setParametersin interfaceFunction- Parameters:
parameters- The parameters for the function call- Throws:
InvalidVariableException- - when the variables for the function call can't be evaluated- See Also:
-
getReferenceKey
Description copied from interface:FunctionReturn the name of your function. Convention is to prepend "__" to the name (ie "__regexFunction")- Specified by:
getReferenceKeyin interfaceFunction- Returns:
- The name of the function
- See Also:
-
getVariables
Gives access to the JMeter variables for the current thread.- Returns:
- a pointer to the JMeter variables.
-
checkParameterCount
protected void checkParameterCount(Collection<CompoundVariable> parameters, int min, int max) throws InvalidVariableException Utility method to check parameter counts.- Parameters:
parameters- collection of parametersmin- minimum number of parameters allowedmax- maximum number of parameters allowed- Throws:
InvalidVariableException- if the number of parameters is incorrect
-
checkParameterCount
protected void checkParameterCount(Collection<CompoundVariable> parameters, int count) throws InvalidVariableException Utility method to check parameter counts.- Parameters:
parameters- collection of parameterscount- number of parameters expected- Throws:
InvalidVariableException- if the number of parameters is incorrect
-
checkMinParameterCount
protected void checkMinParameterCount(Collection<CompoundVariable> parameters, int minimum) throws InvalidVariableException Utility method to check parameter counts.- Parameters:
parameters- collection of parametersminimum- number of parameters expected- Throws:
InvalidVariableException- if the number of parameters is incorrect
-
addVariableValue
Utility method to store value in a variable- Parameters:
value- value of variable to updatevalues- array ofCompoundVariablefrom which variable name will be extractedindex- index of variable in values array
-