Dynamic chainbuilder generation

Hello everyone, I’m trying to create a Gatling script with Java, and met with quite a big problem for me.
So this is my issue:

I have a scenario that looks like so:
.exec(ChainBuilder)
.exec(ChainBuilder)
.exec(ChainBuilder)
.exec(ChainBuilder)
.exec(function(value1)) //returns ChainBuilder, where one of the request inside uses that param .repeat(4).on(exec(function2(value1))) //returns ChainBuilder, where one of the request inside uses that parameter
.repeat(4).on(exec(function2(value2))

When function2 is called the first time it uses value1, when it is called the second time it still uses value1 and not value2

I understand that Gatling compiles methods only once, but I don’t want to create a lot of identical methods, so the question is, how can I work around it?

(I’m sorry that I didn’t provide a code, but the reason is that I can’t show endpoints and data)

Hi @Dmytro,

I’m not sure to understand what you want to achieve.

You may create a sample with same applied concept but pointing to computerdatabase (https://computer-database.gatling.io), for instance.

Are you sure? You have a repeat(4) in front of your first call. Perhaps your 2nd call is only the 2nd repeat.

For instance, based on your topic, I just wrote this simulation:

package computerdatabase;

import java.time.Duration;
import java.util.List;

import io.gatling.javaapi.core.*;
import io.gatling.javaapi.http.*;

import static io.gatling.javaapi.core.CoreDsl.*;
import static io.gatling.javaapi.http.HttpDsl.*;

public class BasicSimulation extends Simulation {

  HttpProtocolBuilder httpProtocol = http
      .baseUrl("https://computer-database.gatling.io") // Here is the root for all relative URLs
      .acceptHeader("text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8") // Here are the common headers
      .acceptEncodingHeader("gzip, deflate")
      .acceptLanguageHeader("en-US,en;q=0.5")
      .userAgentHeader("Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:16.0) Gecko/20100101 Firefox/16.0");

  static ChainBuilder function2(String computerName) {
    return exec(
        http("Request for " + computerName)
            .get("/computers")
            .queryParam("f", computerName)
    );
  }

  static ChainBuilder home = exec(
      http("Home")
          .get("/")
  );


  ScenarioBuilder scn = scenario("Sample with function2")
      .exec(home)
      .exec(function2("ace"))
      .exec(function2("amiga"))
      ;

  {
    setUp(
        scn.injectOpen(atOnceUsers(1))
    ).protocols(httpProtocol);
  }
}

And I correctly have the following result:
2022-06-02_236x266

Cheers!

The script that you wrote is identical to mine, so I guess that I’m missing something in the script that I’m writing. So I guess I will need to reconfirm everything, thank you for the pointers!