How to iterate over a vector

1,031 views
Skip to first unread message

letstestthis

unread,
Aug 10, 2015, 1:32:50 PM8/10/15
to Gatling User Group
Hi there

I am trying to iterate over a vector with a foreach, but I get this error

14:14:31.797 [ERROR] i.g.c.s.LoopBlock$ - Condition evaluation crashed with message 'Can't cast value 463bd5f1-caee-47e0-beba-551e47c008d3 of type class java.lang.String into interface scala.collection.Seq', exiting loop

The code looks like this 

.exec(http("Get tickets")
.get("/tickets_updated?start=0")
.check(status.is(200))
.check(jsonPath("$.updated[*]").findAll.saveAs("updatedTickets")))

.foreach("${updatedTickets}","updatedTickets") {
exec(http("POST Tickets")
.post("/${eventId}/tickets")
.body(StringBody( """{"id":"${updatedTickets}"}""")).asJSON
.check(status.is(200)))
}

Updated tickets looks like this, I logged this out

updatedTickets -> Vector(463bd5f1-caee-47e0-beba-551e47c008d3, 7fecbdd6-865e-4244-84c6-e8b036474564, b3fe695a-0496-42e0-9117-f844bf904024,f61a66b1-fc23-4554-8619-d96282468833, b76725df-b7c3-4709-ab94-39eb5610b97f, 1e19963f-1ba2-4762-981f-b8b4a45a5f0b, 3b61da7c-98b4-431d-a511-d37567bcb451, 411272f5-4021-49e7-80b5-a697d08a090b, 1ccad1fd-81c2-4062-9d9c-803de8b12aef, e9233d64-9d50-448b-9b3c-d8b066f77a61)

How do I iterate through the vector in the POST tickets call? 

Thanks!

Pierre DAL-PRA

unread,
Aug 10, 2015, 1:37:19 PM8/10/15
to gat...@googlegroups.com
Hi, 

you're using the same name for both the list of tickets and the session variable that will hold each ticket, which means that as soon as one enter the foreach, the list is lost and has been overwritten.
Simply use a different name for the element and it'll work.

Cheers,

Pierre 
--
You received this message because you are subscribed to the Google Groups "Gatling User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gatling+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

letstestthis

unread,
Aug 10, 2015, 1:49:51 PM8/10/15
to Gatling User Group
Thank you so much, that was it! The error message sent me through to a very different path. 
Hi, 

To unsubscribe from this group and stop receiving emails from it, send an email to gatling+unsubscribe@googlegroups.com.

letstestthis

unread,
Aug 10, 2015, 5:37:01 PM8/10/15
to Gatling User Group
just to clarify, the error makes sense. Seems pretty obvious now that I see what was going on :-)
Reply all
Reply to author
Forward
0 new messages