Error using Gatling with Joda Time ( RC5)

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)

Honestly, I have no idea why this doesn’t compile for you. It works perfectly fine for me, as expected.
It could be an issue with your Gradle over Ant over Scalac build chain. Did you try to clean before building?

Just note that you could write this in a more elegant manner:
val timestampFeeder = Iterator.continually(Map(“timestamp” → new DateTime().toString))

Also, note that Gatling ships ThreeTenBP which is the backport of the new DateTime API that was introduced in Java 8.

Stephane, I like your version of this much better! I feel like I’m just doing baby talk when it comes to writing Scala and Gatling code.

I added clean to the Gradle call, but still am getting the error. I suspect that the Joda library reference I saw in the main project might be incomplete or not quite what I thought it was. Looks like this will be a good chance for me to dig into Joda Time, which I’ve been curious about for awhile. At least I know i’m on the right track with this code in its crude form. :wink:

there seems to be a similar issue described here:

Nice finding, Alex!

I’m baffled o_0

A long overdue update on this. I was finally able to get this working with a few minor changes. It turned out I needed to use a DateFormatter. Final version of the method is below>

 * Generate timestamps for requests
val timestampFeeder = new Feeder[String] {
  override def hasNext = true

  val nowdate = new java.util.Date()

  val fmt = new java.text.SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss-07:00")
  val timestamp = fmt.format(nowdate)

  override def next: Map[String, String] = {
    Map( "timestamp" -> timestamp.toString )