Passing command line parameter to the simulation

Hi,

I have one simulation within which I have configured multiple scenarios and multiple loads. Based on the command line parameter, I want to decide which scenario to run etc. I tried passing the parameter -DscenarioToRun=abc but I am not getting the value in simulation. Am I doing something wrong?

Chaitali

Probably, but hard to tell as long as you don’t share what you’ve done.

here’s what the maven command looks like mvn clean install -DscenarioToRun=abc and in my scenario I am trying to access it as follows:

val scenarioToRun = System.getProperty(“scenarioToRun”) scenarioToRun is null

This should be working. Which version do you use?

Hi All,

I am facing the same issue. I am using gatling-charts-highcharts-2.0.3.
I want that user can input ‘Count, repeatCount, testServerUrl and definitionId’ from command line while executing from Gatling. From command line I execute


|



> <br>> > sudo JAVA_OPTS="-DuserCount=5 -DflowRepeatCount=5 -DdefinitionId=10220101 -DtestServerUrl='https://someurl.com'" sudo bash gatling.sh -s TestCL<br>>

But it triggers only 1 action (default) not 5(user input from command line)




|

  • | - |

`
val userCount = Integer.getInteger(“userCount”, 1).toInt

val flowRepeatCount = Integer.getInteger(“flowRepeatCount”, 1).toInt

val definitionId = java.lang.Long.getLong(“definitionId”, 0L)

val testServerUrl = System.getProperty(“testServerUrl”)
`

Can you pls help me to find why command line parameters are not working?

Thanks,
Ronak

Hi Pandya,

That’s an overly complex command line. Have you tried:

JAVA_OPTS="-DuserCount=5 -DflowRepeatCount=5 -DdefinitionId=10220101 -DtestServerUrl='[https://someurl.com](https://someurl.com)'" ./gatling.sh -s TestCL

which assumes that gatling.sh is executable. Do chmod ug+x gatling.sh if it's not.

Regards,

Tony.

Hi Tony,
Thanks for the reply.

Executed this command
JAVA_OPTS="-DuserCount=5 -DflowRepeatCount=5 -DdefinitionId=10220101 -DtestServerUrl=https://someurl.com" ./gatling.sh -s TestCL
but gives following error:

`
The request class(‘TestCL’) can not be found in the classpath.
Exception in thread “main” java.util.NoSuchElementException: head of empty list
at scala.collection.immutable.Nil$.head(List.scala:337)
at scala.collection.immutable.Nil$.head(List.scala:334)
at io.gatling.app.Gatling.start(Gatling.scala:219)
at io.gatling.app.Gatling$.fromMap(Gatling.scala:55)
at io.gatling.app.Gatling$.runGatling(Gatling.scala:80)
at io.gatling.app.Gatling$.runGatling(Gatling.scala:59)
at io.gatling.app.Gatling$.main(Gatling.scala:51)
at io.gatling.app.Gatling.main(Gatling.scala)

`

Thanks,
Ronak

Hi Ronak (and apologies for using the wrong name in my previous replies),

Is TestCL the full classpath to your class? You can try to run your test without specifying the -s option (which is just a shortcut to select the simulation, after all).

Also, if you’re going to use -s , you might want to add -m to avoid the prompts for name & description.

Regards,

Tony.

Hi Tony,
Really sorry for the late reply, was busy on other stuffs.

I have tried on windows and it worked with this command.

set JAVA_OPTS=-DuserCount=3 -DflowRepeatCount=3 -DdefinitionId=10201

now,
it gives me this error (its not getting the value of ‘definationid’ which I pass thru command line)

`
body=
{
“errors” : {
“error” : “Unexpected character (‘$’ (code 36)): expected a valid value (num
ber, String, array, object, ‘true’, ‘false’ or ‘null’)\n at [Source: org.apache.
catalina.connector.CoyoteInputStream@31e6639f; line: 1, column: 19]”
}
}
---- Errors --------------------------------------------------------------------

status.find.in(200,304,201,202,203,204,205,206,207,208,209), but actually found 400

`
Here is my code,

`
class TestCLI extends Simulation {

val userCount = Integer.getInteger(“userCount”, 1).toInt
val holdEachUserToWait = 2
val flowRepeatCount = Integer.getInteger(“flowRepeatCount”, 1).toInt
val definitionId = java.lang.Long.getLong(“definitionId”, 0L)

val testServerUrl = “Some URL”
val envAuthenticationHeaderFromPostman = “”“Basic UGVREXW87uY2V0ZXN0OlBlcmWRcmdhbmNldGODKDE=”“”

val httpProtocol = http


val headers_0 = Map(…
…)

val scn = scenario(“T”)
.repeat (flowRepeatCount) {
exec(http(“Test”)
.post(“”“/api/wfo”“”)
.headers(headers_0)
.body(StringBody(“”“{“definitionId”: $definitionId}”“”))) // <== I think it didnt get the value of definition ID
.pause(holdEachUserToWait)
}

setUp(scn.inject(atOnceUsers(userCount))).protocols(httpProtocol)

}

`

If I use ‘DefinationID’ value static(Define in code not passing thru cmd) it works fine, but doesn’t work with command line argument. Can u pls take a look?

Thanks.

Hi,

Even if I use

.body(StringBody("""{"definitionId": ${definitionId}}""")))

