scala - Gatling - doIfOrElse does wrong branching with Map.size condition -


in following code snippet usermap empty map still when run else block executed , error

package computerdatabase  import io.gatling.core.predef._ import io.gatling.http.predef._ import scala.concurrent.duration._ import io.gatling.jsonpath._  class test1 extends simulation {      //global users   val usermap = scala.collection.concurrent.triemap[string, string]()   //randomiser    val rnd = new scala.util.random   val httpconf = http     .baseurl("http://demo1263864.mockable.io/") // here root relative urls     .acceptheader("application/json") // here common headers     .donottrackheader("1")     .acceptlanguageheader("en-us,en;q=0.5")     .acceptencodingheader("gzip, deflate")     .useragentheader("mozilla/5.0 (macintosh; intel mac os x 10.8; rv:16.0) gecko/20100101 firefox/16.0")    val headers_10 = map("content-type" -> "application/json") // note headers specific given request    val scn = scenario("simple battle")     .doiforelse(rnd.nextint(3) > 2 || usermap.size == 0) {       println("++++++++++++++++" + usermap.size)       exec(         http("if request ")           .get("gatling1")           .headers(headers_10)           .check(jsonpath("$.result").is("success")) // because warning when no password sent , new profile created            ) // executed if session value stored in "mykey" equal "myvalue"         .exec(session => {           println("++" + session)           usermap("1") = "2"           session         })         .exec(session => {           println("++" + usermap.size)           session         })     } {       val index = rnd.nextint(usermap.size)       val userarray = usermap.toarray.map(x => array(x._1, x._2))       exec(http("else request")         .get("gatling1")         .headers(headers_10)         .check(jsonpath("$.result").is("success"))) // because warning when no password sent , new profile created       }    setup(scn.inject(atonceusers(1)).protocols(httpconf)) } 

the output shows else block executed if usermap.size == 0

simulation computerdatabase.test1 started... ++++++++++++++++0 exception in thread "main" java.lang.illegalargumentexception: n must positive     @ java.util.random.nextint(random.java:300)     @ scala.util.random.nextint(random.scala:65)     @ computerdatabase.test1.<init>(test1.scala:43)     @ sun.reflect.nativeconstructoraccessorimpl.newinstance0(native method)     @ sun.reflect.nativeconstructoraccessorimpl.newinstance(nativeconstructoraccessorimpl.java:57)     @ sun.reflect.delegatingconstructoraccessorimpl.newinstance(delegatingconstructoraccessorimpl.java:45)     @ java.lang.reflect.constructor.newinstance(constructor.java:526)     @ java.lang.class.newinstance(class.java:374)     @ io.gatling.core.runner.runner.run(runner.scala:37)     @ io.gatling.app.gatling.start(gatling.scala:235)     @ io.gatling.app.gatling$.frommap(gatling.scala:54)     @ io.gatling.app.gatling$.rungatling(gatling.scala:79)     @ io.gatling.app.gatling$.rungatling(gatling.scala:58)     @ io.gatling.app.gatling$.main(gatling.scala:50)     @ io.gatling.app.gatling.main(gatling.scala) 

i answered question on gatling's group : https://groups.google.com/forum/#!topic/gatling/j8o27q112ou


Comments