Java - Get value out of the feeder.

587 views
Skip to first unread message

Bharath Marrivada

unread,
Feb 16, 2022, 4:32:33 AM2/16/22
to Gatling User Group
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.


Stéphane LANDELLE

unread,
Feb 16, 2022, 4:57:34 AM2/16/22
to gat...@googlegroups.com
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.

--

Stéphane Landelle

Chief Technical Officer

   

slan...@gatling.io
gatling.io
   
facebook twitter linkedin 


--
You received this message because you are subscribed to the Google Groups "Gatling User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gatling+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/gatling/d5deff8f-03e9-4316-a06c-6e3e8deeaa4bn%40googlegroups.com.

Bharath Marrivada

unread,
Feb 16, 2022, 5:26:38 AM2/16/22
to Gatling User Group
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.

Stéphane LANDELLE

unread,
Feb 16, 2022, 4:16:41 PM2/16/22
to gat...@googlegroups.com
I have observed that you are suggesting using Java than Scala. May I know the reason?

The main reason is adoption, eg from the rest of your organization.
Some people will be reluctant to even try learning the basics of a new language.
Currently, the Java API is built on top of the Scala one, so there's a small overhead, but it will go unnoticed to most users.


--

Stéphane Landelle

Chief Technical Officer

   

slan...@gatling.io
gatling.io
   
facebook twitter linkedin 
Reply all
Reply to author
Forward
0 new messages