【问题标题】:Apache JMeter : Add random data in body for requestApache JMeter:在请求正文中添加随机数据
【发布时间】:2017-12-01 16:54:09
【问题描述】:

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

我想调用注册用户方法来在数据库中添加用户。但如果电子邮件已经存在,则不会发生数据库操作。

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

以下是一些截图:

控制器代码:

@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:/";
    }
}

【问题讨论】:

    标签: java random jmeter stress-testing


    【解决方案1】:
    1. 使用带有变量名 emailValue 的 Random Variable 并在请求中发送 ${emailValue}

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

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

    【讨论】:

    • 当你的 UUID 计算出来时,我会使用它。并为当前问题创建一个新问题。谢谢。
    【解决方案2】:

    看看JMeter Functionslike:

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

    更多建议:

    【讨论】:

    • 这非常有用,谢谢
    【解决方案3】:

    我的例子是__UUID

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-10-06
      • 2014-08-15
      • 2017-04-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多