Scenario picking (randomly or sequentially) from a set of POST bodies stored as files (one POST request per file) in request-bodies

Hi,

I’m trying to set up scenario where I make POST requests by picking the contents from a set of files. This is my basic scenario which works:

val scn = scenario(“Batch write”)

.exec(

http(“request_1”)

.post("/blah/batch_write")

// -rw-r–r-- 1 xxxx users 87476 Jun 17 22:14 …/…/request-bodies/5076100000

.fileBody(“5076100000”)

.headers(headers_1)

.check(status.is(200)))

.pause(0 milliseconds, 100 milliseconds)

Now I want to parameterize the fileBody. Two options I see are:

  • Using a feed

How do I set it up? My feed needs to contain these file names. Should I create a CSV file containing:

key1 file1

key2 file2

  • Using a variable as the parameter to fileBody

My POST body files are named numerically - a prefix of 50761 and an monotonically increasing 5 digit suffix. Should I just create a Scala variable that generates this number, and then, can I use that variable as a parameter to fileBody() ?

Regards,

Anil.

Both solutions are fine, just that with the feeder solution, your CSV file would have to look like:

file (header line)
file1
file2

.fileBody("${file}")

Thanks, Stephane. I tried that and got the following exception:

java.io.IOException: File /home/anile/gatling-charts-highcharts-1.5.5/user-files/request-bodies/${file} is not a file or doesn’t exist

val postData = csv(“contents.csv”)

val scn = scenario(“Batch write”)
.feed(postData)
.exec(
http(“request_1”)
.post("/foo/batch_write")
.fileBody("${file}")
.headers(headers_1)
.check(status.is(200)))
.pause(0 milliseconds, 100 milliseconds)

ls user-files/request-bodies/
5076100000 5076100001 5076100002 5076100003 5076100004

cat user-files/data/contents.csv
file
5076100000
5076100001
5076100002
5076100003
5076100004

Sorry, I didn’t realize that you were using Gatling 1.
I’m afraid you’d have to upgrade to Gatling 2.

Is the fileBody method missing in 2.x?

GATLING_HOME is set to /home/xxxx/gatling-charts-highcharts-2.0.0-SNAPSHOT

21:51:14.700 [ERROR] i.g.a.ZincCompiler$ - /home/anile/gatling-charts-highcharts-2.0.0-SNAPSHOT/user-files/simulations/foo/FooWriteSimulation.scala:33: value fileBody is not a member of io.gatling.http.request.builder.HttpRequestWithParamsBuilder

possible cause: maybe a semicolon is missing before `value fileBody’?

21:51:14.703 [ERROR] i.g.a.ZincCompiler$ - .fileBody("${file}")

21:51:14.704 [ERROR] i.g.a.ZincCompiler$ - ^

21:51:14.719 [ERROR] i.g.a.ZincCompiler$ - one error found

Compilation failed

API has changed.
The upcoming version documentation is here: https://github.com/excilys/gatling/blob/master/src/sphinx/http/http_request.rst#request-body

I tried the following:

.body(RawFileBody("${file}"))

Got:

05:25:40.171 [ERROR] i.g.h.a.HttpRequestAction - No attribute named ‘file’ is defined

Exception in thread “main” java.lang.IllegalStateException: Feeder is now empty, stopping engine

Where is your feeder call and what does the file content look like?

Same as earlier:

val postData = csv(“contents.csv”)

val scn = scenario(“Batch write”)
.feed(postData)
.exec(
http(“request_1”)
.post("/xxx/batch_write")
.body(RawFileBody("${file}"))
.headers(headers_1)
.check(status.is(200)))
.pause(0 milliseconds, 100 milliseconds)

setUp(
scn.inject(rampUsers(10) over (10 seconds)
).protocols(httpConf))

$ ls user-files/request-bodies/
5076100000 5076100001 5076100002 5076100003 5076100004

$ cat user-files/data/contents.csv
file
5076100000
5076100001
5076100002
5076100003
5076100004

So I suspect you’re not telling everything (that the first files were successfully posted) and what happens is that you run out of feeder records because you have more users that file entries. If so, default feeder strategy is queue, please checkout Feeder documentation.

Oh, yeah! You’re right.