使用JMeter时陷入嵌套循环中.嵌套循环控制器和CSV数据集配置. [英] Stuck in a nested loop while using JMeter. Nested loop controller and CSV data set config.

查看:126
本文介绍了使用JMeter时陷入嵌套循环中.嵌套循环控制器和CSV数据集配置.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的网站上,我有两个商家操作:搜索和浏览.搜索通常会触发三个浏览.

On my site I have two merchant actions: search and browse. A search normally triggers three browses.

我有一个JMeter测试,该测试使用商户和商户ID号的CSV文件,在大规模运行此测试时,我希望使用网站上的所有商户.

I have a JMeter test which uses a CSV file of merchants and merchant id numbers, when running this test at scale I want all the merchants on my site to be used.

我已经在JMeter中将其映射为:

I have mapped this in JMeter like so:

  • 回路控制器
    • HTTP采样器(搜索/search/$ {merchant_name})
    • CSV数据集配置(商家名称)
    • 回路控制器
      • HTTP采样器(浏览/merchant/$ {merchant_id})
      • CSV数据集配置(商家ID)
      • Loop Controller
        • HTTP Sampler (Search /search/${merchant_name})
        • CSV data set config (Merchant Name)
        • Loop Controller
          • HTTP Sampler (Browse /merchant/${merchant_id})
          • CSV data set Config (Merchant ID)

          我在外部循环中设置loop count = 2,在内部循环中设置loop count = 3.

          I set loop count = 2 in the outer loop and loop count = 3 in the inner loop.

          我希望进行两次搜索才能触发6个浏览操作.但是我得到的是一个搜索,然后进行三个浏览,直到我中止测试为止.

          I expect two searches to trigger 6 browse actions. But what I get is a search, followed by three browses, continually until I abort the test.

          我是否误解了循环结构?这是预期的行为吗?

          Have I misunderstood the loop construct? Is this the expected behaviour?

          我如何实现运行搜索,然后进行三次浏览两次的目标?

          How can I achieve my goal of running a search, followed by three browses, twice?

          推荐答案

          我认为您正在滥用CSV数据集配置.

          I think that you're misusing CSV Data Set configuration.

          我的情况如下:

          提供以下CSV文件:

          merchants.csv包含:

          merchant1name
          merchant2name
          

          和另外2个CSV文件:merchant1name.csvmerchant2name.csv,其内容为:

          and 2 other CSV files: merchant1name.csv and merchant2name.csv with the contents of:

          id1
          id2
          id3
          

          并遵循测试计划结构:

          • 线程组(1个线程,1秒加速,1个循环)
            • 循环控制器(2个循环)
              • HTTP请求/$ {商家名称}
                • Beanshell后处理器(请参见下面的代码和说明)
                • Thread Group (1 thread, 1 second ramp-up, 1 loop)
                  • Loop Controller (2 loops)
                    • HTTP Request /${merchantname}
                      • Beanshell Post Processor (see below for code and explanation)
                      • HTTP请求/$ {merchantid}
                        • CSV数据集配置(文件名:商人名称1文件的完整路径,商人名称1应该是属性,变量名称:商人id,所有默认值)
                        • HTTP Request /${merchantid}
                          • CSV Data Set Config (Filename: full path to merchantname1 file, merchantname1 should be property, Variable name: merchantid, all defaults)

                          通过对CSV数据集配置使用所有默认设置",我假设以下内容:

                          By using "all defaults" in regards to CSV Data Set Config I assume the following:

                          • 文件编码-空白(我的JMeter使用UTF-8运行,在大多数情况下都可以使用)
                          • 定界符-,(逗号)
                          • 允许引用数据-假
                          • 在EOF上回收-true
                          • 在EOF上停止线程-假
                          • 共享模式-所有线程

                          Beanshell代码:

                          Beanshell Code:

                          props.put("merchantname", vars.get("merchantname"));
                          

                          这是必需的,因为CSV数据配置不允许在文件路径中使用变量.

                          This is required as CSV Data Config does not allow using variables in file path.

                          内循环中的路径:

                          C:\jmeter\${__P(merchantname,)}.csv
                          

                          您可以参考 http://glinius.narod.ru/stackoverflow/nestedloop.zip 文件.将所有内容从"nestedloop"文件夹(1个jmx文件和3个CSV文件)解压缩到JMeter的/bin文件夹,然后运行测试.它将产生8个请求

                          You can refer to http://glinius.narod.ru/stackoverflow/nestedloop.zip file. Unpack everything from "nestedloop" folder (1 jmx file and 3 CSV files) to /bin folder of JMeter and run the test. It'll produce 8 requests

                          参考资料:

                          1. 使用CSV数据集配置
                          2. 如何使用BeanShell
                          1. Using CSV DATA SET CONFIG
                          2. How to use BeanShell

                          这篇关于使用JMeter时陷入嵌套循环中.嵌套循环控制器和CSV数据集配置.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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