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

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.

Yep, this is the Gatling 1 syntax.

In Gatling 2.0.0-M2, you have to write session => session.getVInt.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

Thank you for so quick answer!
It works perfectly

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.getVInt.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.

I don’t know what it was for issue, but now code compile with: session => session(“counter”).as[Int] < 5

As it should :slight_smile: