0
如何根據JSON文件編寫自定義Gatling進紙器,該JSON文件具有某些殘存值且需要在發送前需要替換的值?例如從帶有殘值的JSON編寫Gatling自定義進紙器
{"payloads":[
{"groupId":"<GUID>", "epoch":<TIME>, "report":"somethingInteresting1"},
{"groupId":"<GUID>", "epoch":<TIME>, "report":"somethingInteresting2"},
{"groupId":"<GUID>", "epoch":<TIME>, "report":"somethingInteresting3"}
]}
jsonFile("/opt/gatling/user-files/simulation/cannedPayloads.json")
將無法正常工作,我認爲,因爲它不是真正有效的JSON的文件中。我已經試過:
val jsonFileContents = Source.fromFile("/opt/gatling/user-files/simulation/cannedPayloads.json").getLines.mkString
.replaceAll("<GUID>", java.util.UUID.randomUUID().toString())
.replaceAll("<TIME>", Instant.now().toEpochMilli().toString())
val feeder = JsonPath.query("$.payloads[*]", jsonFileContents).right.get.toArray.circular
val scn1 = scenario("CannedTestSimulation").exec(feed(feeder).exec(
http("to ingestion").post(url).body(StringBody("$")).asJSON
)