json - 在 Ga特林 中使用包含 JSON 作为数据源文件的 .tsv 文件时出现问题

标签 json scala csv gatling

我正在使用 Gadling 对 RESTful API 进行压力测试。我将把 JSON 数据发布到特定的 URI。我想使用 .tsv 格式的 feed 文件,其中每一行都是一个特定的 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 将使用引号换行,类似于本文作者的做法。但是,这并不适用于所有情况。处理 JSON 和加特林的最佳实践是什么?感谢您的帮助!

最佳答案

直接来自Gatling's documentation :使用 rawSplit 以便 Gattle 的 TSV 解析器能够处理您的 JSON 条目:

tsv("inputJSON.tsv", rawSplit = true).circular

关于json - 在 Ga特林 中使用包含 JSON 作为数据源文件的 .tsv 文件时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29267069/

相关文章:

json - 带 [ ] 的 getJSON 不起作用

scala - 如何将 Map[A,Future[B]] 转换为 Future[Map[A,B]]?

csv - 如何制作与 `cut` 一样高效的 TSV 处理 golang 程序?

scala 迭代匹配,奇怪的编译器错误

scala - 如何将句子拆分为多个空格分隔的单词?

ruby-on-rails - ActiveAdmin,CSV 导入,将编码更改为 cp1251

python - 为什么一个简单的 CSV 清理 python 脚本可以工作,而另一个却不能?

json - 如何使用 Decodable 协议(protocol)为这个 JSON 制作结构?

javascript - 将大型 json 发送到服务器的最佳模式是什么

android - 如何在android中获取json数组值?