Does feeder allow EL variables?

Gatling version: 3.10.4
Gatling flavor: [ x] java kotlin scala javascript typescript
Gatling build tool: maven [ x] gradle sbt bundle npm

I made sure I’ve update my Gatling version to the latest release
I read the guidelines and how to ask a question topics.
I provided a SSCCE (or at least, all information to help the community understand my topic)
I copied output I observe, and explain what I think should be

I have a need to select the appropriate feeder for a user based on a value parsed from the login response.

I create feeders stored in a HashMap<String, FeederBuilder> in my code so that the appropriate feeder can be selected based on the String value.

I am trying to find the technique needed to select the appropriate feeder after user login, and then use this feeder for http request data later on.

All the techniques I have tried have failed, I think because the EL variable I reference from the session does not get replaced with the value of the variable in the feed(“#{variable}”).

My first question is can EL can be used in feed()?

If so, I will need to pursue what I am doing wrong.

If no, what approaches are available to solve my problem? I have an inelegant solution working that doesn’t use a feeder, but rather just a Map read in a session block. That sets variables directly in the session that are used for my http requests.

I save one of the FeederBuilder in my session after login. I verify that the feeder has rows and can be referenced, at least in a session block. If the feeder is saved in my session with

Session newSession = session.set(“feederName”, feeder);
return session;

I attempt to reference it in my script with feeder(“#{feederName}”);

I have also tried feed(session → session.get(“feederName”);

I always get an error like:
Cannot invoke “io.gatling.javaapi.core.FeederBuilder.asScala()” because “feeder$6” is null

I know the feeder is not null because I can reference it in session blocks and see the feeder.recordsCount() is non-zero in the session.

Hello,

How are you? In order to better understand the situation, can you share with us a POC?

Hi Samir.

I realize my “end of day” post last night isn’t the clearest and needs more precision.
My basic issue remains though: should I be able to use feeder(…) where I use a session variable in the feeder argument. If so, how.

Below is a more precise description of what I have done that has not worked.
I think what follows are the relevant code excerpts:

I create my feeders:

    Set<String> dataSet = Set.of("dataId1","dataId2");
    Map<String, FeederBuilder<Object>> populatedDataFeeders = new HashMap<>();
    //===================
    for (String dataId : dataSet) {

        FeederBuilder<Object> dataFeeder = jdbcFeeder(
            "jdbc:drvr://localhost:8080",
            System.getenv("username"),
            System.getenv("password"),
            "select att1, att2 from dataTable where dataId = '" + dataId + "'");

        populatedDataFeeders.put(dataId, dataFeeder);
    }

I parse a user’s dataId from login:

        http("Login")
            .post("/login")
            .formParam("username", "user")
            .formParam("password", "password")
        .check(jsonPath("$..dataId").saveAs("dataId"))

I can see that the correct value for dataId is stored in the session.

I can see that my feeders contain data. I put the following in a session block to verify I could get a feeder and that it had data:

String dataId = session.get(“dataId”);
FeederBuilder<Object> dataFeeder = populatedDataFeeders.get(dataId);
logger.info(“feederSize: {}”, dataFeeder.recordsCount());
Session newSession = session.set(“dataFeeder”, dataFeeder);
return newSession;

Then I try to use the dataId to choose which feeder to use, or use the saved feeder:


.feed(“#{dataFeeder}”)

This gets the compiler error "Cannot resolve method 'feed(String)

If I try


.feed(networkFeeders.get(“#{dataFeeder}”)

I get:
java.lang.NullPointerException: Cannot invoke “io.gatling.javaapi.core.FeederBuilder.asScala()” because “feeder$5” is null

I assume because the EL variable is not substituted for in the HashMap get() and what is returned is in fact null because there is no key “#{dataFeeder}” in the hashmap.

If I try


.feed(session → session.get(“dataFeeder”))

I get compiler errors: “Cannot resolve method ‘feed’ in ‘ChainBuilder’”
and also “Cannot resolve method ‘get(String)’”

No, you can’t use Gatling EL anywhere you want, as explained in the documentation: Gatling session scripting reference - Expression Language

As the documentation states, Gatling EL only works when passing a String to the Gatling methods that accept such Strings.

.feed(“#{dataFeeder}”) won’t work, as feed doesn’t take a String parameter.

networkFeeders.get(“#{dataFeeder}”) will return null as HashMap#get won’t magically resolve Gatling EL.

In short, you can’t do it this way.
What you can do is having a doSwitch to branch on the desired feeder.

Thanks for the definitive answer. And thanks for providing a useful alternative. I’ll have to investigate how we might use this approach for our general case.

For now, I have found an alternate approach for selecting and pulling data from a Map<String, List<Map, Object>> inside of a Gatling session block: session → {…}. I can save the session variables I need there and use them like they came from a feeder.

Thanks for your help.

Is there any chance of the EL someday allowing the use of non-string session objects such as

feed(#{dataFeeder})

where dataFeeder is a FeederBuilder object?

Honestly no, feed will never take an EL String.