我需要在Jmeter中创建一个自定义函数,由于性能问题,我不能使用beanshell。
我在http://gabenell.blogspot.com/2010/01/custom-functions-for-jmeter.html和http://code4reference.com/2013/06/jmeter-custom-function-implementation/之后编写了一个Java类,但是当我编译它时,我似乎无法让Jmeter识别它。
我的课:
package custom.functions;
import org.apache.jmeter.engine.util.CompoundVariable;
import org.apache.jmeter.functions.AbstractFunction;
import org.apache.jmeter.functions.InvalidVariableException;
import org.apache.jmeter.samplers.SampleResult;
import org.apache.jmeter.samplers.Sampler;
import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
public class Username extends AbstractFunction{
private static final List<String> desc = new LinkedList<String>();
private static final String KEY = "__Username";
private int number = 0;
static {
desc.add("Pass a random value to get a valid username for the system.");
}
public Username() {
super();
}
@Override
public synchronized String execute(SampleResult previousResult, Sampler currentSampler)
throws InvalidVariableException {
try {
return getValue(number);
} catch(Exception e){
throw new InvalidVariableException(e);
}
}
public String getValue(int number){
return "John-Smith";
}
@Override
public synchronized void setParameters(Collection<CompoundVariable> parameters) throws InvalidVariableException {
checkParameterCount(parameters, 1, 1);
Object[] values = parameters.toArray();
number = Integer.parseInt(((CompoundVariable) values[0]).execute().trim());
}
@Override
public String getReferenceKey() {
return KEY;
}
@Override
public List<String> getArgumentDesc() {
return desc;
}
}
当我运行jar tf custom-functions.jar
(以验证类文件在jar中)时:
META-INF/
META-INF/MANIFEST.MF
custom/
custom/functions/
custom/functions/Username.class
我将jar放在我的jmeter lib / ext目录中,并尝试单独运行,并使用来运行jmeter -Jsearch_paths=../lib/ext/custom-functions.jar
,但是无论哪种方式,当我打开功能助手工具时都没有列出它,而是一个简单的测试计划来验证该函数是否发送%24%7B__Username%281%29%7D
。
我是否将文件放置在正确的位置?命名不正确吗?
我的问题是我使用Java 8而不是Java 7编译了我的类,这是我用于jmeter的运行时。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句