TypechoJoeTheme

Misty rain的博客

统计

Jmeter性能测试-进阶篇(中)

2021-12-24
/
82 评论
/
1,516 阅读
/
正在检测是否收录...
12/24

进阶篇中:本章主要讲jmeter连接数据库,直接从数据库取值作为参数

下章预定:开始接口性能测试!

环境:mysql数据库5.7
在数据库中新建表student:
字段:id、name、phone,并添加三条数据。
1 张三 17878181818
2 李四 17878181819
3 小白 17878181820

下载mysql-connector-java-8.0.11.jar文件
网址:https://dev.mysql.com/downloads/file/?id=477058
解压下载的文件,找到里面的jar即可。

在jmeter项目中添加jar
点击项目-Browse


在线程组中添加JDBC Connection Configuration
点击线程组-->Add-->Config Element -->JDBC Connection Configuration,更改名称:连接数据库


创建jdbc request
点击线程组-->Add-->Sampler-->jdbc request,更改名称:数据库请求-获取学生信息
本环节需要使用mysql语句。


点击‘运行’,发现连接数据库报错

Cannot create PoolableConnectionFactory (Communications link failure

The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.)

我们打开‘连接数据库’将databaseurl改成:
jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf8&serverTimezone=UTC&useSSL=false
再次运行即可。
一般情况下,我们只需要查询一次数据库获取参数即可,这时,我们新建一个:仅一次控制器
Add-->Logic Controller-->Once only Controller,更改名称:仅一次控制器
将数据库请求放进控制器里面;
这时我们将线程组调为2,发现该请求只运行了一次(同时,还有各种各样的控制器,看个人业务需要再做指定调整)。

将数据库查询出来的数据作为参数
我们打开‘数据库请求-获取学生信息’;
将Variable names:name,phone(,分割字段)
同时语句保持不变,必须是查询指定的参数。
为‘数据库请求-获取学生信息’添加:Add-->Post Processors-->Debug PostProcessor,更改名称:调试结果集
运行接口:


现在,怎么把这些值取出来呢???

1、假设只要一个值,那么直接取就好了,比如:${name_1},${phone_1}就好了

2、如果要批量取值怎么办???依次取出来
这时,我们就需要我们的计时器来完成了,计时器:可以模拟从1-3的值所以我们新增一个计时器(计时器的用法前面已经交过大家了)新建一个:数据库查询值计时器


