在 Gatling 中使用包含 JSON 的 .tsv 文件作为数据馈送文件时出现问题
Problems with using a .tsv file that contains JSON as a data feed file in Gatling
我正在使用 Gatling 对 RESTful API 进行压力测试。我会将 JSON 的数据发布到特定的 URI。我想使用一个 .tsv 文件,其中每一行都是一个特定的 JSON 元素。但是,我遇到了错误,而且我似乎无法找到一种模式或系统来将“”添加到我的 .tsv JSON 中,以便提要能够正常工作。附件是我的代码和 tsv 文件。
package philSim
import io.gatling.core.Predef._
import io.gatling.http.Predef._
import scala.concurrent.duration._
class eventAPISimulation extends Simulation {
object Query {
val feeder = tsv("inputJSON.tsv").circular
val query = forever {
feed(feeder)
.exec(
http("event")
.post("my/URI/here")
.body(StringBody("${json}")).asJSON
)
}
}
val httpConf = http.baseURL("my.url.here:portnumber")
val scn = scenario("event").exec(Query.query)
setUp(scn.inject(rampUsers(100) over (30 seconds)))
.throttle(reachRps(2000) in (30 seconds), holdFor(3 minutes))
.protocols(httpConf)
}
这是我未经编辑的 .tsv 示例 JSON:
json
{"userId":"234342234","secondaryIdType":"mobileProfileId","secondaryIdValue":"66666638","eventType":"push","eventTime":"2015-01-23T23:20:50.123Z","platform":"iPhoneApp","notificationId":"123456","pushType":1,"action":"sent","eventData":{}}
{"userId":"234342234","secondaryIdType":"mobileProfileId","secondaryIdValue":"66666638","eventType":"INVALID","eventTime":"2015-01-23T23:25:20.342Z","platform":"iPhoneApp","notificationId":"123456","pushType":1,"action":"received","eventData":{"osVersion":"7.1.2","productVersion":"5.9.2"}}
{"userId":"234342234","secondaryIdType":"mobileProfileId","secondaryIdValue":"66666638","eventType":"push","eventTime":"2015-01-23T23:27:30.342Z","platform":"iPhoneApp","notificationId":"123456","pushType":1,"action":"followedLink","eventData":{"deepLinkUrl":"URL.IS.HERE","osVersion":"7.1.2","productVersion":"5.9.2"}}
{"userId":"234342234","secondaryIdType":"mobileProfileId","secondaryIdValue":"66666638","eventType":"push","eventTime":"2015-01-23T23:27:30.342Z","platform":"AndroidApp","notificationId":"123456","pushType":1,"action":"followedLink","eventData":{"deepLinkUrl":"URL.IS.HERE"}}
{"userId":"234342234","secondaryIdType":"mobileProfileId","secondaryIdValue":"66666638","eventType":"push","eventTime":"2015-01-23T23:25:20.342Z","platform":"iPhoneApp","notificationId":"123456","pushType":1,"action":"error","eventData":{}}
我看到 this blog post 谈到操纵引号 (") 使作者的 JSON 与 .tsv 一起工作,但作者没有提供系统如何。我已经试过了各种各样的事情,我所做的一切都没有真正起作用。一些 JSON 将使用类似于论文作者所做的引号换行。但是,这并不适用于所有情况。处理 [ 的最佳实践是什么=21=] 和加特林机?感谢您的帮助!
直接来自 Gatling's documentation:使用 rawSplit
以便 Gatling 的 TSV 解析器能够处理您的 JSON 条目:
tsv("inputJSON.tsv", rawSplit = true).circular
我正在使用 Gatling 对 RESTful API 进行压力测试。我会将 JSON 的数据发布到特定的 URI。我想使用一个 .tsv 文件,其中每一行都是一个特定的 JSON 元素。但是,我遇到了错误,而且我似乎无法找到一种模式或系统来将“”添加到我的 .tsv JSON 中,以便提要能够正常工作。附件是我的代码和 tsv 文件。
package philSim
import io.gatling.core.Predef._
import io.gatling.http.Predef._
import scala.concurrent.duration._
class eventAPISimulation extends Simulation {
object Query {
val feeder = tsv("inputJSON.tsv").circular
val query = forever {
feed(feeder)
.exec(
http("event")
.post("my/URI/here")
.body(StringBody("${json}")).asJSON
)
}
}
val httpConf = http.baseURL("my.url.here:portnumber")
val scn = scenario("event").exec(Query.query)
setUp(scn.inject(rampUsers(100) over (30 seconds)))
.throttle(reachRps(2000) in (30 seconds), holdFor(3 minutes))
.protocols(httpConf)
}
这是我未经编辑的 .tsv 示例 JSON:
json
{"userId":"234342234","secondaryIdType":"mobileProfileId","secondaryIdValue":"66666638","eventType":"push","eventTime":"2015-01-23T23:20:50.123Z","platform":"iPhoneApp","notificationId":"123456","pushType":1,"action":"sent","eventData":{}}
{"userId":"234342234","secondaryIdType":"mobileProfileId","secondaryIdValue":"66666638","eventType":"INVALID","eventTime":"2015-01-23T23:25:20.342Z","platform":"iPhoneApp","notificationId":"123456","pushType":1,"action":"received","eventData":{"osVersion":"7.1.2","productVersion":"5.9.2"}}
{"userId":"234342234","secondaryIdType":"mobileProfileId","secondaryIdValue":"66666638","eventType":"push","eventTime":"2015-01-23T23:27:30.342Z","platform":"iPhoneApp","notificationId":"123456","pushType":1,"action":"followedLink","eventData":{"deepLinkUrl":"URL.IS.HERE","osVersion":"7.1.2","productVersion":"5.9.2"}}
{"userId":"234342234","secondaryIdType":"mobileProfileId","secondaryIdValue":"66666638","eventType":"push","eventTime":"2015-01-23T23:27:30.342Z","platform":"AndroidApp","notificationId":"123456","pushType":1,"action":"followedLink","eventData":{"deepLinkUrl":"URL.IS.HERE"}}
{"userId":"234342234","secondaryIdType":"mobileProfileId","secondaryIdValue":"66666638","eventType":"push","eventTime":"2015-01-23T23:25:20.342Z","platform":"iPhoneApp","notificationId":"123456","pushType":1,"action":"error","eventData":{}}
我看到 this blog post 谈到操纵引号 (") 使作者的 JSON 与 .tsv 一起工作,但作者没有提供系统如何。我已经试过了各种各样的事情,我所做的一切都没有真正起作用。一些 JSON 将使用类似于论文作者所做的引号换行。但是,这并不适用于所有情况。处理 [ 的最佳实践是什么=21=] 和加特林机?感谢您的帮助!
直接来自 Gatling's documentation:使用 rawSplit
以便 Gatling 的 TSV 解析器能够处理您的 JSON 条目:
tsv("inputJSON.tsv", rawSplit = true).circular