Dynamic feeder population during simulation

Hi team,
Before starting simulation, I’m populating my feeder with auth tokens. But those tokens have 1 hour ttl and there is no ability to extend them.
In static block I have method that initializes a feeder with tokens received from auth service, after this actual scenario is started.
So to run my test more than 1 hour I need somehow to remove old tokens and add new ones, or substitute old feeder with new one by using same Java code as in generateTokensFeeder(); .
Do you have any ideas how to do that?
My code:

public class SearchSimulationv2 extends Simulation {
    private static final Env GATLING_ENV = new Env();
    private FeederBuilder<Object> tokensFeeder;
    private ServiceApiCalls serviceApiCalls = new ServiceApiCalls();
    private FeederBuilder<Object> queriesFeeder = listFeeder(
                    Map.of("query", "Foo"),
                    Map.of("query", "Bar")
    private Map<String, String> requestHeaders = Map.of(
            "Content-Type", "application/json",
            "Host", GATLING_ENV.getHost(),
            "Authorization", "#{jwtToken}"

        tokensFeeder = generateTokensFeeder(); // inside this method I'm calling auth service for the tokens for my users and then create a feeder 

    private ScenarioBuilder getSearchScenario() {
        return scenario("API Test")

Hi @Vadam,

As explained in the first part of the Feeder documentation, Feeder is merely a rebrand of an Iterator<Map<String, Object>>.
So you may implement one yourself.

For your specific use case, you may want that such an implementation rely on a global variable shared by your current scenario and another scenario that refresh the token when needed.
In your “user” scenario, before each request that requires this token, you may want to feed it (to be sure to be up to date).

In the other hand, it means that your tokens are not linked to a user, so maybe manipulating directly the global variable may be more suitable.
Did you read the topic about that and the wonderful implementation by @GeMi?



This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.