Java - Get value out of the feeder

Hello Stephan,

I have implemented the Gatling code in a function and called it from the main class. I need to get the value out of the feeder and send it to the function. Following is the sample code. Request your help on the same.

Iterator<Map<String, Object>> feeder1 =
Stream.generate((Supplier<Map<String, Object>>) () → {
int num = (int)Math.floor(Math.random()*(100-10+1)+10);
return Collections.singletonMap(“number”, num);
}
).iterator();

private ScenarioBuilder scn = scenario(“homePage”)
.feed(feeder1)
.exec(http(“Page”).get("/computers?p=#{number}"));
.exec(gotoPage(2)) //Want to replace 2 with #{number}

Regards,
Bharath.

Then your goto method can’t take an Int. Make it take a String or a Function.

Moreover, you should probably switch to Java instead of Scala.

Thank you, Stephan, I have fixed it. I am using Java only.

I have observed that you are suggesting using Java than Scala. May I know the reason?
In one of the youtube videos, you told that Java compilation is faster than Scala. Any differences between Java & Scala in terms of code execution?

Following is the working code.

Iterator<Map<String, Object>> feeder1 =
Stream.generate((Supplier<Map<String, Object>>) () → {
int num = (int)Math.floor(Math.random()*(100-10+1)+10);
return Collections.singletonMap(“number”, String.valueOf(num));
}
).iterator();

private ScenarioBuilder scn = scenario(“homePage”)
.feed(feeder)
//.exec(homePage())
.exec(gotoPage("#{number}"))
.exec(http(“Page”).get("/computers?p=#{number}"));

Regards,
Bharath.

I have observed that you are suggesting using Java than Scala. May I know the reason?