Passing command line parameter to the simulation

3,824 views
Skip to first unread message

chaitali phadnis

unread,
Jul 7, 2014, 4:53:10 PM7/7/14
to gat...@googlegroups.com
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

Stéphane Landelle

unread,
Jul 7, 2014, 5:50:17 PM7/7/14
to gat...@googlegroups.com
Probably, but hard to tell as long as you don't share what you've done.


--
You received this message because you are subscribed to the Google Groups "Gatling User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gatling+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

chaitali phadnis

unread,
Jul 7, 2014, 7:32:56 PM7/7/14
to gat...@googlegroups.com
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


Stéphane Landelle

unread,
Jul 8, 2014, 2:01:24 AM7/8/14
to gat...@googlegroups.com
This should be working. Which version do you use?


2014-07-08 1:32 GMT+02:00 chaitali phadnis <phadnis...@gmail.com>:
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


pandya ronak

unread,
Jun 27, 2016, 3:29:42 AM6/27/16
to Gatling User Group
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

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

Tony Cruickshank

unread,
Jun 27, 2016, 4:39:28 AM6/27/16
to gat...@googlegroups.com
Hi Pandya,

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

JAVA_OPTS="-DuserCount=5 -DflowRepeatCount=5 -DdefinitionId=10220101 -DtestServerUrl='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.

--
You received this message because you are subscribed to the Google Groups "Gatling User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gatling+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Intelligence is free. Wisdom comes at a cost.

pandya ronak

unread,
Jun 27, 2016, 5:58:22 AM6/27/16
to Gatling User Group
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

Tony Cruickshank

unread,
Jun 27, 2016, 6:31:03 AM6/27/16
to gat...@googlegroups.com
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 <classpath>, you might want to add -m to avoid the prompts for name & description.

Regards,
Tony.

pandya ronak

unread,
Jul 4, 2016, 9:21:34 AM7/4/16
to Gatling User Group
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.

pandya ronak

unread,
Jul 4, 2016, 9:44:04 AM7/4/16
to Gatling User Group
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 --------------------------------------------------------------------

> No attribute named 'definitionId' is defined                        1 (100.0%)

================================================================================

Thanks.

Tony Cruickshank

unread,
Jul 6, 2016, 5:50:26 AM7/6/16
to gat...@googlegroups.com
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.

pandya ronak

unread,
Jul 8, 2016, 5:49:51 AM7/8/16
to Gatling User Group
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

Tony Cruickshank

unread,
Jul 8, 2016, 7:17:22 AM7/8/16
to gat...@googlegroups.com

Our emails crossed in the ether :) Hopefully you've received my direct reply.

pandya ronak

unread,
Jul 13, 2016, 3:11:57 AM7/13/16
to Gatling User Group
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 :-(

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
***********************************************************

Thanks,
Ronak

Tony Cruickshank

unread,
Jul 13, 2016, 4:29:43 AM7/13/16
to gat...@googlegroups.com
Hi Ronak,

Partial good news.

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

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.

pandya ronak

unread,
Jul 13, 2016, 4:46:43 AM7/13/16
to Gatling User Group
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
***********************************************************

Thanks.

pandya ronak

unread,
Jul 13, 2016, 8:26:33 AM7/13/16
to Gatling User Group
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
***********************************************************

Is there any solution to remove space error?

Thanks,
Ronak
Reply all
Reply to author
Forward
0 new messages