我有以下要求:-
第二个要求:-
我怎样才能用豆壳处理器做到这一点。
我尝试过的解决方案:
对于第一点,我使用了设置线程,它应该是第一个要运行的线程。
对于第二点和第三点,我已经为每个线程定义了具有不同 CSV 文件的线程组(我不希望将其作为解决方案),因为它可能会上传超过 100 个 csv 文件并用作 no每组中的线程数不相同。
对于第4点,我还没有任何解决方案,第二个要求也是如此。
首先,Beanshell 脚本是某种形式的性能反模式,从 JMeter 3.1 开始,您应该使用 JSR223 测试元素和 Groovy 语言e 进行脚本编写。有关 Jmeter 中 Groovy 脚本编写的更多信息,请参阅 Apache Groovy:Groovy 有何用途?。
实现“以下要求”的示例代码如下所示:
def engine = ctx.getEngine();
def test = engine.getClass().getDeclaredField("test");
test.setAccessible(true);
def testPlanTree = test.get(engine)
def threadGroupSearch = new org.apache.jorphan.collections.SearchByClass<>(org.apache.jmeter.threads.ThreadGroup.class)
testPlanTree.traverse(threadGroupSearch)
def threadGroups = threadGroupSearch.getSearchResults()
def threadGroupIndex = ((ctx.getThread().getThreadName() =~ ctx.getThreadGroup().getName() + ' (\\d+)')[0][1]) as int
int offset = 0
0.upto(threadGroupIndex - 1, {
if (threadGroupIndex > 1) {
offset += threadGroups.toArray()[it - 1].getNumThreads()
}
})
def threadNum = 0
if (threadGroupIndex == 1) {
threadNum = ctx.getThread().getThreadNum()
} else {
threadNum = ctx.getThread().getThreadNum() - 1
}
def lineFromCSV = offset + threadNum
def line = new File('test.csv').readLines().get(lineFromCSV)
//do what you need with this "line" here
关于“第二个要求”,您可以将以下 __groovy() 函数放入 Loop Controller 的“循环计数”输入中:
${__groovy((vars.get('total_count') as int) < (vars.get('max_count') as int) ? vars.get('max_count') : vars.get('total_count'),)}