I'm currently working on conducting a load test using Gatling along with DataFaker. However, I've encountered an issue where the test code seems to be generating the same object repeatedly. This observation is based on monitoring the logs generated by the API during the test execution.
My intention is to perform a mass load test, but the repetitive object generation is hindering the accuracy of the test results. I'm wondering if anyone has faced a similar issue or could provide insights into what might be causing this behavior.
I would appreciate any suggestions or solutions to ensure that the object generation within Gatling's load test is randomized as expected. Thank you in advance for your assistance!
public class ApiSimulation extends Simulation {
private final Faker faker = new Faker(Locale.forLanguageTag("pt_BR"));
/**
* Criação do protocolo HTTP
*/
private final HttpProtocolBuilder httpProtocolBuilder = http
.baseUrl("http://localhost:8081")
.userAgentHeader("Mozilla/5.0");
/**
* Criação do cenário de inserção de dados
*/
private final ScenarioBuilder insertAlunosScenario = scenario("Inserção em massa de dados")
.feed(listFeeder(List.of(
Map.of("id", UUID.randomUUID(),
"nome", faker.name().fullName(),
"idade", faker.number().numberBetween(3, 17),
"email", faker.internet().emailAddress(),
"sexo", faker.gender().shortBinaryTypes().toUpperCase(),
"dataInsercao", LocalDateTime.now(),
"dataAlteracao", LocalDateTime.now())))
.random())
.exec(http("Criando o aluno")
.post("/alunos")
.header("Content-Type", "application/json")
.body(ElFileBody("alunoTemplate.json"))
.asJson()
.check(status().in(201, 400, 422, 500)));
{
setUp(insertAlunosScenario.injectOpen(
constantUsersPerSec(10_000).during(of(10, SECONDS))))
.protocols(httpProtocolBuilder);
}
}
My code now
public class ApiSimulation extends Simulation {
private final Faker faker = new Faker(Locale.forLanguageTag("pt_BR"));
private final Iterator<Map<String, Object>> feeder = Stream.generate(() -> {
Map<String, Object> map = new HashMap<>();
map.put("id", UUID.randomUUID());
map.put("nome", faker.name().fullName());
map.put("idade", faker.number().numberBetween(3, 17));
map.put("email", faker.internet().emailAddress());
map.put("sexo", faker.gender().shortBinaryTypes().toUpperCase());
map.put("dataInsercao", LocalDateTime.now());
map.put("dataAlteracao", LocalDateTime.now());
return map;
}).iterator();
/**
* Criação do protocolo HTTP
*/
private final HttpProtocolBuilder httpProtocolBuilder = http
.baseUrl("http://localhost:8081")
.userAgentHeader("Mozilla/5.0");
/**
* Criação do cenário de inserção de dados
*/
private final ScenarioBuilder insertAlunosScenario = scenario("Inserção em massa de dados")
.feed(feeder)
.exec(http("Criando o aluno")
.post("/alunos")
.header("Content-Type", "application/json")
.body(StringBody(
"""
{
"id": "#{id}",
"nome": "#{nome}",
"idade": "#{idade}",
"email": "#{email}",
"sexo": "#{sexo}",
"dataInsercao": "#{dataInsercao}",
"dataAlteracao": "#{dataAlteracao}"
}
"""
))
.asJson()
.check(status().in(201, 400, 422, 500)));
{
setUp(insertAlunosScenario.injectOpen(
constantUsersPerSec(10).during(of(10, SECONDS))))
.protocols(httpProtocolBuilder);
}
}
This is expected as you’re passing a singleton List. The first example in the official documentation is exactly what you’re asking for.