Gatling 2.0 Snapshot. Set variable to null during the test

From the my previous question: https://groups.google.com/forum/#!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”){

exec(http(“request_new_dictionary”)

.post("""/test/mobile""")

.headers(headers_Content_Length_0)

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

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

.check (

xpath(“count(/response/dictionary)”)

.find.saveAs(“count_sync”)

)

.check(

xpath(“string-length(/response/dictionary[1]/@sync_ts)”)

.find

.saveAs(“length_sync”)

)

.check(

xpath("/response/dictionary/@sync_ts")

.find

.saveAs(“dictionary_sync”)

)

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] [GatlingSystem-akka.actor.default-dispatcher-5] [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 io.gatling.core.session.SessionAttribute.as(Session.scala:39)
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.io$gatling$core$action$InnerWhile$$continue$1(While.scala:50)
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.actor.ActorCell.receiveMessage(ActorCell.scala:498)
at akka.actor.ActorCell.invoke(ActorCell.scala:456)
at akka.dispatch.Mailbox.processMailbox(Mailbox.scala:237)
at akka.dispatch.Mailbox.run(Mailbox.scala:219)
at akka.dispatch.ForkJoinExecutorConfigurator$AkkaForkJoinTask.exec(AbstractDispatcher.scala:386)
at scala.concurrent.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260)
at scala.concurrent.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1339)
at scala.concurrent.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979)
at scala.concurrent.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107)

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”)).
.exec(http(“request_sync2”)
.post("""/test/mobile""")

}

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


in desperate search for solution
Natalja

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
Natalja

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

No

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:
https://github.com/excilys/gatling/wiki/Gatling%202#core-misc

https://github.com/excilys/gatling/blob/master/src/sphinx/general/scenario.rst#aslongas

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!!!

Natalija