Apache JMeter:在请求体中添加随机数据

19

我正在使用Apache JMeter进行我们应用程序的压力测试。

我考虑调用“register user”方法来向数据库中添加用户。但是,如果电子邮件已经存在,则不会进行数据库操作。

我该如何在正文数据中添加随机数字?还是有其他方法可以压力测试与数据库连接的应用程序?

以下是一些截图: 输入图片描述输入图片描述

控制器代码:

@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:/";
    }
}
3个回答

19
请看 JMeter Functions,例如: JMeter函数可在测试的任何地方使用,因此可以直接将它们放入请求正文中。
以下是一些更多建议:
  • 不要使用JMeter GUI来运行负载测试,GUI模式仅用于测试开发和调试,测试本身需要在命令行非GUI模式下运行。
  • 在运行负载测试时,请从测试计划中删除所有的监听器,因为JMeter监听器会消耗大量资源并产生不必要的开销。

这非常有用,谢谢。 - Gülsen Keskin

12
  1. 在请求中使用变量名为emailValue的随机变量并将${emailValue}发送

  2. 使用JDBC请求到您的数据库,创建随机数或序列,并保存在变量名为emailValue的变量中

  3. 使用UUID函数创建唯一标识(uniqueId),并通过电子邮件发送 ${uniqueId}@gmail.com 例如


根据您计算出的UUID,我将使用它,并为当前问题创建一个新的问题。谢谢。 - We are Borg

11

我的例子使用了__UUID

enter image description here

对于POST请求,请确保在HTTP Header Manger中拥有正确的Content-Type,例如application/json


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接