Incomprehensible type issue => why the hell "required: io.gatling.core.session.Session" ???

Hello everybody

I am using following “pure Scala” function within my scenario

def extractCharacteristicFromConfig(config:String, numChar:Int): String = {
val jsonObject: JsValue = Json.parse(config)

//println("==> DEBUG : config=" +config +" - numChar=" +numChar)

return Json.stringify(jsonObject(numChar))
}

and when i am doing my mvn:gatling test I got this kind of issue from ZincCompiler

found : Int
required: io.gatling.core.session.Session
return Json.stringify(jsonObject(numChar))
^
15:29:30.711 [ERROR] i.g.c.ZincCompiler$ - one error found
15:29:30.718 [ERROR] i.g.c.ZincCompiler$ - Compilation crashed

I am 100% sure than input parameters (config & numChar) are correctly set thanks to the previous DEBUG println
I really dont get the reason of this type mistmatch issue (even if I am pretty sure it is an obvious one for Gatling experts :slight_smile: )

Thanks in advance for any suggestion!!

For your information here is the overall call chain:

val sc_scenario_1_loop = scenario(Prefix + " - S&C loop")
.exec(SC_Execution_Chain())

def SC_Execution_Chain() =
exec(
session => {
val conf = dataGen.getRandomConfiguration(“c:/TEMP/configurations.json”)
// lets create 3 session variables to store information required to manage PUT /…/characteritics requests
session.set(“randomConfig”, (conf \ “configuration”).get)
.set(“configCharacteristics”, (conf \ “characteristics”).get)
.set(“nbConfigCharacteristics”, (conf \ “characteristics” \ “id”).size)
}
)
// start a new product configuration
.exec(postConfiguration())
.exec(
session => {
session.set(“scEncodedConfigurationId”, percentEncoding(session(“scConfigurationId”).as[String]))
}
)

// for i from 1 to nbConfigCharacteristics do
.repeat(session => session(“nbConfigCharacteristics”).as[Int], “i”) {
exec(
session => {
session.set(“characteristicSetting”, extractCharacteristicFromConfig(session(“configCharacteristics”).as[String], session(“i”).as[Int]))

}
)
.exec(putConfigurationCharacteristics("${scEncodedConfigurationId}", “${characteristicSetting}”))

}

// get the from a complete JSON configuration (=[{characteristic}, …, {characteristic}])
def extractCharacteristicFromConfig(config:String, numChar:Int): String = {
val jsonObject: JsValue = Json.parse(config)

//println("==> DEBUG : config=" +config +" - numChar=" +numChar +" - char=" +Json.stringify(jsonObject(numChar)))

return Json.stringify(jsonObject(numChar))

}

Please mind your language here. Some people will find “why the hell” offensive.

I don’t know what your JsValue is (Play?) but it looks like it doesn’t have an apply method so you can’t call jsonObject(Int).

Hi Stephane

Very sorry for the “why the hell” - I did not want to offend anyone

Indeed JsValue comes from JSON Play framework.
To be sure I tested the content of the extractCharacteristicFromConfig is a “pure Scala context” (using below piece of code)

import play.api.libs.json._

val numChar:Int = 2
val config:String =
“”"

[
{“id”:“T_RATED_CURRENT”,“bomPath”:“00000010”,“value”:“50_A”},
{“id”:“T_POLES_DESCRIPTION”,“bomPath”:“00000010”,“value”:“4P”},
{“id”:“TC_CONNECTIONS”,“bomPath”:“0000”,“value”:“COMPRESSION_LUG”}
]
“”"
val jsonObject: JsValue = Json.parse(config)
println(“Debug: config=” +config +" - numChar=" +numChar +" - char=" +jsonObject(numChar))
println("Debug : " +Json.stringify(jsonObject(numChar)))

==> It works fine

What confuse me is the required: io.gatling.core.session.Session error message that makes me think that I am using “badly” Gatling and I dont get why…

Your problem is that both play-json and Gatling provide implicit conversions with similar signature and they clash with each other.

You have 2 solutions:

  • move play-json code to its own classes where you don’t import Gatling components
  • make play-json conversions explicit: Json.stringify(JsValue.jsValueToJsLookup(jsonObject)(numChar))