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:
@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}"));
}
}