我正在使用Apache JMeter针对我们开发的应用程序针对RESTFUL API运行一些性能测试。我有一个终点" api / create / empListJob",它基本上在MongoDB中添加了一个或多个员工记录。 POST调用的有效负载如下所示:
{
"employeeList": [
{
"first_name": "josh",
"last_name": "don",
"age": "25",
"address": {
"street1": "xyz",
"street2": "apt-10",
"city" : "def",
"state" : "CA",
"zip" : "95055"
},
"deptType": {
"deptID": "1",
"deptName": "R&D"
}
},
{
"first_name": "mary",
"last_name": "jane",
"age": "22",
"address": {
"street1": "zzz",
"street2": "apt-15",
"city" : "yyy",
"state" : "CA",
"zip" : "95054"
},
"deptType": {
"deptID": "2",
"deptName": "HR"
}
}
]
}
如您所见,有效负载采用员工数据列表,并且应该至少有一个员工记录。我有一个要求,我希望JMeter线程组有10个线程,这些线程中的每一个都应该对" api / create / empListJob"进行并发POST。这样,机构有10个独特的员工记录,从而共创造100条记录。我可以参数化有效载荷的最佳方法是什么?
答案 0 :(得分:1)
查看JMeter Functions,例如:
因此,例如,如果您将JSON有效负载更改为:
"employeeList": [
{
"first_name": "josh-${__threadNum}",
"last_name": "don-${__threadNum}",
"age": "25",
"address": {
"street1": "xyz",
"street2": "apt-10",
"city" : "def",
"state" : "CA",
"zip" : "95055"
},
"deptType": {
"deptID": "1",
"deptName": "R&D"
}
},
{
"first_name": "mary-${__threadNum}",
"last_name": "jane-${__threadNum}",
"age": "22",
"address": {
"street1": "zzz",
"street2": "apt-15",
"city" : "yyy",
"state" : "CA",
"zip" : "95054"
},
"deptType": {
"deptID": "2",
"deptName": "HR"
}
}
]
}
JMeter将创建:
- `josh-1` for 1st virtual user
- `josh-2` for 2nd virtual usre
- etc.
请参阅Apache JMeter Functions - An Introduction以熟悉JMeter功能概念。