[INFO] --- gatling-maven-plugin:2.1.6:execute (default-cli) @ hawkular-metrics-load-tests ---
10:43:15.156 [main][ERROR][ZincCompiler.scala:108] i.g.c.ZincCompiler$ - /home/tsegismont/Projets/hawkular-metrics/load-tests/src/test/scala/org/hawkular/metrics/loadtest/MetricsSimulation.scala:25: type mismatch;
found : Integer
required: io.gatling.core.session.Expression[Int]
(which expands to) io.gatling.core.session.Session => io.gatling.core.validation.Validation[Int]
10:43:15.161 [main][ERROR][ZincCompiler.scala:108] i.g.c.ZincCompiler$ - val simulation = repeat(loops, "n") {
10:43:15.163 [main][ERROR][ZincCompiler.scala:108] i.g.c.ZincCompiler$ - ^
10:43:15.530 [main][ERROR][ZincCompiler.scala:108] i.g.c.ZincCompiler$ - one error found
package org.hawkular.metrics.loadtest
import scala.concurrent.duration._
import io.gatling.core.Predef._
import io.gatling.http.Predef._
import io.gatling.jdbc.Predef._
class MetricsSimulation extends Simulation {
val baseURI = System.getProperty("baseURI", "http://localhost:8080")
val clients = Integer.getInteger("clients", 1)
val ramp = java.lang.Long.getLong("ramp", 0L)
val loops = Integer.getInteger("loops", 1000)
val interval = Integer.getInteger("interval", 1)
val httpProtocol = http
.baseURL(baseURI)
.header("Hawkular-Tenant", "default")
.contentTypeHeader("application/json;charset=utf-8")
val simulation = repeat(loops, "n") {
exec(http("Report ${n}")
.post("/hawkular/metrics/gauges/data")
.body(ELFileBody("body.json")).asJSON
).pause(interval)
}
val scn = scenario("MetricsSimulation").exec(simulation)
setUp(scn.inject(rampUsers(clients) over (ramp seconds))).protocols(httpProtocol)
}
val loops = Integer.getInteger("loops", 1000)
val loops = Integer.getInteger("loops", 1000).toInt
--
You received this message because you are subscribed to the Google Groups "Gatling User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gatling+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Long explanation:An implicit conversion between Integer and Int can automatically happen but only if there's only one implicit conversion involved.And there's already one because repeat actually takes a function (so there's an implicit conversion from raw value to function).
Have fun!
Now I need to figure out how to build a JSON string with a configurable number of metrics data points. Once this is done I'll be in the Nirvana :p
package org.hawkular.metrics.loadtest
import scala.concurrent.duration._
import io.gatling.core.Predef._
import io.gatling.http.Predef._
import io.gatling.jdbc.Predef._
class MetricsSimulation extends Simulation {
val baseURI = System.getProperty("baseURI", "http://localhost:8080")
val clients = Integer.getInteger("clients", 1)
val ramp = java.lang.Long.getLong("ramp", 0L)
val loops = Integer.getInteger("loops", 10).toInt
val interval = Integer.getInteger("interval", 1)
val metrics = Integer.getInteger("metrics", 10)
val points = Integer.getInteger("points", 1)
val httpProtocol = http
.baseURL(baseURI)
.header("Hawkular-Tenant", "default")
.contentTypeHeader("application/json;charset=utf-8")
val random = new util.Random
val genReport = (m: Int, p: Int) => {
val builder = new StringBuilder
builder += '['
for (i <- 1 to m) {
builder ++= """{"id":"metrics.load.test."""
builder.append(i)
builder ++= """.value","data":["""
for (j <- 1 to p) {
builder ++= """{"timestamp":"""
builder.append(System.currentTimeMillis)
builder ++= ""","value":"""
builder.append(random.nextDouble)
builder += '}'
if (j < p) builder += ','
}
builder ++= "]}"
if (i < m) builder += ','
}
builder += ']'
builder.toString
}
val feeder = Iterator.continually(Map("jsonReport" -> genReport(metrics, points)))
val simulation = repeat(loops, "n") {
feed(feeder)
.exec(http("Report ${n}")
.post("/hawkular/metrics/gauges/data")
.body(StringBody("""${jsonReport}"""))
).pause(interval)
}
val scn = scenario("MetricsSimulation").exec(simulation)
setUp(scn.inject(rampUsers(clients) over (ramp seconds))).protocols(httpProtocol)
}
I'm sure it's not idiomatic Scala but it seems to work as expected.
Then, if I may: there's no need to store the generated body in the Sessions with a Feeder.You can just simply call genReport from StringBody:val simulation = repeat(loops, "n") {
exec(http("Report ${n}")
.post("/hawkular/metrics/gauges/data")
.body(StringBody(session => genReport(metrics, points)))).pause(interval)
}
Also, note that, instead of writing:if (i < m) builder += ','you can simply move the StringBuilder's index after the loop:builder.setLength(builder.length - 1)
builder += ','
builder.setLength(builder.length - 1)