Using feeders to construct a StringBody (2.0.0-M3a)

1,690 views
Skip to first unread message

Hank

unread,
Oct 21, 2013, 4:19:54 PM10/21/13
to gat...@googlegroups.com
Okay, I've got another feeder/http POST body question.  Thank you for all of your help so far - Gatling is an awesome tool, and I feel like I'm so close to getting it to work for our project.  

I'm continuing to work on my registration load test, and now I'm running into the following issue when attempting to use a feeder to generate my JSON POST body - some lines don't seem to be correctly handling double quotes in my CSV file.  (Of three requests, one worked, two mysteriously didn't.)

Relevant script pieces:
val userData = csv("test.csv").queue

val httpConf = http.baseURL("http://myappurl.com/api")

val scn = scenario("Register user")
.feed(userData)
.exec(
http("POST registration")
.post("/user/register")
.headers(headers_1)
.body(StringBody("""{"username":${username}, "email":${email}, "imei":${imei}, "gcmId":${gcmId}, "age":${age},"albumSelection":${albumSelection},"latitude":${latitude},"longitude":${longitude},"emailOptIn":${emailOptIn},"termsOptIn":${termsOptIn} }""")))

My CSV file looks like this:
username,emailOptIn,albumSelection,termsOptIn,age,gcmId,longitude,latitude,imei,email
""tester7105408553"",true,""clean"",false,""62"",""7105408553"",0,45,""999997105408553"",""tester71...@mailinator.com""
""tester7317165156"",true,""clean"",true,""59"",""7317165156"",176,65,""999997317165156"",""tester73...@mailinator.com""
""tester6271383680"",true,""explicit"",true,""37"",""6271383680"",-42,-82,""999996271383680"",""tester62...@mailinator.com""

It seems like everything is correct there, but when I run with logging turned on, I see the following messages:

Session:
Session(Register user,1,Map(latitude -> 65, email -> "tester73...@mailinator.com", username -> tester7317165156", imei -> "999997317165156", age -> "59", longitude -> 176, termsOptIn -> true, emailOptIn -> true, gcmId -> "7317165156", albumSelection -> "clean"),1382385464346,0,List(),List(KO),List(),List())
=========================
HTTP request:
headers=
Content-Type: [application/JSON]
stringData={"username":tester7317165156", "email":"tester73...@mailinator.com", "imei":"999997317165156", "gcmId":"7317165156", "age":"59","albumSelection":"clean","latitude":65,"longitude":176,"emailOptIn":true,"termsOptIn":true }


Session:
Session(Register user,2,Map(latitude -> -82, email -> "tester62...@mailinator.com", username -> tester6271383680", imei -> "999996271383680", age -> "37", longitude -> -42, termsOptIn -> true, emailOptIn -> true, gcmId -> "6271383680", albumSelection -> "explicit"),1382385464346,0,List(),List(KO),List(),List())
=========================
HTTP request:
headers=
Content-Type: [application/JSON]
stringData={"username":tester6271383680", "email":"tester62...@mailinator.com", "imei":"999996271383680", "gcmId":"6271383680", "age":"37","albumSelection":"explicit","latitude":-82,"longitude":-42,"emailOptIn":true,"termsOptIn":true }


Session:
Session(Register user,0,Map(latitude -> 45, email -> "tester71...@mailinator.com", username -> "tester7105408553", imei -> "999997105408553", age -> "62", longitude -> 0, termsOptIn -> false, emailOptIn -> true, gcmId -> "7105408553", albumSelection -> "clean"),1382385464345,0,List(),List(OK),List(),List())
=========================
HTTP request:
headers=
Content-Type: [application/JSON]
stringData={"username":"tester7105408553", "email":"tester71...@mailinator.com", "imei":"999997105408553", "gcmId":"7105408553", "age":"62","albumSelection":"clean","latitude":45,"longitude":0,"emailOptIn":true,"termsOptIn":false }

I don't understand why this is only sometimes failing.  The first two requests are not correctly placing the first quote on the username in the JSON, and are (correctly) getting a 500 error from the server, the last one is, and (correctly) registers the user.

Any thoughts or suggestions are much appreciated.

Thanks,
Hank

Stéphane Landelle

unread,
Oct 21, 2013, 4:34:56 PM10/21/13
to gat...@googlegroups.com
Hi,

Except if gmail did something funny with your original message, it seems your csv file is still messed up: double quotes inside a field have to be escape, and the whole field has to be surrounded with double quotes:
  • ""tester7105408553"" => bad
  • "\"tester7105408553\"" => good
We use opencsv underneath, and it silently does weird stuff with malformed csv.

Anyway, why don't you handle JSON string value quotes inside your JSON template?

You csv file would look like:
username,emailOptIn,albumSelection,termsOptIn,age,gcmId,longitude,latitude,imei,email
tester7105408553,true,clean,false,62,7105408553,0,45,999997105408553,tester71...@mailinator.com


and your template like this:
"""{
  "username":"${username}",
  "email":"${email}",
  "imei":"${imei}",
  "gcmId":"${gcmId}",
  "age":"${age}",
  "albumSelection":"${albumSelection}",
  "latitude":${latitude},
  "longitude":${longitude},
  "emailOptIn":${emailOptIn},
  "termsOptIn":${termsOptIn}
}"""

WDYT?




2013/10/21 Hank <henry....@gmail.com>

--
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/groups/opt_out.

Hank

unread,
Oct 21, 2013, 6:32:29 PM10/21/13
to gat...@googlegroups.com
That totally did the trick - I based the "double double quotes" off of some random CSV documentation I found, but your solution is better and more elegant, and works, to boot.

Thanks again for the prompt responses, much appreciated.

Thanks,
Hank


On Monday, October 21, 2013 1:34:56 PM UTC-7, Stéphane Landelle wrote:
Hi,

Except if gmail did something funny with your original message, it seems your csv file is still messed up: double quotes inside a field have to be escape, and the whole field has to be surrounded with double quotes:
  • ""tester7105408553"" => bad
  • "\"tester7105408553\"" => good
We use opencsv underneath, and it silently does weird stuff with malformed csv.

Anyway, why don't you handle JSON string value quotes inside your JSON template?

You csv file would look like:
username,emailOptIn,albumSelection,termsOptIn,age,gcmId,longitude,latitude,imei,email
tester7105408553,true,clean,false,62,7105408553,0,45,999997105408553,tester710540855...@mailinator.com


2013/10/21 Hank <henry....@gmail.com>
""tester6271383680"",true,""explicit"",true,""37"",""6271383680"",-42,-82,""999996271383680"",""tester6271383...@mailinator.com""

Stéphane Landelle

unread,
Oct 22, 2013, 3:16:16 AM10/22/13
to gat...@googlegroups.com
Was glad to help :)

Have fun!



2013/10/22 Hank <henry....@gmail.com>
Reply all
Reply to author
Forward
0 new messages