update a session variable in a foreach block.

54 views
Skip to first unread message

vignesh jeyaraj

unread,
Jan 12, 2018, 10:02:02 PM1/12/18
to Gatling User Group
I need to retrieve some values from a json response and build a subsequent request with the response. This needs to be unique for each virtual user. I try to retrieve the response and build a List of Json Objects. This works well with single user, but I am getting incorrect result of the session variable when I increase the number of users. Can someone help me understand what is wrong in this?

val GetJobsRequestToPublish = exec(
http("Get Job Request To Publish")
.get("/jobs/${MetajobId}")
.check(status.in(200 to 210), bodyString.saveAs("GetJobPublishResponse"),
jsonPath("$..product.styleColor").saveAs("styleColor"),
jsonPath("$.product.id").saveAs("productDBId"),
jsonPath("$.id").saveAs("PublishMetajobId"), jsonPath("$.tasks[0].id").saveAs("PublishMetataskId"),
jsonPath("$.assetJobs[*]").findAll.optional.saveAs("PublishAssetJobs")
))
.foreach("${PublishAssetJobs}", "assetJob") {
var assetJobPayloads = ListBuffer[JsObject]();
exec(session => {
val result:List[(String, String)] = for {
Some(M(map)) <- List(JSON.parseFull(session("assetJob").as[String]))
S(assetId) = map("id")
L(tasks) = map("tasks")
M(task) <- tasks
S(taskId) = task("id")
} yield {
(assetId, taskId)
}
val (assetId, taskId) = result.unzip
val assetJobPayload : JsObject = Json.obj(
"jobId" -> assetId.head,
"taskId" -> taskId.head,
"properties" -> Json.obj(
"reject" -> false
)
)
assetJobPayloads += assetJobPayload;
println("The Consolidated Asset Payload is " + assetJobPayloads)
session.set("assetJobPayloads", assetJobPayloads)
})}

Rytis Jazdauskas

unread,
Jan 31, 2018, 7:29:28 PM1/31/18
to Gatling User Group
how about you get your stuff using that call add .silent at the end this way the get won't show in the report and then have another exec to do what you need to do?
Reply all
Reply to author
Forward
0 new messages