Java_opts invoke error

Hello,

everytime I invoke values only have of them work. If anyone has any idea. Tnx

Terminal
mvn gatling:execute -DuserAtOnce=10 -DfirstPause=10 -Dtest1=10 -Dtest2=10 -Dgatling.simulationClass=OpenScenario

object EnvironmentVariables {
  // Global - Environment Variables for Jenkins}
  val firstPause = Integer.getInteger("firstPause", 1).toInt
  val secondPause = sys.env.getOrElse("secondPause", "1").toInt
  val thirdPause = sys.env.getOrElse("thirdPause", "1").toInt

  // Environment Variables for Jenkins
  val userAtOnce = Integer.getInteger("userAtOnce", 1).toInt
  val test1 = sys.env.getOrElse("test1", "1").toDouble
  val test2 = sys.env.getOrElse("test2", "1").toInt
}

And the simulation class:

  setUp(
    OpenScenario.inject(
      atOnceUsers(userAtOnce),
      nothingFor(firstPause seconds),
      constantUsersPerSec(test1) during(test2 seconds)
    )
  )
    .protocols(openProtocol)
}

All the "Integer.getInteger()" get invoked, but the "sys.env.getOrElse()" going producing the default?
TNX

You’re confusing Env properties and System properties. You pass the latter.

Do you mean by added system properties to my pom.xml and invoking them there?

myKey myValue

or did you mean I had to export them first to maven?
export MAVEN_OPTS=-DmyKey=myValue

That’s not the problem here.
When you’re using Integer.getInteger, you get your values from System Properties, which is what you’re passing using -Dmykey=myValue.

When using sys.env, you get your values from Environment Variables. It’s simply not the same thing.
If you want to have default values for your system properties, use scala.util.Properties.propOrElse(“myProperty”, “defaultValue”).

Tnx

One final question:
(Is this true?, because jenkins uses envVar)

When I want to invoke using Jenkins, I have to pass

val test1 = sys.env.getOrElse("foo", "1").toDouble

And when I want to do it from the command line

val test1 = System.getProperty("foo").toDouble

Jenkins allows you to use environment variables, but you can also use system properties :slight_smile:

Thanks a million dude