NPE on randomswitch

Hi:

I am getting NPE on the randomswitch, can you take a look?

Simulation overall.ProfilePeople started…
Exception in thread “main” java.lang.NullPointerException
at io.gatling.core.action.builder.RandomSwitchBuilder$$anonfun$3.apply(RandomSwitchBuilder.scala:34)
at io.gatling.core.action.builder.RandomSwitchBuilder$$anonfun$3.apply(RandomSwitchBuilder.scala:32)
at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:244)
at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:244)
at scala.collection.immutable.List.foreach(List.scala:318)
at scala.collection.TraversableLike$class.map(TraversableLike.scala:244)
at scala.collection.AbstractTraversable.map(Traversable.scala:105)
at io.gatling.core.action.builder.RandomSwitchBuilder.build(RandomSwitchBuilder.scala:32)
at io.gatling.core.structure.AbstractStructureBuilder$$anonfun$buildChainedActions$1.apply(AbstractStructureBuilder.scala:31)
at io.gatling.core.structure.AbstractStructureBuilder$$anonfun$buildChainedActions$1.apply(AbstractStructureBuilder.scala:30)
at scala.collection.LinearSeqOptimized$class.foldLeft(LinearSeqOptimized.scala:111)
at scala.collection.immutable.List.foldLeft(List.scala:84)
at io.gatling.core.structure.AbstractStructureBuilder.buildChainedActions(AbstractStructureBuilder.scala:30)
at io.gatling.core.structure.ChainBuilder.build(ChainBuilder.scala:45)
at io.gatling.core.action.builder.IfBuilder.build(IfBuilder.scala:34)
at io.gatling.core.structure.AbstractStructureBuilder$$anonfun$buildChainedActions$1.apply(AbstractStructureBuilder.scala:31)
at io.gatling.core.structure.AbstractStructureBuilder$$anonfun$buildChainedActions$1.apply(AbstractStructureBuilder.scala:30)
at scala.collection.LinearSeqOptimized$class.foldLeft(LinearSeqOptimized.scala:111)
at scala.collection.immutable.List.foldLeft(List.scala:84)
at io.gatling.core.structure.AbstractStructureBuilder.buildChainedActions(AbstractStructureBuilder.scala:30)
at io.gatling.core.structure.ChainBuilder.build(ChainBuilder.scala:45)
at io.gatling.core.action.builder.RandomSwitchBuilder$$anonfun$3.apply(RandomSwitchBuilder.scala:34)
at io.gatling.core.action.builder.RandomSwitchBuilder$$anonfun$3.apply(RandomSwitchBuilder.scala:32)
at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:244)
at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:244)
at scala.collection.immutable.List.foreach(List.scala:318)
at scala.collection.TraversableLike$class.map(TraversableLike.scala:244)
at scala.collection.AbstractTraversable.map(Traversable.scala:105)
at io.gatling.core.action.builder.RandomSwitchBuilder.build(RandomSwitchBuilder.scala:32)
at io.gatling.core.structure.AbstractStructureBuilder$$anonfun$buildChainedActions$1.apply(AbstractStructureBuilder.scala:31)
at io.gatling.core.structure.AbstractStructureBuilder$$anonfun$buildChainedActions$1.apply(AbstractStructureBuilder.scala:30)
at scala.collection.LinearSeqOptimized$class.foldLeft(LinearSeqOptimized.scala:111)
at scala.collection.immutable.List.foldLeft(List.scala:84)
at io.gatling.core.structure.AbstractStructureBuilder.buildChainedActions(AbstractStructureBuilder.scala:30)
at io.gatling.core.structure.ScenarioBuilder.build(ScenarioBuilder.scala:53)
at io.gatling.core.scenario.configuration.ConfiguredScenarioBuilder.build(ConfiguredScenarioBuilder.scala:51)
at io.gatling.core.scenario.configuration.Simulation$$anonfun$scenarios$1.apply(Simulation.scala:26)
at io.gatling.core.scenario.configuration.Simulation$$anonfun$scenarios$1.apply(Simulation.scala:26)
at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:244)
at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:244)
at scala.collection.mutable.ResizableArray$class.foreach(ResizableArray.scala:59)
at scala.collection.mutable.ArrayBuffer.foreach(ArrayBuffer.scala:47)
at scala.collection.TraversableLike$class.map(TraversableLike.scala:244)
at scala.collection.AbstractTraversable.map(Traversable.scala:105)
at io.gatling.core.scenario.configuration.Simulation$class.scenarios(Simulation.scala:26)
at overall.ProfilePeople.scenarios(ProfilePeople.scala:13)
at io.gatling.core.runner.Runner.run(Runner.scala:46)
at io.gatling.app.Gatling$$anonfun$19.apply(Gatling.scala:198)
at io.gatling.app.Gatling$$anonfun$19.apply(Gatling.scala:190)
at scala.Option.getOrElse(Option.scala:120)
at io.gatling.app.Gatling.start(Gatling.scala:190)
at io.gatling.app.Gatling$.fromMap(Gatling.scala:58)
at io.gatling.app.Gatling$.runGatling(Gatling.scala:79)
at io.gatling.app.Gatling$.main(Gatling.scala:53)
at io.gatling.app.Gatling.main(Gatling.scala)

