aslongas http response not OK

Hello Group,

I’m trying to do an aslongas check that seems like it should be pretty simple, but it doesn’t seem to be working for me. Here’s the gist:

class Demo extends Simulation
{
setUp(
scenario(“Demo Start”)
.exec(.set(“rs”, “0”))
.exec(
.set(“workflowGuid”, “D1O5KIBJo4BEB1Kt”))
.exec(Test.printSession)
.exec(Test.checkCallback)
.exec(Test.printSession)
.inject( atOnceUsers(1) )
)
}

object Test {
val checkCallback: ChainBuilder = asLongAs(session => session(“i”).as[Int] < 10 && session(“rs”).as[String] != “200”, “i”) {
exec(
http(“Look for callbacks”)
.get(Constants.callbackUrl + “?workflow_id=${workflowGuid}”)
.check(status.saveAs(“rs”))
)
}
val printSession: ChainBuilder = exec(session => {
session.foreach(print)
session
})
}

That outputs:

Session(Demo Start,1,Map(gatling.http.cache.dns → io.gatling.http.resolver.ShuffleJdkNameResolver@1f9ea9a7, rs → 0, workflowGuid → D1O5KIBJo4BEB1Kt),1529105538251,0,OK,List(),io.gatling.core.protocol.ProtocolComponentsRegistry$$Lambda$380/848102479@671ea959)16:32:18.353 [INFO ] i.g.c.c.Controller - InjectionStopped expectedCount=1
Session(Demo Start,1,Map(gatling.http.cache.dns → io.gatling.http.resolver.ShuffleJdkNameResolver@1f9ea9a7, rs → 200, workflowGuid → D1O5KIBJo4BEB1Kt),1529105538251,40,OK,List(),io.gatling.core.protocol.ProtocolComponentsRegistry$$Lambda$380/848102479@671ea959)16:32:20.340 [INFO ] i.g.c.c.Controller - All users are stopped

https://groups.google.com/d/msg/gatling/5bIEPSM1zzw/2XfF2KhEBgAJ

session(“rs”).as[Int] != 200

Hi Vu,
Thanks for your reply. changed to string comparison, exactly the same effect:

val checkCallback: ChainBuilder = asLongAs(session => session(“i”).as[Int] < 10 && session(“rs”).as[String] != “200”, “i”) {

I also enabled trace logging and have verified that the very first request is returning 200 and yet request it made 10 times:

Request:

Look for callbacks: OK

Status code is an INT!!!

Oop, misread. I actually did try that initially:
session(“rs”).as[Int] != 200

But that throws an exception:
java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer

Ah hah! I was initializing it as a string!

Thanks for your help, works as expected!