for my test scenario with 10 or 100 users at once, I need for every user different numbers for my REST request.
User 1 gets the numbers 1 to 10 and User 2 needs to get higher numbers, for example 11-20 and so on.
How can I achieve that?
All of the 10 or 100 users are performing the same put request with different JSON Body and I need to get different numbers for my REST call.
.set("number", session("counter").validate[Int].map(i => i + 1).get).set("switch", switch))
.exec(http("""Add Flow ${number} on ${switch}""")
.put("""/restconf/config/opendaylight-inventory:nodes/node/${switch}/table/0/flow/${number}""")
//.headers(headers)
.body(StringBody("${FlowBody}")))
}
This is how my code looks like so far and I need change ${number} in every request and it should be unique over the different users I am injecting.
Is it possible to generate numbers in the range from 1 to 20 for 2 users, where each user gets different numbers? User 1 gets the numbers 1 to 10 and User 2 gets the numbers 11-20.
How can I wrap an atomicHeader around my .exec in order to increase the email by 1 / add 1, then 2 and so forth for each user and the same for MobileNumber?
Think of the AtomicInteger as a memory address with an API. Right before you do your exec(), you would have an exec( session => { … } ) block which updates the session with the next unique ID using the AtomicInteger. For specific syntax, read up on AtomicInteger.
Thanks, but how do I get to put it into my request body as a parameter? Can I refer it as a regular parameter within the request body as I do when using a feeder?
And,
Can I combine a static value with the atomic integer value. I just need unique email addresses and I want to say combine thisadress with ${theAtomicValue} @ myemail.com
as thisadress${theAtomicValue}@myemail.com within the request body? What would be the syntax then?
This isn’t that complicated. The AtomicInteger is just that, an integer. You may do with it what you want.
HOWEVER: you are not going to reference the atomic integer directly from within EL. EL only pulls from the session. You need to create code that queries the AtomicInteger, and constructs an appropriate value, and then stores that in the session, so you can then reference the session value inside your request body.
To set a value: session.set(‘key’,‘value’)
To get a value: session(‘key’).as[Type]
Where do you see a Map? So why does unique_email return a Map? Which part of the above is unique_email() intended to be substituted into? So, which type should it return?
However I do not understand what you mean by:
“You need to create code that queries the AtomicInteger, and constructs an appropriate value, and then stores that in the session, so you can then reference the session value inside your request body.”
Do I need to create separate code to get the “my_var” and then put that value into the session and then refer that (in session) value within the request body?
I was deliberately vague, because this is one of those things where there are many different ways to accomplish the same goal. For example, if your payload is an EL file, you could do either of these:
Which one you choose determines the code that you write. You can either query the AtomicInteger and set the email_counter session variable (the easiest solution), or you can do a more complicated expression that builds the whole email address and stores it in the session. It is six of one, half-dozen of the other, so it doesn’t MATTER which you choose. You may even get creative and come up with something entirely different.
Point is, know what you are trying to accomplish, understand the steps involved, and then code them. Right?