I’m trying to use gatling for testing following use case:1) Authenticate using REST endpoint /login/ and obtain a session cookie
2) Make 100K requests to other services with this cookie
I would like to make the first request using the gatling API in order to use the same HTTP properties (proxy, e.t.c.)
I can see that build method of PopulationBuilder is private to io.gatling.core and I cannot call it directly
I’ve implemented this very type of thing before. It’s doable.
Assuming you don’t want to make 100k requests in serial, you want all your requests to be executed like a normal scenario, so you can take advantage of the traffic shaping abilities of Gatling…
Option 1: Create a thread-safe token cache object. When you request the token for the first time, it communicates with the server to fetch the token. Once it has the token, it caches it and on future requests, it returns the cached token. In the mean time, any calls to the cache looking for a token while the token is being fetched need to block.
Option 2: Fetch the token during scenario build time. You won’t be using Gatling DSL to fetch it, so you will have to implement it differently.
Option 3: Create a Gatling scenario that all it does is request the token, and writes it to a file. Then you build your test to feed the token from that file. Then when you launch your test, you launch it using a batch file or shell script which first launches the token-getter scenario, then when it completes, it launches the real test.
Option 3 is the easiest to implement, from a complexity standpoint.
I’ve even gone farther, and got access to the database and gave the token a lifetime of 1 year, so I could do it once, and then cache it, and not have to re-run the token-fetching code very often. But that’s because I needed hundreds of thousands of tokens, not just one, and the cost of creating the tokens was significant.
The first request is executed only once?
I have a similar problem, I need to grab some data first and then reused it until now I kept a static list but it’s changing too often.
I did a similar thing
Hi Lukasz,
I think with your code example you need to input 1 user in setup, then it will fetch filterList once, and then generate the number of requests of length of filterList.
You can try to divide your requests to separate ChainBuilder objects and pass the values between two sessions by saving fetched list to external object:
Then you can have different number of users for them. I think this scheme is good enough for authorisation (fetching token), but for similar situation as yours I use saving to files and running simulations in sequence, as you can use standard csv feeder then.