I have the following two methods:
def randomStartMethod() : Long = {
var range = 1000L
var r = ThreadLocalRandom.current().nextLong(10L*range)
var randomStart = 1396024675000L + r
return randomStart
}
def randomStopMethod() : Long = {
var range = 1000L
val r = ThreadLocalRandom.current().nextLong(10L*range)
val randomStop = 1396024675000L + r*2L
return randomStop
}
Then I add it to the request body like this:
val activity = repeat(10, "i") {
exec(http("POST activity post")
.post("/activity/")
.header("Content-Type", "application/json; charset=ISO-8859-1")
.header("accept", "*/*")
.body(StringBody(
s"""
|{
| "id": "activityId",
| "type": "run",
| "start_epoch_ms": "${randomStartMethod()}",
| "end_epoch_ms": "${randomStop()}",
| "metrics": [
| {
| "type": "distance",
| "unit": "KM",
| "source": "nike.running.ios",
| "values": [
| {
| "start_epoch_ms": "${randomStartMethod()}",
| "end_epoch_ms": "${randomStopMethod()}",
| "value": 2.0
| }
|
| ]
| }
| ]
|}
""".stripMargin)).
asJSON
.check(status.is(202))
.check(
jsonPath(
"$.activityId").saveAs("message")
)
.check(bodyString.
transform(_.split("\""
)(3)).saveAs(
"changeToken"))
).exec(
session => {
val maybeId =
session.get(
"message").asOption[String]
println(maybeId)
session
}
)
}
}
But here the values are not generated dynamically when I use with feed. Can someone suggest how to generate the random numbers every time throughout the run?