3、现在就是参数与参数的嵌套了,${name_#},这个#我们如何替换成我们的sqlcounter参数呢:
这里我们使用函数对话框:
${__V(name_${sqlcounter},)}
调整‘新增学生’的请求参数:
{

"name":"${__V(name_${sqlcounter},)}",
"grade":"三班",
"phone":"1511111${__Random(1000,9999,)}"

}

注意:这里的‘新增学生’接口必须放在‘数据库请求-获取学生信息’的下面(第一顺位,如果放在‘获取学生列表’的请求下就无效,需要用参数接才能生效)。

如何循环添加
到这里我们数据库有3条数据的,上面我们通过计时器只获取了一条数据,那如果我们要添加3条数据呢?
这里我们引用:循环控制器


这样我们就实现了循环添加。

由于篇幅原因,数据库篇就到这里了,后续如果有新的操作和问题,会在其他篇进行解释和记录。

性能jmeter
朗读
赞(6)
版权属于:

Misty rain的博客

本文链接:

http://101.42.223.25/index.php/archives/96/(转载时请注明本文出处及文章链接)

评论 (82)
  1. 1 作者
    Windows 10 · Google Chrome

    1

    2022-04-28 回复
  2. 1 作者
    Windows 10 · Google Chrome

    1

    2022-04-28 回复
  3. 1 作者
    Windows 10 · Google Chrome

    1

    2022-04-28 回复
  4. 1 作者
    Windows 10 · Google Chrome

    1BHlZt9IXGO

    2022-04-28 回复
  5. 1 作者
    Windows 10 · Google Chrome

    -1)) OR 894=(SELECT 894 FROM PG_SLEEP(15))--

    2022-04-28 回复
  6. 1 作者
    Windows 10 · Google Chrome

    1

    2022-04-28 回复
  7. 1 作者
    Windows 10 · Google Chrome

    1'"()&%

    EC4h(9114)

    2022-04-28 回复
  8. 1 作者
    Windows 10 · Google Chrome

    1'"()&%

    ZLwR(9739)

    2022-04-28 回复
  9. 1 作者
    Windows 10 · Google Chrome

    1'"()&%

    105n(9538)

    2022-04-28 回复
  10. 1 作者
    Windows 10 · Google Chrome

    1'"()&%

    n28u(9001)

    2022-04-28 回复
  11. 1 作者
    Windows 10 · Google Chrome

    1'"()&%

    moDz(9354)

    2022-04-28 回复
  12. 1 作者
    Windows 10 · Google Chrome

    1'"()&%

    oEWf(9289)

    2022-04-28 回复
  13. 1 作者
    Windows 10 · Google Chrome

    1

    2022-04-28 回复
  14. 1 作者
    Windows 10 · Google Chrome

    1

    2022-04-28 回复
  15. 1 作者
    Windows 10 · Google Chrome

    1

    2022-04-28 回复
  16. 1 作者
    Windows 10 · Google Chrome

    1

    2022-04-28 回复
  17. 1 作者
    Windows 10 · Google Chrome

    1

    2022-04-28 回复
  18. 1 作者
    Windows 10 · Google Chrome

    1

    2022-04-28 回复
  19. 1 作者
    Windows 10 · Google Chrome

    1

    2022-04-28 回复
  20. 1 作者
    Windows 10 · Google Chrome

    1

    2022-04-28 回复
  21. 1 作者
    Windows 10 · Google Chrome

    1'"()&%

    IfsX(9887)

    2022-04-28 回复
  22. 1 作者
    Windows 10 · Google Chrome

    1'"()&%

    ppj0(9137)

    2022-04-28 回复
  23. 1 作者
    Windows 10 · Google Chrome

    '"()&%

    ppj0(9861)

    2022-04-28 回复
  24. 1 作者
    Windows 10 · Google Chrome

    1'"()&%

    Kkbw(9944)

    2022-04-28 回复
  25. 1 作者
    Windows 10 · Google Chrome

    1

    2022-04-28 回复
  26. 1 作者
    Windows 10 · Google Chrome

    1

    2022-04-28 回复
  27. 1 作者
    Windows 10 · Google Chrome

    1

    2022-04-28 回复
  28. 1 作者
    Windows 10 · Google Chrome

    1

    2022-04-28 回复
  29. 1 作者
    Windows 10 · Google Chrome

    1

    2022-04-28 回复
  30. 1 作者
    Windows 10 · Google Chrome

    1

    2022-04-28 回复
  31. 1 作者
    Windows 10 · Google Chrome

    1

    2022-04-28 回复
  32. 1 作者
    Windows 10 · Google Chrome

    1

    2022-04-28 回复
  33. 1 作者
    Windows 10 · Google Chrome

    1

    2022-04-28 回复
  34. 1 作者
    Windows 10 · Google Chrome

    1

    2022-04-28 回复
  35. 1 作者
    Windows 10 · Google Chrome

    1

    2022-04-28 回复
  36. 1 作者
    Windows 10 · Google Chrome

    1'"()&%

    WimE(9964)

    2022-04-28 回复
  37. 1 作者
    Windows 10 · Google Chrome

    1

    2022-04-28 回复
  38. 1 作者
    Windows 10 · Google Chrome

    1

    2022-04-28 回复
  39. 1 作者
    Windows 10 · Google Chrome

    1

    2022-04-28 回复
  40. 1 作者
    Windows 10 · Google Chrome

    1

    2022-04-28 回复
  41. 1 作者
    Windows 10 · Google Chrome

    1

    2022-04-28 回复
  42. 1 作者
    Windows 10 · Google Chrome

    1

    2022-04-28 回复
  43. 1 作者
    Windows 10 · Google Chrome

    1

    2022-04-28 回复
  44. 1 作者
    Windows 10 · Google Chrome

    1

    2022-04-28 回复
  45. 1 作者
    Windows 10 · Google Chrome

    1

    2022-04-28 回复
  46. 1 作者
    Windows 10 · Google Chrome

    1

    2022-04-28 回复
  47. 1 作者
    Windows 10 · Google Chrome

    1

    2022-04-28 回复
  48. 1 作者
    Windows 10 · Google Chrome

    1

    2022-04-28 回复
  49. 1 作者
    Windows 10 · Google Chrome

    1

    2022-04-28 回复
  50. 1 作者
    Windows 10 · Google Chrome

    1

    2022-04-28 回复
  51. 1 作者
    Windows 10 · Google Chrome

    1

    2022-04-28 回复
  52. 1 作者
    Windows 10 · Google Chrome

    1

    2022-04-28 回复
  53. 1 作者
    Windows 10 · Google Chrome

    1

    2022-04-28 回复
  54. 1 作者
    Windows 10 · Google Chrome

    1'"()&%

    wKe9(9720)

    2022-04-28 回复
  55. 1 作者
    Windows 10 · Google Chrome

    1'"()&%

    02Sg(9861)

    2022-04-28 回复
  56. 1 作者
    Windows 10 · Google Chrome

    1'"()&%

    OJzP(9415)

    2022-04-28 回复
  57. 1 作者
    Windows 10 · Google Chrome

    '"()&%

    OJzP(9645)

    2022-04-28 回复
  58. 1 作者
    Windows 10 · Google Chrome

    555

    2022-04-28 回复
  59. 1 作者
    Windows 10 · Google Chrome

    1

    2022-04-28 回复
  60. 1 作者
    Windows 10 · Google Chrome

    1

    2022-04-28 回复
  61. 1 作者
    Windows 10 · Google Chrome

    1

    2022-04-28 回复
  62. 1 作者
    Windows 10 · Google Chrome

    1

    2022-04-28 回复
  63. the 作者
    Windows 10 · Google Chrome

    response.write(9082558*9625469)

    2022-04-28 回复
  64. the 作者
    Windows 10 · Google Chrome

    '+response.write(9082558*9625469)+'

    2022-04-28 回复
  65. the 作者
    Windows 10 · Google Chrome

    "+response.write(9082558*9625469)+"

    2022-04-28 回复
  66. the 作者
    Windows 10 · Google Chrome

    555

    2022-04-28 回复
  67. the 作者
    Windows 10 · Google Chrome

    555

    2022-04-28 回复
  68. the 作者
    Windows 10 · Google Chrome

    echo uwerlj$()\ woazeh\nz^xyu||a #' &echo uwerlj$()\ woazeh\nz^xyu||a #|" &echo uwerlj$()\ woazeh\nz^xyu||a #

    2022-04-28 回复
  69. the 作者
    Windows 10 · Google Chrome

    555

    2022-04-28 回复
  70. the 作者
    Windows 10 · Google Chrome

    555

    2022-04-28 回复
  71. the 作者
    Windows 10 · Google Chrome

    &echo wrmemc$()\ tzknmr\nz^xyu||a #' &echo wrmemc$()\ tzknmr\nz^xyu||a #|" &echo wrmemc$()\ tzknmr\nz^xyu||a #

    2022-04-28 回复
  72. the 作者
    Windows 10 · Google Chrome

    555

    2022-04-28 回复
  73. 1 作者
    Windows 10 · Google Chrome

    555

    2022-04-28 回复
  74. 1 作者
    Windows 10 · Google Chrome

    1

    2022-04-28 回复
  75. 1 作者
    Windows 10 · Google Chrome

    1

    2022-04-28 回复
  76. 1 作者
    Windows 10 · Google Chrome

    555

    2022-04-28 回复
  77. the 作者
    Windows 10 · Google Chrome

    555

    2022-04-28 回复
  78. 1 作者
    Windows 10 · Google Chrome

    1'"()&%

    3igN(9038)

    2022-04-28 回复
  79. 1 作者
    Windows 10 · Google Chrome

    1'"()&%

    d1bj(9892)

    2022-04-29 回复
  80. evabbeque 作者
    Windows 10 · Google Chrome

    RA and or LA appendages were obtained from 43 patients with sinus rhythm SR, 22 patients with pAF, and 30 patients with cAF undergoing open heart surgery for either coronary artery bypass grafting and or valve replacement Table, but matched samples of RA and LA appendages were obtained from only 2 SR and 2 cAF patients buy cialis online cheap b N 67 69; all Gemzar plus cisplatin patients with laboratory or non laboratory data

    2024-01-07 回复
  81. Fawbapy 作者
    Windows 10 · Google Chrome

    00591 3630 Hydromorphone Hydrochloride Actavis Pharma, Inc daily cialis online Deandre ZYJLULgztysoJuMa 6 27 2022

    2024-07-24 回复
  82. priligy and viagra combination 作者
    Linux · FireFox

    Hello there, I discovered your web site by the use of Google whilst searching for a similar matter,
    your web site came up, it appears to be like great. I have bookmarked it in my google bookmarks.

    Hi there, simply turned into alert to your weblog via Google, and located that it's truly
    informative. I am gonna watch out for brussels.
    I will be grateful in the event you proceed this in future.
    Numerous other people will probably be benefited from your writing.

    Cheers!

    2024-09-20 回复

备案号: 浙ICP备2021040483号