I am using Gatling to send POST requests with JSON payloads, and need to inject a unique timestamp into the payload of each request. Gatling is deployed alongside of source code for the application being tested, and we are using Gradle 1.9 as our build system, but the Scala code for Gatling gets compiled by an ant process.
In code I created a Feeder object to generate unique timestamps, but have run into problems with the service rejecting my payloads.
After much trial and error, I finally determined the timestamp is required be in ISO 8061 format (example = 2011-02-10T15:04:55.234Z).
Long doesn’t work; neither does System.currentTimeMillis; nor does apache DataFormatUtils.ISO_DATETIME_FORMAT.
I was happy to find out the parent project my Gatling code run in has the Joda Time 2.4 library, but when I tried to use this, I got an internal compilation error in Gatling.
I’ve attached an excerpt of the stack trace that occurs.
From what I can gather by reading through it, there seems to be a problem with toString not performing as expected when used with my new DateTime joda object.
Is there a better way to do this in Gatling?
My code is below. It lives inside an object file called RandomFeeder.scala.
/**
- Produces timestamps in ISO 8061 format
- example = 2011-02-10T15:04:55.234Z
*/
val timestampFeeder = new Feeder[String] {
override def hasNext = true
override def next: Map[String, String] = {
// Map(“timestamp” → abs(scala.concurrent.forkjoin.ThreadLocalRandom.current().nextLong(10000000000L)).toString) // regular Java
// Map(“timestamp” → System.currentTimeMillis().toString()) // regular Java
// Map(“timestamp” → DateFormatUtils.ISO_DATETIME_FORMAT.toString() ) // apache common.lang
Map(“timestamp” → new DateTime().toString() ) // joda time
}
}
gatling_compilationErrorUsingJoda.txt (3.17 KB)