is there an EL function to generate UUID using java in Gatling
I’m not sure if my proposition is optimal but I would do it in this way:
import io.gatling.javaapi.core.ScenarioBuilder;
import io.gatling.javaapi.core.Simulation;
import io.gatling.javaapi.http.HttpProtocolBuilder;
import java.util.Collections;
import java.util.Iterator;
import java.util.Map;
import java.util.UUID;
import java.util.function.Supplier;
import java.util.stream.Stream;
import static io.gatling.javaapi.core.CoreDsl.atOnceUsers;
import static io.gatling.javaapi.core.CoreDsl.scenario;
import static io.gatling.javaapi.http.HttpDsl.http;
public class FunWithFeederUUIDSimulation extends Simulation {
HttpProtocolBuilder httpProtocol = http;
Iterator<Map<String, Object>> feederUUID =
Stream.generate((Supplier<Map<String, Object>>) () -> {
String uuidString = UUID.randomUUID().toString();
return Collections.singletonMap("uuidString", uuidString);
}
).iterator();
ScenarioBuilder scn =
scenario("Scenario Name")
.feed(feederUUID)
.exec(session -> {
System.out.println("GeMi_session: " + session.toString());
System.out.println("GeMi_feederUUID_uuidString: " + session.get("uuidString"));
return session;
});
{
setUp(scn.injectOpen(atOnceUsers(10)).protocols(httpProtocol));
}
}
Thank you @GeMi . I tried this similar code. But this one is working well.
1 Like
I’ve filled a feature ticket for this: Core: add random generators to Gatling EL · Issue #4305 · gatling/gatling · GitHub
Contributions welcome.
1 Like