It gives this error
`

---- Response Time Distribution ------------------------------------------------

t < 800 ms 0 ( 0%)
800 ms < t < 1200 ms 0 ( 0%)
t > 1200 ms 0 ( 0%)
failed 1 (100%)
---- Errors --------------------------------------------------------------------

Hi Ronak,

If I understand correctly, using

.body(StringBody(“”“{“definitionId”: $definitionId}”“”)))

attempts to find an entry in the session map. However, you’re not putting in the map, and presumably you’d need to use a feeder to do so.

Instead, the following might work

.body(StringBody(“”“{“definitionId”: " + definitionId + “}””“”)))

(i.e. just concatenate the definitionId variable into the string.) Note the quotes are probably wrong as I’ve not checked this.

Kind regards,
Tony.

Hi Tony,

Thanks a lot for giving your precious time and help.
Still not getting the solution. Don’t know where I m going wrong.

I have set
.body(StringBody("""{"definitionId": " + definitionId + "}"""")))

I have executed this

set JAVA_OPTS=-DuserCount=2 -DflowRepeatCount=2 -DdefinitionId=1123612

but it throws this error:

`

body=
{
“errors” : {
“error” : "Can not construct instance of java.lang.Long from String value ’

  • definitionId + ': not a valid Long value\n at [Source: org.apache.catalina.con
    nector.CoyoteInputStream@1d4e804c; line: 1, column: 2] (through reference chain:
    tv.nativ.mio.api.model.workflow.create.NewWorkflow[“definitionId”])"
    }
    }
    `

I’ve tried with some modification in quotes and it throws this error:

`

body=
{
“errors” : {
“error” : “Unexpected character (’+’ (code 43)): was expecting a colon to se
parate field name and value\n at [Source: org.apache.catalina.connector.CoyoteIn
putStream@3c496336; line: 1, column: 20]”
}
}
`

Thanks once again,
Ronak

Our emails crossed in the ether :slight_smile: Hopefully you’ve received my direct reply.

Hi Tony,

Have tried on command prompt from windows operating system and Worked well…Thanks for the help.
this is the command which I have executed.

JAVA_OPTS=-DuserCount=2 -DflowRepeatCount=3 -DdefinitionId=102168 -DtestServerUrl=https://someURL -DenvAuthenticationHeaderFromPostman="Basic UWRZm9aGwsxFsB1V7RXK0OlB5cmZvcm1hbmNldGVzdDE="

Do you know how to execute same command for Linux? I have tried with this but it won’t execute, takes null/1 as arguments :frowning:

sudo JAVA_OPTS=-DuserCount=2 -DflowRepeatCount=3 -DdefinitionId=102168 -DtestServerUrl=https://someURL -DenvAuthenticationHeaderFromPostman="Basic UWRZm9aGwsxFsB1V7RXK0OlB5cmZvcm1hbmNldGVzdDE=" sudo bash gatling.sh

I have printed the inputs and it takes this parameters as input (While in command prompt from Windows it works fine and takes parameters which we input)
INPUT***************
User Count ====>> 1
Repeat Count ====>> 1
Definition ID ====>> 0
Environment URL ====>> null
Authentication Header ====>> null

Hi Ronak,

Partial good news.

There looks to be too many sudo and not enough quotes. :slight_smile:

Have you tried:

JAVA_OPTS="-DuserCount=2 -DflowRepeatCount=3 -DdefinitionId=102168 -DtestServerUrl=https://someURL -DenvAuthenticationHeaderFromPostman=‘Basic UWRZm9aGwsxFsB1V7RXK0OlB5cmZvcm1hbmNldGVzdDE=’" ./gatling.sh

(note single quotes for -DDenvAuthenticationHeaderFromPostman, to capture the spaces in the option value)

Kind regards,
Tony.

Hi,

Yes I have tried with this (with ./gatling.sh)

`
JAVA_OPTS="-DuserCount=2 -DflowRepeatCount=3 -DdefinitionId=102168 -DtestServerUrl=‘https://someURL’ -DenvAuthenticationHeaderFromPostman=‘Basic UWRZm9aGwsxFsB1V7RXK0OlB5cmZvcm1hbmNldGVzdDE=’" ./gatling.sh

`

Gives this error,
GATLING_HOME is set to /opt/gatling-charts-highcharts-2.0.3

Error: Could not find or load main class UWRZm9aGwsxFsB1V7RXK0OlB5cmZvcm1hbmNldGVzdDE='

and If I Use this command (with **sudo bash gatling.sh)**
JAVA_OPTS="-DuserCount=2 -DflowRepeatCount=3 -DdefinitionId=102168 -DtestServerUrl='https://someURL' -DenvAuthenticationHeaderFromPostman='Basic UWRZm9aGwsxFsB1V7RXK0OlB5cmZvcm1hbmNldGVzdDE='" **sudo bash gatling.sh**

it runs but gives this input values (takes null and binary values as input)
INPUT***************
User Count ====>> 1
Repeat Count ====>> 1
Definition ID ====>> 0
Environment URL ====>> null
Authentication Header ====>> null

Hey Tony,

Again good news, almost near to solve the problem.

Got the problem where i m stuck.
Its a Space related issue in passing parameters of Authentication Header. -DenvAuthenticationHeaderFromPostman='Basic UWRZm9aGwsxFsB1V7RXK0OlB5cmZvcm1hbmNldGVzdDE='"

It gets parameter till Environment URL but when ‘Space’ comes in parameter it throws error.
INPUT***************
User Count ====>> 2
Repeat Count ====>> 3
Definition ID ====>> 10201
Environment URL ====>> https://SomeURL
Authentication Header ====>> null