UrlEncode queryParams and Ids per User

1,159 views
Skip to first unread message

Annie

unread,
Dec 11, 2013, 3:49:59 PM12/11/13
to gat...@googlegroups.com
I'll start with I'm new to both Gatling and Scala, and I'm using Gatling-1.5.3

I'm having two issues with a scenario I'd like to create.  The basic setup is this:

val divisionScn = scenario("Division CRUD")
.exec(
http("Create Division")
.get("/division/add")
.queryParam("parameters", java.net.URLEncoder.encode("""[{"divisionName":"Perf Test Division","divisionCode":"DivCode-${id}"]""", "UTF-8"))
.check(status.is(200))
)
.pause(0 milliseconds, 5 milliseconds)
.exec (
http("Update Division")
.get("/division/update")
.queryParam("parameters", java.net.URLEncoder.encode("""[{"divisionName":"Update name","divisionCode":"DivCode-${id}"]""", "UTF-8"))
.check(status.is(200))
)
.pause(0 milliseconds, 5 milliseconds)
.exec (
http("Delete Division")
.get("/division/delete")
.queryParam("parameters", java.net.URLEncoder.encode("""[{"divisionCode":"DivCode-${id}"]""", "UTF-8"))
.check(status.is(200))
)

For each user, I'd like to increment an ID that becomes part of the division identifier "divisionCode".  I've found some examples of using AtomicInteger for that, which I am trying to use on the session, but I can't figure out if it is working because it seems that encode method is executed at compile time and not at runtime, so I end up with requests that look like this:


instead of the id being replaced.

I've tried so many things and I can't tell if I'm getting hung up on Scala or Gatling.  Any advice greatly appreciated.

Annie

Nicolas Rémond

unread,
Dec 11, 2013, 3:58:14 PM12/11/13
to gat...@googlegroups.com
"it seems that encode method is executed at compile time and not at runtime"
Absolutely.

Simply, do you call it? Gatling is managing that.


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

Annie

unread,
Dec 11, 2013, 4:08:36 PM12/11/13
to gat...@googlegroups.com
Right after I posted, I found something that helped me out.  I changed

.queryParam("parameters", java.net.URLEncoder.encode("""[{"divisionName":"Update name","divisionCode":"DivCode-${id}"]""", "UTF-8"))

to

.queryParam("parameters", (s:Session) => java.net.URLEncoder.encode("""[{"divisionName":"Perf Test Division","divisionCode":"DivCode-"""+s.userId.toString+""""]""","UTF-8"))

and that seems to work.

I'm not sure how to answer the question "do you call it".  I was getting UrlEncode errors when trying this:
   .queryParam("parameters", """[{"divisionName":"PerfTest Division","divisionCode":"PerfDivision"}]""")
which is why I added the call to  java.net.URLEncoder.encode

Stéphane Landelle

unread,
Dec 11, 2013, 4:15:54 PM12/11/13
to gat...@googlegroups.com
Yes, that's the way.
With your first tentative, the sequence was:
  1. simulation loading: URLEncoder.encode
  2. simulation loading: EL compiler triggered, but characters such as curly braces have been encoded, so it's just compiled into a function that returns a constant string
  3. every time a user reaches this action, the function is resolved, but the result is just a constant
If you want dynamic stuff, you have to either pass a function, or an EL string. AND you cannot use EL inside a function.


2013/12/11 Annie <ahudd...@gmail.com>

Annie

unread,
Dec 11, 2013, 4:20:19 PM12/11/13
to gat...@googlegroups.com
Thanks for the explanation and the quick response!

Nicolas Rémond

unread,
Dec 11, 2013, 4:54:43 PM12/11/13
to gat...@googlegroups.com
What is the error you got ?
And also, just to be sure, in your Gatling config file, "useRawUrl" is correctly set to false ?  

thanks.

Stéphane Landelle

unread,
Dec 12, 2013, 1:14:46 AM12/12/13
to gat...@googlegroups.com
Just providing some explanations about Nicolas' questions: async-http-client (the library Gatling uses underneath) is supposed to take care on encoding query parameters, expect if you disabled the feature and set useRawUrl to true. So, you shouldn't have to encode yourself.

I tested with 1.5.3 and master:

exec(http("Search")
.get("/computers")
.queryParam("""f""",  """[{"divisionName":"PerfTest Division","divisionCode":"PerfDivision"}]"""))

properly sends:
GET /computers?f=%5B%7B%22divisionName%22%3A%22PerfTest%20Division%22%2C%22divisionCode%22%3A%22PerfDivision%22%7D%5D HTTP/1.1


2013/12/11 Nicolas Rémond <nicolas...@gmail.com>

Annie

unread,
Dec 12, 2013, 10:20:52 AM12/12/13
to gat...@googlegroups.com
I went back to see what error I was getting, because I don't want to have to do the extra encoding.  Looks like I caused my own error and unfortunately spent the day trying to "fix" it.  Amazing what becomes obvious after a good nights sleep.  

Before I changed the logging levels to see the request I tried something with requestInfoExtractor, and I guess I got it wrong, saw the encoding exception and jumped to conclusions.  At least I learned some things along the way.

Thanks for your help.

Nicolas Rémond

unread,
Dec 12, 2013, 10:22:40 AM12/12/13
to gat...@googlegroups.com
That's good news.
Thanks for the heads up.

cheers
Nicolas
Reply all
Reply to author
Forward
0 new messages