Gatling 2.0 Snapshot. Set variable to null during the test

From the my previous question:!topic/gatling/rK7cqe4s0cc

To exit loop I need on every iteration before checks set variable to “null” (string) or “0” (integer)

I really need help to write it in scenario, because I still very newbie in Scala

val request_new_dictionary = asLongAs(session => session(“count_sync”).as[String] != “0”){




.param(""“request”"", “”" “”")

.exec {session => session.setAll (“count_sync”->0)} //it didn’t compile

.check (














I’m sorry to disturb, but I still has this problem unsolved
I really need set one of variable to null during the request,otherwise I can’t exit the loop.
My test is only one request which repeats until variable exist in response.

Don’t set to null, that’s a very very bad Java habit.
Remove the attribute: Session.remove(“key”)

Stéphane, thank You VERY MUCH for Your help.
It compile now, but now I have another ussue…

Then i reach AsLongAs loop I receve error
[ERROR] [07/25/2014 10:17:43.184] [] [akka://GatlingSystem/user/$f] key not found: count_sync
java.util.NoSuchElementException: key not found: count_sync
at scala.collection.MapLike$class.default(MapLike.scala:228)
at scala.collection.AbstractMap.default(Map.scala:58)
at scala.collection.MapLike$class.apply(MapLike.scala:141)
at scala.collection.AbstractMap.apply(Map.scala:58)
at MainScenario_TryLoop$$anonfun$1.apply(MainScenario_TryLoop.scala:51)
at MainScenario_TryLoop$$anonfun$1.apply(MainScenario_TryLoop.scala:51)
at io.gatling.core.action.InnerWhile$$anonfun$3.applyOrElse(While.scala:56)
at io.gatling.core.action.InnerWhile$$anonfun$3.applyOrElse(While.scala:55)
at scala.PartialFunction$OrElse.apply(PartialFunction.scala:162)
at io.gatling.core.action.Interruptable$$anonfun$1.applyOrElse(Actions.scala:62)
at scala.PartialFunction$OrElse.applyOrElse(PartialFunction.scala:165)
at akka.dispatch.Mailbox.processMailbox(Mailbox.scala:237)
at akka.dispatch.ForkJoinExecutorConfigurator$AkkaForkJoinTask.exec(AbstractDispatcher.scala:386)
at scala.concurrent.forkjoin.ForkJoinTask.doExec(
at scala.concurrent.forkjoin.ForkJoinPool$WorkQueue.runTask(
at scala.concurrent.forkjoin.ForkJoinPool.runWorker(

The MainScenario_TryLoop.scala:51 is
val request_new_dictionary = asLongAs(session => session(“count_sync”).as[String].length() != 0){ \this is line 51 in my test
exec(session => session.remove(“count_sync”)).


If I remove
exec(session => session.remove(“count_sync”)) - test goes Ok, but with eternal loop.

in desperate search for solution

Instead of your ugly session => session(“count_sync”).as[String].length() != 0
you should be doing session.contains(“count_sync”)

Stéphane, it helps to avoid the error, but does not actually solve the problem as the loop does not start.

If the response does not contain any dictionary tag the session variable count_sync remains the same from the previous request, so the program goes to the endless loop.
If I add exec(session => session.remove(“count_sync”)). as the first command inside the loop the loop does not start at all, it looks like the variable is removed from the session before the loop condition is checked.

Best regards

it looks like the variable is removed from the session before the loop condition is checked


So add a flag in the session to force entering the loop, and remove it inside the loop.

The flag is already set to the session. If I comment the remove command the loop is started

OK, I didn’t look at your code properly.
Yes, by default, asLongAs loops exit ASAP:

Either disable exitASAP or move the removal to the end on the loop content.

Thanks a lot for Your help and time!
You really make my day today!!!