在 JMeter 中有条件地重新启动用户线程 [英] Restarting a user thread conditionally in JMeter

查看:30
本文介绍了在 JMeter 中有条件地重新启动用户线程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道我可以在 JMeter 中有条件地停止线程.

I know that I can stop a thread conditionally in JMeter.

在我的脚本中,我发送了一个请求,然后我提取了他们的响应 json 以进一步处理它.在一些罕见的情况下,参数响应提供了一些我无法在进一步步骤中处理的值.

In my script I'm sending a requests and then I'm extracting their response json to further process it. There are some rare cases, where the parameter response provides some value that I cannot process in further steps.

我实际上可以通过提取另一个参数来检测此有效响应.是否可以根据条件重新启动线程而不是停止它?

I could actually detect this valid response by extracting another parameter. Would it be possible to just restart the thread based on condition, instead of stopping it?

推荐答案

对于进一步的研究人员:

For further researchers:

根据条件开始另一个线程迭代的简单方法(即从 json 中提取一些数据)是以上述方式使用 BeanShell 采样器.

The easy way to start another iteration of a thread based on condition (i.e extracting some data out of json) is to use a BeanShell Sampler in way like described above.

    import org.apache.jmeter.samplers.SampleResult;
    import org.apache.jmeter.threads.JMeterContext;
    import org.apache.jmeter.threads.JMeterContext.TestLogicalAction;


    String statVar = vars.get("statusVariable");    //getting some data for condition check (statusVariable is a variable that has been set previously in the Jmeter JSON Extractor)

    if(statVar.equals("NOK")){ .                   //checking the condition

    SampleResult.setTestLogicalAction(TestLogicalAction.START_NEXT_ITERATION_OF_THRE 
            AD);                                  //Starting thread again (it starts the thread from the beginning, so we may compare this to restart effect)
}

这篇关于在 JMeter 中有条件地重新启动用户线程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