# Dynamic feeder population during simulation

**URL:** <https://community.gatling.io/t/dynamic-feeder-population-during-simulation/8624>\
**Category:** Gatling (Open-Source)\
**Created:** [January 12, 2024, 3:10pm UTC](https://community.gatling.io/t/dynamic-feeder-population-during-simulation/8624 "2024-01-12T15:10:21Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vadam](https://avatars.discourse-cdn.com/v4/letter/v/4af34b/32.png) [@Vadam](https://community.gatling.io/u/Vadam)\
**Post date:** [January 12, 2024, 3:10pm UTC](https://community.gatling.io/t/dynamic-feeder-population-during-simulation/8624/1 "2024-01-12T15:10:21Z")

</div>

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:

```auto

@Slf4j
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(
            List.of(
                    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 
        setUp(getSearchScenario().injectOpen(
                        rampUsersPerSec(1).to(50).during(3),
                        constantUsersPerSec(50).during(Duration.ofMinutes(120))
                )
                .protocols(http.baseUrl(GATLING_ENV.baseUrl()).headers(requestHeaders)));
    }

    private ScenarioBuilder getSearchScenario() {
        return scenario("API Test")
                .feed(tokensFeeder.circular())
                .feed(queriesFeeder.random())
                .exec(serviceApiCalls.getSearch("#{query}"));
    }
}

```

---

<div class="post-metadata">

**Author:** ![sbrevet](https://dub1.discourse-cdn.com/flex013/user_avatar/community.gatling.io/sbrevet/32/830_2.png) [@sbrevet](https://community.gatling.io/u/sbrevet)\
**Post date:** [January 12, 2024, 3:22pm UTC](https://community.gatling.io/t/dynamic-feeder-population-during-simulation/8624/2 "2024-01-12T15:22:25Z")

</div>

Hi @Vadam,

As explained in the first part of the [Feeder](https://docs.gatling.io/gatling/reference/current/core/session/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](https://community.gatling.io/t/token-refresh-java-example/7935)?

Cheers!

---

<div class="post-metadata">

**Author:** ![system](https://europe1.discourse-cdn.com/flex013/uploads/gatling2/original/2X/b/b148e0742de35c6280726cabf3ecd3de2d320f63.png) [@system](https://community.gatling.io/u/system)\
**Post date:** [February 11, 2024, 3:22pm UTC](https://community.gatling.io/t/dynamic-feeder-population-during-simulation/8624/3 "2024-02-11T15:22:57Z")

</div>

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