Scala/Gatling 来说相当陌生,我已经搜索了很多 SO,但没有针对我的问题得到任何回答。所以这是我的代码
val adminUplFile: ScenarioBuilder = scenario("Admin user uploads file")
.exec(http("Upload File")
.post("/file")
.header("username", "example") r
.header("password", "80HL/d1fETqxuCArAbIU6/Sb3F2nSTCqw/eqw1lzJio=")
.formUpload("file", "uploadFile") // body params ("key" , "path of the file/name")
.formParamSeq(Seq(("uploadByID", "1"), ("location", "meetings"), ("personID", "0"), ("uploadTimeStamp", "2019-01-15 10:01:04.426"), ("md5Hash", "n95QI48+Uqxfw0hTnJdqMA==")))
.check(status.is(200))
.check(jsonPath("$.uuid").saveAs("guidList")))
.exec { session =>
val writer = new PrintWriter(new FileOutputStream(new File("src/gatling/resources/extractedData/GuidList.json"), true))
writer.write(session(""guidList"").as[String].trim)
writer.write("n")
writer.close()
session }
setUp(
adminUplFile.inject(constantUsersPerSec(2) during (1 seconds)).protocols(httpConf)
)
这是我试图提取的响应:
{
"uuid": "3a917e22-3c76-45de-a104-4e2aa4b72a35"
}
所以我被写入文件是:
"3a917e22-3c76-45de-a104-4e2aa4b72a35"
"929c89c0-7a1a-4a18-8ee8-2958c9cd430f"
我想要的是:
[
"3a917e22-3c76-45de-a104-4e2aa4b72a35" ,
"929c89c0-7a1a-4a18-8ee8-2958c9cd430f"
]
只是看着它,它看起来像一个简单的案例,在文件中添加方括号和逗号,但实际上,每个虚拟用户都试图附加同一个文件,我正在努力如何使其格式化方括号不会再次使用并且只使用一次。
所以我不想要:
["3a917e22-3c76-45de-a104-4e2aa4b72a35"],
["929c89c0-7a1a-4a18-8ee8-2958c9cd430f"]
基本上用before after
加特林的钩子和一些版作家的魔法
这是我的代码:
try {
val br = new BufferedReader(new FileReader(deleteGuidsFilePath))
var last : String = ""
var line = br.readLine
while ({line != null})
{
last = line
line = br.readLine
}
br.close()
afterPw.write(last.replace(",", "]"))
afterPw.close()
}
catch {
case e: Throwable => println("Couldn't read the file")
}