POSTing a random file in a scenario

My gatling script creates a set of users (5) and then each user iterates over a loop 20 times. The contents of the loop issues a single http request.

The http request is a POST request to a rest web service.

I have a directory with 1000 request bodies. How do I grab one of those files to post (e.g. the parameter to the fileBody() method call)?

I’ve tried the following using feed(), but it just tries to load a file that that includes the expression literally (not replacing it with a value from the csv file) – e.g. http://myhost.mycompany.com:8080/my-rest-service

My csv file listing all my data files looks like this:

filename
file123.txt
file456.txt

Essentially, I do three things:

  • load the csv file with the list of all my files containing http post contents:

  • val fileList = csv(“file_listing__separated_smaller.csv”).concurrentQueue- call feed() with this fileList variable as a parameter

  • .feed(fileList)- call the fileBody() method

  • .fileBody("${filename}")

Attempted script contents:

val httpConf = httpConfig
.baseURL(“http://myhost.mycompany.com:8080”)
.acceptHeader("/")
.userAgentHeader(“curl/7.21.4 (universal-apple-darwin11.0) libcurl/7.21.4 OpenSSL/0.9.8r zlib/1.2.5”)
.warmUp(“http://myhost.mycompany.com:8080”)

val headers_1 = Map(
“Content-Type” → “”“text/plain”"",
“Expect” → “”“100-continue”"",
“Proxy-Connection” → “”“Keep-Alive”""
)

val fileList = csv(“file_listing.csv”).concurrentQueue

val scn = scenario(“Scenario Name”)
.feed(fileList)
.repeat(20)
{
exec(
http(“request_1”)
.post("/my-rest-service")
.headers(headers_1)
.fileBody("${filename}")
)
.pause(3)
}

setUp(scn.users(5).protocolConfig(httpConf))

Thanks!
Matt

Hi,

Bad luck: that’s not currently possible, the template location is static.
Could you fill an issue, please?

We should be able to have it for 1.4.3 coming next week.

Cheers,

Stéphane

I actually implemented it on the master/v2 branch.
This part has gone under major refactoring, so backporting is not straightforward.
Would it be possible for you to use a 2.0.0-SNAPSHOT?

You can grab one on Cloudbees:
https://forge.cloudbees.com/a/gatling/

Available methods are now:

  • body for passing a String
  • rawFileBody
  • fileBody for passing a template file that uses Gatling EL
  • sspBody for passing a SSP template
  • byteArrayBody
    Cheers,

Stéphane

Perfect Stéphane!! Thanks so much! Yes, I’ll pull and use the 2.0.0-SNAPSHOT!

Glad I asked!

Thanks for your help!
Matt

Do you have instructions on how to use the snapshot version? I see that I can grab the individual jars for each gatling module from the maven repo, but I don’t see a complete download .tar.gz.

I also tried grabbing the trunk code from git and running “mvn package” (which also build the individual module jars).

Is there a command to produce the bundle .tar.gz?

Or can I just take my 1.4.1 binary directory and delete all the gatling*.jar files and replace them with the 2.0-SNAPSHOT versions? (I suspect some of the other dependencies might need to be updated too).

Thanks for your help!

Matt

The bundles are in the repo too:
http://repository-gatling.forge.cloudbees.com/snapshot/com/excilys/ebi/gatling/highcharts/gatling-charts-highcharts/2.0.0-SNAPSHOT

You’ll probably have to delete your gatling-recorder.ini, it might not be compatible.

Cheers,

Stéphane