【问题标题】:jmeter unique id per thread for http request用于 http 请求的每个线程的 jmeter 唯一 ID
【发布时间】:2015-07-24 15:20:29
【问题描述】:

我的 jmeter 测试发出一个包含唯一 ID 的 http 请求。

http://myserver.com/{uniqueId}/

我想为每个线程设置基数(比如 35000)并递增,例如我的 id 将是 35001、35002、35003 ...

http://myserver.com/{base + count}

我看到了 __threadnum 和 __counter 的函数,但我会怎么做:

  1. 将它设置在一个变量中,以便我可以在我的 url 中替换它
  2. 将此计数添加到我的基值中

【问题讨论】:

    标签: jmeter


    【解决方案1】:

    我会简单地使用 Beanshell 预处理器。

    int threadNo = ctx.getThreadNum()+1; //to get the thread number in beanshell
    int base = 35000;
    int uniqueId = threadNo + base;
    vars.put("uniqueId", Integer.toString(uniqueId));
    

    现在您的 HTTP 请求如下所示应该具有替换值。

    http://myserver.com/${uniqueId}/

    【讨论】:

    • 我对此进行了扩展,并将 Beanshell 预处理器添加到我的第一个 http 请求中,并在整个测试过程中使用这些变量。完美的例子!
    【解决方案2】:

    要为每个线程设置一个变量,您可以使用User Defined Variables

    总而言之,你可以使用函数:

    或者使用 JSR223 PRE ProcessorJSR223 POST Processor + Groovy 并在 Groovy 中执行。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多