Custom feeder that fetches data from an API

Hey,

I have a requirement where I need to fetch a password from an API and use it as payload in an authentication request.

I’m using a custom feeder for the purpose. Something like this

val passwordFeeder= Iterator.continually(Map(“password” → getPassword()))

and then

feed(passwordFeeder)

However as I understand every call to the “feed” method will make a call to the , I want to avoid this since its a system outside the test scope, which shouldn’t be receiving this extra traffic.

How can I modify the behavior to feed once and use the data repeatedly.

regards,
Aju

Hey,

Iterator.continually takes a “called by name“ parameter.
If I understood correctly, you want to call getPassword once.
You can do so by having your password value retrieved before creating your feeder.

val password = getPassword(<API URL>)
val passwordFeeder = Iterator.continually(Map("password" -> password))

// ...

feed(passwordFeeder)

Cheers!

Then, you have to understand that feeders are meant to be able to immediately return data, typically from memory, or worst case scenario from local fast disk.
If you’re performing a blocking network call every time your feeder is trying to fetch a record, you’re going to kill performance. If that’s what you’re trying to achieve, you should use a silent Gatling request instead.

Thanks Sebastian, it seems fairly obvious looking at it now :slight_smile:

@Stephane - Sebastian’s suggestion would work just fine, the getPassword function is called once and the value is stored in a variable (in memory) and the value is retrieved from memory there on, without making expensive calls over the network for each record fetch.