Check the foreach counter value does not exceed a given value in Gatling2

1,041 views
Skip to first unread message

natalja....@gmail.com

unread,
May 22, 2013, 7:53:03 AM5/22/13
to gat...@googlegroups.com
Hi!

In my test I request details of user loans. Each user could have a number of loans, but I need to request not more than five of them.

My scenario is:
val request_loans_list = execWithStdChecks(http("Loans list")
 .post("/accounts/accounts-list.xml")
 .headers(headers_Content_Length_0)
 .check(
  xpath("//account[starts-with(producttypeid/text(), '51')]/accountid")
  .findAll
  .whatever
  .saveAs("loan_ids")
 )
)

val request_loans_info = execWithStdChecks(http("Loans info")
 .get("/loans/loans_xml.xml")
 .queryParam("""id""", "${loan_id}")
)

val request_all_loan_info = doIf(session => session.contains("loan_ids")){
 foreach("${loan_ids}", "loan_id", "counter"){
  doIf(session => session.getAttribute("counter") < 5){
   exec(request_loans_info)
  }
 }
}

As I understood I have to use  doIf  inside  foreach loop, but it is not compiled. I use Gatling2 for my tests.

Stéphane Landelle

unread,
May 22, 2013, 8:08:44 AM5/22/13
to gat...@googlegroups.com
Yep, this is the Gatling 1 syntax.

In Gatling 2.0.0-M2, you have to write session => session.getV[Int]("counter").map(_ < 5)

Beware, that will change in the next milestone (we've been discussing the new syntax here). Then, you'll be able to write:
  • session => session("counter").as[Int] < 5
  • or, session => session("counter").validate[int].map(_ < 5)
Cheers,

Stéphane

--
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/groups/opt_out.
 
 

natalja....@gmail.com

unread,
May 22, 2013, 8:33:26 AM5/22/13
to gat...@googlegroups.com
Thank you for so quick answer!
It works perfectly


среда, 22 мая 2013 г., 14:53:03 UTC+3 пользователь natalja....@gmail.com написал:

natalja....@gmail.com

unread,
Dec 15, 2014, 8:58:58 AM12/15/14
to gat...@googlegroups.com
Hello!

I updating my old test scenario for Gatling M2.0.3


In my test I request details of user loans. Each user could have a number of loans, but I need to request not more than five of them.
In Gatling 2.0.0-M2 I have perfectly working check:
foreach("${account_ids}", "account_id", "counter"){
      doIf(session => session.getV[Int]("counter").map(_ < 5)){

But now i have problem with syntactics
I try earlier suggested
foreach("${account_ids}", "account_id", "counter"){
      doIf (
    • session => session("counter").as[Int] < 5
    • or, session => session("counter").validate[int].map(_ < 5) {

    But it didn't compile anymore.


    среда, 22 мая 2013 г., 15:08:44 UTC+3 пользователь Stéphane Landelle написал:

    Stéphane Landelle

    unread,
    Dec 15, 2014, 9:18:18 AM12/15/14
    to gat...@googlegroups.com
    Could you provide your compiler error, please?

    natalja....@gmail.com

    unread,
    Dec 17, 2014, 8:39:34 AM12/17/14
    to gat...@googlegroups.com
    I don't know what it was for issue, but now code compile with: session => session("counter").as[Int] < 5


    понедельник, 15 декабря 2014 г., 16:18:18 UTC+2 пользователь Stéphane Landelle написал:

    Stéphane Landelle

    unread,
    Dec 17, 2014, 9:49:00 AM12/17/14
    to gat...@googlegroups.com
    As it should :)

    --
    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.
    Reply all
    Reply to author
    Forward
    0 new messages