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:
.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
Yes, that’s the way.
With your first tentative, the sequence was:
simulation loading: URLEncoder.encode
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
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.
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 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.