当前位置: 首页 > article >正文

学英语学压测:03jmeter组件-采样器、逻辑控制器

📢📢📢:先看关键单词,再看英文,最后看中文总结,再回头看一遍英文原文,效果更佳!!

关键词

assertion断言/əˈsɜrʃən/
configuration element配置元素/ˌkɒn.fɪˈɡjʊr.eɪ.ʃən ˈɛlɪmənt/
controller控制器/kənˈtroʊlər/
cookie managercookie管理器/ˈkʊki ˈmænɪdʒər/
default默认值/dɪˈfɔlt/
interleave controller交错控制器/ˈɪntərˌliv kənˈtroʊlər/
listener监听器/ˈlɪsənər/
logical controller逻辑控制器/ˈlɒdʒɪkəl kənˈtroʊlər/
once only controller仅一次控制器/wʌns ˈoʊnli kənˈtroʊlər/
sampler采样器/ˈsæmplər/
thread group线程组/θrɛd ɡruːp/

控制器:包括采样器和逻辑控制器

JMeter has two types of Controllers: Samplers and Logical Controllers. These drive the processing of a test.

Samplers tell JMeter to send requests to a server. For example, add an HTTP Request Sampler if you want JMeter to send an HTTP request. You can also customize a request by adding one or more Configuration Elements to a Sampler. For more information, see Samplers.

Logical Controllers let you customize the logic that JMeter uses to decide when to send requests. For example, you can add an Interleave Logic Controller to alternate between two HTTP Request Samplers. For more information, see Logical Controllers.

采样器:

Samplers tell JMeter to send requests to a server and wait for a response. They are processed in the order they appear in the tree. Controllers can be used to modify the number of repetitions of a sampler.

JMeter samplers include:

  • FTP Request
  • HTTP Request (can be used for SOAP or REST Webservice also)
  • JDBC Request
  • Java object request
  • JMS request
  • JUnit Test request
  • LDAP Request
  • Mail request
  • OS Process request
  • TCP request

Each sampler has several properties you can set. You can further customize a sampler by adding one or more Configuration Elements to the Test Plan.

If you are going to send multiple requests of the same type (for example, HTTP Request) to the same server, consider using a Defaults Configuration Element. Each controller has one or more Defaults elements (see below).

Remember to add a Listener to your test plan to view and/or store the results of your requests to disk.

If you are interested in having JMeter perform basic validation on the response of your request, add an Assertion to the sampler. For example, in stress testing a web application, the server may return a successful "HTTP Response" code, but the page may have errors on it or may be missing sections. You could add assertions to check for certain HTML tags, common error strings, and so on. JMeter lets you create these assertions using regular expressions.

逻辑控制器

Logic Controllers let you customize the logic that JMeter uses to decide when to send requests. Logic Controllers can change the order of requests coming from their child elements. They can modify the requests themselves, cause JMeter to repeat requests, etc.

To understand the effect of Logic Controllers on a test plan, consider the following test tree:

  • Test Plan
    • Thread Group
      • Once Only Controller
        • Login Request (an HTTP Request)
      • Load Search Page (HTTP Sampler)
      • Interleave Controller
        • Search "A" (HTTP Sampler)
        • Search "B" (HTTP Sampler)
        • HTTP default request (Configuration Element)
      • HTTP default request (Configuration Element)
      • Cookie Manager (Configuration Element)

The first thing about this test is that the login request will be executed only the first time through. Subsequent iterations will skip it. This is due to the effects of the Once Only Controller.

After the login, the next Sampler loads the search page (imagine a web application where the user logs in, and then goes to a search page to do a search). This is just a simple request, not filtered through any Logic Controller.

