Get value from a seq in session?

Hey Stéphane,

sorry to bother you again. i may need some tips to make this working.

i have two seq lists from previous regex check, list A, list B. then i use foreach to iterate list A, and use counter to identify the same index element in list B.
here is the code:

foreach("${ListA}",“A”,“counter”) {
exec(
http(“Get”)
.get("/")
.queryParam(""“A”"", “”"${A}""")
.queryParam(""“B”"", session => session(“ListB”)[session(“counter”).as[Int]])
.pause(0 milliseconds, Properties.requestSleep milliseconds)

but the compile didnt pass, 3 errors are all about the format of the brackets.

i checked in sessions that both lists are complete and correct.

Thanks!

With as:

.queryParam(""“B”"", session => {
val listB = session(“ListB”).as[Seq[String]]
val counter = session(“counter”).as[Int]
listB(counter)
})

With validate (safer):

.queryParam(""“B”"", session =>
for {
listB ← session(“ListB”).validate[Seq[String]]
counter ← session(“counter”).validate[Int]
} yield listB(counter)
)

Works perfectly in gatling 2, thanks a lot!!

在 2014年1月28日星期二UTC-8上午12时50分48秒,Stéphane Landelle写道:

is is possible to re-use listB in next exec? for example, i dont want use counter anymore, but a random value.

.queryParam(""“weight”"", session => {
val listB = session(“ListB”).as[Seq[String]]
val random = getRand(listB.size)
listB(random)
})

in next exec, i want to re-use the random value and listB if possible, how can i do this? compilation said value listB, random not found.

在 2014年1月28日星期二UTC-8上午12时50分48秒,Stéphane Landelle写道:

i think i can use session set attribute to set the random.

在 2014年1月28日星期二UTC-8上午11时29分54秒,Kan Wu写道:

I feel stupid: I totally forgot that Gatling EL supports this out of the box!

“${ListB(counter)}”

“${ListB.random}”

nice. but if i want function like indexOf, i have to save that the seq to a list first? That’s what i’m doing now and it works fine.

在 2014年1月28日星期二UTC-8下午1时55分09秒,Stéphane Landelle写道:

Sorry, I don’t get it. indexOf is defined on Seq (which is a trait that List extends).

sorry. i didnt say it clearly. this is my code of how doing it:

exec(session => {
val tList = session(“typeList”).as[Seq[String]]
val wList = session(“weightList”).as[Seq[String]]
val index = tList.indexOf(“0”)
val weight = wList(index)
session.set(“index”,index)
session.set(“weight”,weight)
})

we can simply use ${typeList.indexOf(“0”)} and skip saving to a local val first?

在 2014年1月29日星期三UTC-8上午12时12分24秒,Stéphane Landelle写道:

indexOf isn’t supported in Gatling EL.

Gatling EL is meant to be very simple and not a full blown kind of dynamic language inside Scala code.

Where does this “0” attribute come from?

this is what i expected too. my code is working fine. Thanks a lot for your response!

btw, i sent you an email in detail of the issue we talked about.

在 2014年1月29日星期三UTC-8上午9时44分16秒,Stéphane Landelle写道:

“0” is a value of the seq. i want to know the index of “0” in tList, then get the same index element from list wList.

在 2014年1月29日星期三UTC-8上午9时45分54秒,Stéphane Landelle写道:

If tList and wList are supposed to work together, I guess I’d first zip them together (so I’d get a Seq[(String, String)]), loop over the result and add a exec(function) that would expose the Tuple2 current element into 2 dedicated attributes.

Get it?

yes. i see your point here but we use two lists in separate places but only need to get the index value. i will try your suggestion if it could life efficiency. Thanks for helping out!

在 2014年1月29日星期三UTC-8下午1时07分22秒,Stéphane Landelle写道: