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
)