Can you share your scenario? Are you using Gatling 2.0-M2 ?

thanks
Nicolas

yes,

I think it might be because I have a randomswitch inside a randomswitch

val chain1 = exec(http("/orgchart")
.get("/__services/v2/rest/users/" + “${userID}” + “/orgchart?userID=” + “${userID}”)
.check(status.is(200)))

val chain2 = exec ((session:Session) => {
var view: String = “detail”
var tab: String = “following”
var sort: String = null

var rand = Common.randomInt(0, 1)
if(rand == 0) {
view = “detail”;
}
else {
view = “thumb”
}
rand = Common.randomInt(0,1)
if(rand == 0) {
tab = “following”
}
else {
tab = “followers”
}
rand = Common.randomInt(0,1)
if(rand == 0) {
sort = Common.encodeURIComponent(“following~firstName”);
}
else {
sort = Common.encodeURIComponent(tab + “~” + “dateJoined”)
}
rand = Common.randomInt(1, 10)
if(rand > 8){
session.set(“view”, view).set(“tab”, tab).set(“defaultSort”,EncodeURIComponent.encodeURIComponent(“following~firstName”)).set(“sort”, sort)
}
else{

session.set(“view”, view).set(“tab”, tab).set(“defaultSort”, EncodeURIComponent.encodeURIComponent(“following~firstName”))
}
})
.exec(http("/selecttab")
.get("/__services/v2/rest/users/"+ “${userID}” + “/browse?filterGroupID=profilePeople&start=0&numResults=20&filterID=”+ “${tab}”+ “&sortKey=”+ “${defaultSort}”+"&sortOrder=0&itemView="+ “${view}”+ “&userID=” + “${userID}”)
.check(status.is(200)))
.doIf(session => session.get(“sort”) != null) {
exec(http("/changesort")
.get("/__services/v2/rest/users/"+ “${userID}” + “/browse?filterGroupID=profilePeople&start=0&numResults=20&filterID=”+ “${tab}”+ “&sortKey=”+ “${sort}”+ “&sortOrder=0&itemView=”+ “${view}”+ “&userID=” + “${userID}”)
.check(status.is(200)))
.randomSwitch( // beware: use parentheses, not brackets!
100 → chain3
)
}

val chain3 = feed(csv(“searchterms.csv”))
.exec(http("/query")
.get("/__services/v2/rest/users/"+ “${userID}” + “/browse?filterGroupID=profilePeople&start=0&numResults=20&filterID=”+ “${tab}”+ “&sortKey=”+ “${defaultSort}”+ “&sortOrder=0&itemView=”+ “${view}”+ “&userID=” + “${userID}”).queryParam(“query”, “${query}”)
.check(status.is(200)))

val scn = scenario(“ProfilePeople Scence”)
.exec(http(“cslogin”)
.post("/cs_login")
.headers(Common.headers_0)
.param(""“successURL”"", “”"%2Findex.jspa""")
.param(""“username”"", “”“admin”"")
.param(""“password”"", “”“admin”""))
.pause(1)
.feed(csv(“users.csv”))
.exec(http("/people")
.get("/people/"+ “${userName}” + “/people”)
.check(status.is(200)))
.randomSwitch( // beware: use parentheses, not brackets!
10 → chain1,
90 → chain2
)

Your problem is that you use the chain3 val before it gets assigned (hence the NPE).
Just move chain3 assignment before chain2.

Cheers,

Stéphane

yeah, it works now, thx!

You’re welcome.