JMeter-使用jar输出的URL进行负载测试 [英] JMeter - Use jar output for URL to load test
问题描述
我想使用JMeter测试Java服务.但是,我要测试的URL必须动态生成(时间戳,有效负载哈希等).我创建了一个可输出输出有效URL的自可执行jar.
I would like to use JMeter to test a Java service. However the URL I want to test has to be dynamically generated (timestamps, payload hash, etc). I created a self executable jar that outputs a valid URL.
java -jar file.jar
http://www.example.com/api?params=...
URL每次迭代都会更改.有没有一种方法可以配置JMeter来运行Jar以获取它发出的每个HTTP请求的URL?谢谢!
The URL changes each iteration. Is there a way I can configure JMeter to run the Jar to get the URL for each HTTP request it makes? Thanks!
推荐答案
您需要使用以下各项的组合:
You need to use combination of the following:
- OS Process Sampler (以产生实用程序JAR)
- 正则表达式提取器(获取生成的URL)
- OS Process Sampler (to spawn your utility JAR)
- Regular Expression Extractor (to get generated URL)
详细信息:
鉴于您的系统路径中有Java二进制文件,您需要执行以下操作:
Given you have java binary in your system path you need the following:
在线程组下添加一个OS Process Sampler
Under Thread Group add an OS Process Sampler
- 将Command设置为 java (要完全确保键入Java二进制文件的完整路径,即"d:\ apps \ java6 \ bin \ java.exe")
- 在命令参数下添加以下内容: -jar * your.jar *在单独的行中,最好还是使用完整路径到jar.
- 在与OS Process Sampler相同级别上添加View Results Tree侦听器
- Set Command to be java (to be completely sure type full path to your java binary, i.e. "d:\apps\java6\bin\java.exe")
- Under Command Parameters add following: -jar *your.jar* EACH ON SEPARATE LINE, again it's better to use full path to your jar.
- Add View Results Tree listener at the same level as OS Process Sampler
如果您运行Thead Group,则应看到以下内容:
If you run your Thead Group you should see the following:
系统调用完成. 过程输出: http://example.com/api?params= ....
System Call Complete. Process Output: http://example.com/api?params=....
我相信您对"params ="
I believe that you're interested in something, which comes after "params="
因此,要获取此值,请添加正则表达式提取器后处理器作为OS Process采样器的子代,并提供以下详细信息:
So get this value add a Regular Expression Extractor Post Processor as a child of OS Process sampler with following details:
- 引用名称-变量的任何有意义的名称,请将其设为"params"
- 正则表达式- http://www.example.com/(.*)
- 模板-$ 1 $
- Reference name - any meaningful name for variable, let it be "params"
- Regular Expression - http://www.example.com/(.*)
- Template - $1$
这将提取api?params = ...,因此您可以将其用作$ {params}
That will extract api?params=... so you'll be able to use it as path for your HTTP Request as ${params}
这篇关于JMeter-使用jar输出的URL进行负载测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!