After loading the search page, we want to do a search. Actually, we want to do two different searches. However, we want to re-load the search page itself between each search. We could do this by having 4 simple HTTP request elements (load search, search "A", load search, search "B"). Instead, we use the Interleave Controller which passes on one child request each time through the test. It keeps the ordering (i.e. it doesn't pass one on at random, but "remembers" its place) of its child elements. Interleaving 2 child requests may be overkill, but there could easily have been 8, or 20 child requests.

Note the HTTP Request Defaults that belongs to the Interleave Controller. Imagine that "Search A" and "Search B" share the same PATH info (an HTTP request specification includes domain, port, method, protocol, path, and arguments, plus other optional items). This makes sense - both are search requests, hitting the same back-end search engine (a servlet or cgi-script, let's say). Rather than configure both HTTP Samplers with the same information in their PATH field, we can abstract that information out to a single Configuration Element. When the Interleave Controller "passes on" requests from "Search A" or "Search B", it will fill in the blanks with values from the HTTP default request Configuration Element. So, we leave the PATH field blank for those requests, and put that information into the Configuration Element. In this case, this is a minor benefit at best, but it demonstrates the feature.

The next element in the tree is another HTTP default request, this time added to the Thread Group itself. The Thread Group has a built-in Logic Controller, and thus, it uses this Configuration Element exactly as described above. It fills in the blanks of any Request that passes through. It is extremely useful in web testing to leave the DOMAIN field blank in all your HTTP Sampler elements, and instead, put that information into an HTTP default request element, added to the Thread Group. By doing so, you can test your application on a different server simply by changing one field in your Test Plan. Otherwise, you'd have to edit each and every Sampler.

The last element is a HTTP Cookie Manager. A Cookie Manager should be added to all web tests - otherwise JMeter will ignore cookies. By adding it at the Thread Group level, we ensure that all HTTP requests will share the same cookies.

Logic Controllers can be combined to achieve various results. See the list of built-in Logic Controllers.

总结

  1. JMeter有两种类型的控制器:采样器和逻辑控制器。
  2. 采样器:告诉JMeter向服务器发送请求并等待响应,按它们在测试树中的顺序处理。
  3. 常见的采样器:包括FTP请求、HTTP请求、JDBC请求、Java对象请求、JMS请求、JUnit测试请求、LDAP请求、邮件请求、操作系统进程请求和TCP请求。
  4. 配置元素:可以通过添加一个或多个配置元素来自定义采样器。
  5. 默认配置元素:如果要向同一服务器发送多个相同类型的请求,考虑使用默认配置元素。
  6. 监听器:添加到测试计划中以查看和/或将请求结果存储到磁盘。
  7. 断言:可以在响应中执行基本验证,例如检查特定HTML标签或常见错误字符串。
  8. 逻辑控制器:让你可以自定义JMeter用来决定何时发送请求的逻辑,改变请求的顺序、修改请求、重复请求等。
  9. Once Only Controller:只在第一次迭代时执行其子请求。
  10. Interleave Controller:在其子请求之间交替,每次通过测试时传递一个子请求。
  11. HTTP Request Defaults:可以将共享的HTTP请求信息抽象到一个配置元素中,以减少重复配置。
  12. Cookie Manager:应添加到所有Web测试中,否则JMeter将忽略cookies。
  13. 组合逻辑控制器:可以结合使用来实现各种结果。


http://www.kler.cn/a/468515.html

相关文章:

  • 实际开发中,常见pdf|word|excel等文件的预览和下载
  • qt鼠标右键菜单
  • 【NLP高频面题 - 分布式训练篇】ZeRO主要为了解决什么问题?
  • 安卓漏洞学习(十七):维京海盗-Strandhogg漏洞
  • 数据挖掘——概论
  • 如何在 Spring Cloud Gateway 中创建全局过滤器、局部过滤器和自定义条件过滤器
  • Go Ebiten小球弹性碰撞代码示例
  • 使用Dinky快速提交Flink operator任务
  • 【zig】0.zig的下载安装
  • 【Python基础语法】
  • Leecode刷题C语言之设计一个ATM机器
  • Gitee上传项目代码教程(详细)
  • MySQL中表之间关联不同方式操作详解
  • Spring Boot 的自动配置,以rabbitmq为例,请详细说明
  • 凸包(convex hull)简述
  • 全国青少年信息学奥林匹克竞赛(信奥赛)备考实战之循环结构(while循环语句)
  • 20241231在Ubuntu20.04.5系统中下载安装Android Studio 2024.2.1.12
  • Kafka 消费者专题
  • 如何通过本地部署的DIFY辅助学习算法(PS可以辅助帮你学习任何想学习的资料)
  • 探索WebAssembly:前端与后端的新未来
  • unity学习6:unity的3D项目的基本界面和菜单
  • MCP(Model Context Protocol)模型上下文协议 进阶篇3 - 传输
  • 互动为王:开源AI智能名片链动2+1模式商城小程序在社群运营中的深度应用与价值探索
  • 解锁AI Agent潜能:智能时代的信息处理利器2(18/30)
  • ES-深度分页问题
  • LeetCode题练习与总结:随机翻转矩阵--519