Foreach issues ...

663 views
Skip to first unread message

aditya siram

unread,
Jul 19, 2016, 2:14:51 PM7/19/16
to Gatling User Group
Hi all,
I'm trying to use `foreach` to build up a scenario where I POST each item in a sequence but running the following error:
[error]  found   : io.gatling.http.request.builder.HttpRequestBuilder
[error]  required: io.gatling.commons.validation.Validation[io.gatling.core.session.Session]

Here's the scenario:
  val xs = 1 to 10
  val scn = scenario("Test")
    .foreach(xs, "x") {
      exec(session => {
        val x = session("x").as[Integer]
        http("sendTest")
          .post("/blah/")
          .body(StringBody(s"${x}"))
          .check(status.is(200))
      })
    }

I feel like I'm doing something obviously wrong but I can't seem to understand how to fix this from the documentation.

Thanks!
-deech

aditya siram

unread,
Jul 19, 2016, 2:38:24 PM7/19/16
to Gatling User Group
I got past that error by doing:
  val xs = (1 to 10)

  val scn = scenario("Test")
    .exec(session => {
      foreach(xs, "x") {

        val x = session("x").as[Integer]
        System.out.println(x)
        exec(http("post")
          .post("/blah/")
          .body(StringBody(x.toString))
          .check(status.is(200)))
      }
      Success(session)
    })

but now I get:
Simulation Test started...

================================================================================
2016-07-19 13:35:20                                           0s elapsed
---- Test Test -----------------------------------------------------------------
[##########################################################################]100%
          waiting: 0      / active: 0      / done:1    
---- Requests ------------------------------------------------------------------
> Global                                                   (OK=0      KO=0     )

================================================================================

Simulation Test completed in 0 seconds
Parsing log file(s)...
Parsing log file(s) done
Generating reports...
[error] java.lang.UnsupportedOperationException: There were no requests sent during the simulation, reports won't be generated
[error]     at io.gatling.charts.report.ReportsGenerator.generateFor(ReportsGenerator.scala:48)
[error]     at io.gatling.app.LogFileProcessor.generateReports(RunResultProcessor.scala:64)
[error]     at io.gatling.app.LogFileProcessor.processRunResult(RunResultProcessor.scala:43)
[error]     at io.gatling.app.Gatling.start(Gatling.scala:66)
[error]     at io.gatling.app.Gatling$.start(Gatling.scala:57)
[error]     at io.gatling.app.Gatling$.fromArgs(Gatling.scala:49)
[error]     at io.gatling.sbt.GatlingTask.liftedTree1$1(GatlingTask.scala:51)
[error]     at io.gatling.sbt.GatlingTask.execute(GatlingTask.scala:50)
[error]     at sbt.ForkMain$Run$2.call(ForkMain.java:296)
[error]     at sbt.ForkMain$Run$2.call(ForkMain.java:286)
[error]     at java.util.concurrent.FutureTask.run(FutureTask.java:266)
[error]     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
[error]     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
[error]     at java.lang.Thread.run(Thread.java:745)
[error] Simulation Test failed.

Stéphane LANDELLE

unread,
Jul 19, 2016, 3:29:32 PM7/19/16
to gat...@googlegroups.com
From doc:

Gatling DSL components are immutable ActionBuilder(s) that have to be chained altogether and are only built once on startup. The results is a workflow chain of Action(s). These builders don’t do anything by themselves, they don’t trigger any side effect, they are just definitions. As a result, creating such DSL components at runtime in functions is completely meaningless. If you want conditional paths in your execution flow, use the proper DSL components (doIfrandomSwitch, etc)

exec { session =>

  if (someSessionBasedCondition(session)) {
    // just create a builder that is immediately discarded, hence doesn't do anything
    // you should be using a doIf here
    http("Get Homepage").get("http://github.com/gatling/gatling")
  }
  session
}

Stéphane Landelle
GatlingCorp CEO


--
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.
For more options, visit https://groups.google.com/d/optout.

Mark Bordelon

unread,
Dec 1, 2016, 7:11:48 PM12/1/16
to Gatling User Group
So, Stephane. Is there really no way to create actions in an ActionBuilder at runtime? How does the recorder do it? This would dash my hopes of creating a scenario from an textfile. C'est rellement pas possible?

Stéphane LANDELLE

unread,
Dec 2, 2016, 1:56:34 AM12/2/16
to gat...@googlegroups.com
I suspect you're confusing load time, when the Simulation instance is loaded and the scenario workflows are created, and runtime, when the virtual users are propelled along those workflows and for example execute functions.
You can perfectly create scenarios based on some file content at load time.

Stéphane Landelle
GatlingCorp CEO


To unsubscribe from this group and stop receiving emails from it, send an email to gatling+unsubscribe@googlegroups.com.

Mark Bordelon

unread,
Dec 5, 2016, 4:23:24 PM12/5/16
to Gatling User Group
Stephane, vous avez raison. That was my confusion. Can you point me to some code that builds up scenarios dynamically at load time? I still have one day to put this together before a demo (am currently creating source code with shell scripts -- quelle horreur)

Nikolay Degkin

unread,
Dec 13, 2016, 9:41:55 AM12/13/16
to Gatling User Group
If i understood it right, you want to have 10 requests with appropriate body from 1 to 10?
It yes, you can try smth like below. I use Get just to see my requests

val endNum = 5
val startNum
= 1
var counter = new java.util.concurrent.atomic.AtomicInteger(startNum-1)
 
 val httpProtocol
= http
 
.baseURL("http://demo.mockable.io/")
 
 val scn
= scenario("+1")
 
.asLongAs(session => counter.getAndIncrement() < endNum)
 
{
 
exec(http("Change_Password")
 
.get(session =>"http://demo.mockable.io/" + s"""${counter}""")
 
.check(status.is(404))
 
)
 
}

Reply all
Reply to author
Forward
0 new messages