Java ApacheJMeter:为请求在正文中添加随机数据

Java ApacheJMeter:为请求在正文中添加随机数据,java,random,jmeter,stress-testing,Java,Random,Jmeter,Stress Testing,我正在用ApacheJMeter对我们的应用程序进行压力测试 我想到调用register user方法,它将在数据库中添加用户。但是,如果电子邮件已经存在,则数据库操作不会发生 如何在主体数据中添加随机数?或者是否有其他方法可以对连接到数据库的应用程序进行压力测试 以下是一些屏幕截图: 控制器代码: @RequestMapping(value = "/person/add", method = RequestMethod.POST) public String addPerson(@Model

我正在用ApacheJMeter对我们的应用程序进行压力测试

我想到调用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:/";
    }
}
@RequestMapping(value=“/person/add”,method=RequestMethod.POST)
公共字符串addPerson(@modeldattribute(“person”)person,BindingResult BindingResult){
System.out.println(“名为“+Person.getUsername()”的人员添加);
person.setUsername(this.stripHTML(person.getUsername());
int personId=this.personService.addPerson(person);
如果(!(personId==0)){
Person person1=this.personService.getPersonById(personId);
收集权限=新建ArrayList();
添加(新的SimpleGrantedAuthority(“角色用户”);
AuthenticationAuthentication=新用户名PasswordAuthenticationToken(person1,null,authorities);
SecurityContextHolder.getContext().setAuthentication(身份验证);
返回“重定向:/canvaslinging”;
}否则{
返回“重定向:/”;
}
}
  • 与变量名emailValue一起使用,并在请求中发送${emailValue}

  • 用于数据库创建随机数或序列,并保存在变量名emailValue中

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

  • 看看下面的例子:

    • -生成给定范围内的随机数
    • -从给定输入生成随机字符串
    • -返回当前线程编号
    • -返回唯一的GUID结构
    • -以不同格式返回当前时间戳
    • 上述任何组合
    JMeter函数可以在测试中的任何地方使用,因此您可以将它们直接放入请求体中

    还有一些建议:

    • 不要使用JMeterGUI来运行负载测试,GUI模式仅用于测试开发和调试,测试本身需要运行
    • 在作为运行负载测试时,从测试计划中删除所有侦听器,并创建不必要的开销
    我的例子


    对于POST请求,请确保您在HTTP头管理器中有正确的内容类型,例如应用程序/json

    当您的UUID计算出来时,我将使用它。并为当前问题创建一个新问题。谢谢