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

We *_*org 11 java random jmeter stress-testing

我正在 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:/";
    }
}
Run Code Online (Sandbox Code Playgroud)

Dmi*_*i T 9

看看JMeter 函数,例如:

JMeter 函数可以在测试中的任何地方使用,因此您可以将它们直接放入请求正文中。

还有一些建议:


use*_*900 7

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

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

  3. 使用UUID函数创建 uniqueId 并发送电子邮件 ${uniqueId}@gmail.com 例如


van*_*102 5

我的__UUID示例

在此处输入图片说明

对于POST请求,请确保您有正确的内容类型HTTP标头管理器应用程序/ JSON的例子。