I’m really new to Scala and I’m not even able to concatenate Strings. Here is my code:
object RandomData {
private[this] val bag = new scala.util.Random
def apply(sensorId: String, stamp: Long, size: Int): String = {
var cpt: Int = 0
var data: String = "test"
repeat(10) {
data += "_test"
}
return data
}
}
I got the error:
type mismatch;
found : Unit
required: com.excilys.ebi.gatling.core.structure.ChainBuilder
What am I doing wrong ??
repeatis offered by Gatling in order to repeat Gatling tasks, e.g., query a website. If you have a look at the documentation (I wasn’t able to find a link to the API doc ofrepeat), you’ll see that repeat expects a chain, which is why your error message says “required: com.excilys.ebi.gatling.core.structure.ChainBuilder”. However, all you do is to append to a string – which will not return a value of typeChainBuilder.Moreover, appending to a string is nothing that should be done via Gatling. It looks to me as if you are confusing Gatling’s
repeatwith a Scalaforloop. If you only want to append"_test"todata10 times, use one of Scala’s loops (for,while) or a functional approach with e.g.foldLeft. Here are two examples: