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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-03 08:21:40  来源:igfitidea点击:

Apache JMeter : Add random data in body for request

javarandomjmeterstress-testing

提问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?

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

Here are some screenshots : enter image description hereenter image description here

以下是一些屏幕截图: 在此处输入图片说明在此处输入图片说明

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

  1. Use Random Variablewith variable name emailValue and send ${emailValue} in request

  2. Use JDBC requestto your database to create random number or sequence and save in variable name emailValue

  3. Use UUIDfunction to create uniqueId and send in email ${uniqueId}@gmail.com for example

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

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

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

回答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

JMeter functions can be used anywhere in the test so you can put them directly into your request body.

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

Some more recommendations:

还有一些建议:

回答by vanduc1102

My example with __UUID

我的__UUID示例

enter image description here

在此处输入图片说明

For POST request, make sure you have correct Content-Typein HTTP Header Manger, application/jsonfor example.

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