How can I read duration from configuration file

I want to put some duration parameter to configuration files, such as ramp up time, pause interval, etc. How can I access them in gatling script? Shall I use ConfigFactory and Config API?

Here is what I tried. Define the properties in application.conf file:

load {
rampUpTime = 10 seconds # Ramp up
pauseInterval = 200 milliseconds # Pause interval between each operation
queryStatusInterval = 1 second # Pause interval between querying status

Then access them in the simulation script:

val rampUpTime = appConfFile.getDuration(“test.load.rampUpTime”)
val pauseInterval = appConfFile.getDuration(“test.load.pauseInterval”)
val queryStatusInterval = appConfFile.getDuration(“test.load.queryStatusInterval”)

But ZincCompiler reported the error like below:
not enough arguments for method getDuration: (x$1: String, x$2: java.util.concurrent.TimeUnit)Long.

I checked the documentation :
Seems there is a method defined:

java.time.Duration [getDuration]( path)
Gets a value as a java.time.Duration.

What did I do wrong?

You’re confusing Java Duration and Scala one.
And Java Duration was introduced in JDK8, so it’s only supported in latest config versions, where they dropped support for JDK7. That’s not the version you’re currently using.

Thanks Stéphane, so I guess I should use Scala Duration? Do you have an example of reading Scala Duration from configuration file?


You can use wrapper library -

val config = ConfigFactory.load()
val duration = config.getDuration


Thanks Alex. Seems it’s what I want. Took a look at it and the usage is as below:



libraryDependencies += "com.github.kxbmap" %% "configs" % "0.3.0"

So I need to create build.sbt and build the simulation scripts with sbt? I’m new to Scala, so it will be helpful to know more information.

Here is what I did. Hope it could help somebody.

  1. Upgrade to Java 8.
  2. In the script, define a implicit conversion, so that it can do the conversion automatically.

implicit def asFiniteDuration(d: Long) =

val pauseInterval = appConfFile.getDuration(“pauseInterval”, NANOSECONDS)

How to get duration of audio file in google sheets by using google script