java Apache JMeter:在请求体中添加随机数据
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/44800557/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Apache JMeter : Add random data in body for request
提问by We are Borg
I'm working on stress testing our application in Apache JMeter.
我正在 Apache JMeter 中对我们的应用程序进行压力测试。
I thought of calling register user method which will add users in the database. But if the email already exists, then the database action does not take place.
我想到了调用 register user 方法将用户添加到数据库中。但如果电子邮件已经存在,则不会发生数据库操作。
How can I add a random number in body data? Or is there some other way I can stress test my application connected with database?
如何在正文数据中添加随机数?或者有没有其他方法可以对与数据库连接的应用程序进行压力测试?
Controller code :
控制器代码:
@RequestMapping(value = "/person/add", method = RequestMethod.POST)
public String addPerson(@ModelAttribute("person") Person person, BindingResult bindingResult) {
System.out.println("Person add called"+person.getUsername());
person.setUsername(this.stripHTML(person.getUsername()));
int personId = this.personService.addPerson(person);
if (!(personId == 0)) {
Person person1 = this.personService.getPersonById(personId);
Collection<GrantedAuthority> authorities = new ArrayList<>();
authorities.add(new SimpleGrantedAuthority("ROLE_USER"));
Authentication authentication = new UsernamePasswordAuthenticationToken(person1, null, authorities);
SecurityContextHolder.getContext().setAuthentication(authentication);
return "redirect:/canvaslisting";
} else {
return "redirect:/";
}
}
采纳答案by user7294900
Use Random Variablewith variable name emailValue and send ${emailValue} in request
Use JDBC requestto your database to create random number or sequence and save in variable name emailValue
Use UUIDfunction to create uniqueId and send in email ${uniqueId}@gmail.com for example
回答by Dmitri T
Take a look at JMeter Functionslike:
看看JMeter 函数,例如:
- __Random()- which generates a random number in the given range
- __RandomString()- which generates a random string from the given input
- __threadNum()- which returns the current thread number
- __UUID()- which returns an unique GUID structure
- __time()- which returns current time stamp in different formats
- any combination of above
- __Random()- 在给定范围内生成一个随机数
- __RandomString()- 从给定的输入生成一个随机字符串
- __threadNum()- 返回当前线程号
- __UUID()- 返回唯一的 GUID 结构
- __time()- 以不同格式返回当前时间戳
- 以上任意组合
JMeter functions can be used anywhere in the test so you can put them directly into your request body.
JMeter 函数可以在测试中的任何地方使用,因此您可以将它们直接放入您的请求正文中。
Some more recommendations:
还有一些建议:
- Don't use JMeter GUI for running the load test, GUI mode is designed for tests development and debugging only, the tests themselves need to be run in command-line non-GUI mode
- Remove all the listeners from the test plan while running your load test as JMeter listeners are very resource intensiveand create unnecessary overhead.
- 不要使用 JMeter GUI 来运行负载测试,GUI 模式仅用于测试开发和调试,测试本身需要在命令行非 GUI 模式下运行
- 在运行负载测试时从测试计划中删除所有侦听器,因为JMeter 侦听器非常占用资源并会产生不必要的开销。