[Gatling2] randomSwitch in scenario

1,091 views
Skip to first unread message

natalja....@gmail.com

unread,
Oct 30, 2013, 6:25:15 AM10/30/13
to gat...@googlegroups.com
Hi!

I have scenario with multiple payments. My scenario ends with
[...]
.randomSwitch(
        10 -> exec(ScenarioPayments1.chain_payment1),
        10 -> exec(ScenarioPayment2.chain_payment2),
        20 -> exec(ScenarioPayment3.chain_payment2),
        10 -> exec(ScenarioPayment4.chain_payment4),
        20 -> exec(ScenarioPayment5.chain_payment5),
        20 -> exec(ScenarioPaymen6.chain_payment6),
        10 -> exec(ScenarioPaymen7.chain_payment7)
    )

  }

  setUp(
    scn_payments.inject(
      atOnce(101 users)
    ).protocolConfig(httpConf)
  )
}
But seems, that all users do all payments without any random. So they all do first payments, than second and etc.
Does randomSwitch works in Gatling2 ???

When i tested with Gatling 1.5 randomSwitch works perfectly.


Nicolas Rémond

unread,
Oct 30, 2013, 6:28:31 AM10/30/13
to gat...@googlegroups.com
Gatling-2M3a ?


--
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,
Oct 30, 2013, 6:33:32 AM10/30/13
to gat...@googlegroups.com
I use Gatling 2M1

среда, 30 октября 2013 г., 12:28:31 UTC+2 пользователь Nicolas Rémond написал:

Stefan Magnus Landrø

unread,
Oct 30, 2013, 8:04:55 AM10/30/13
to gat...@googlegroups.com
In master this works as expected it seems

Stefan

natalja....@gmail.com

unread,
Oct 30, 2013, 11:10:18 AM10/30/13
to gat...@googlegroups.com
I try one more time. No success
My scenario

val scn_payments = scenario("Stress test Payments")
    .feed(Users)
    .repeat(1) { 
       exec(ScenarioLogin.chain_login)
      .pause(500 milliseconds)
      .exec(chain_transfer_type)
      .pause(500 milliseconds)
      .exec(ScenarioPayments1.chain_payment1)
      .pause(500 milliseconds)
      .exec(ScenarioPayment1.chain_payment2)
      .exec(chain_logout)
      .randomSwitch(
         exec(ScenarioPayments1.chain_payment1),
         exec(ScenarioPayment1.chain_payment2)
       )
  }

  setUp(
    scn_payments.inject(
      atOnce(6 users)
    ).protocolConfig(httpConf)

But in test 6 users do payment1 and than same 6 users do payment2
I expect, that 6 user will login on site, 3(or 4, 0or2) will do payment1, and other 3 will go straight to payment2

Stefan Magnus Landrø
14:04 (3 ч. назад)

Stéphane Landelle

unread,
Oct 30, 2013, 11:36:53 AM10/30/13
to gat...@googlegroups.com
Hi,

I don't get it: you execute payment1 and payment2, both directly and inside a randomSwitch, so users will do payment1, then payment2, then 50/50 payment1 or payment2 (and I expect those to fail as the users have just logged out).

Are you sure you don't want:

val scn_payments = scenario("Stress test Payments")
    .feed(Users)
    .repeat(1) {  
       exec(ScenarioLogin.chain_login)
      .pause(500 milliseconds)
      .exec(chain_transfer_type)
      .pause(500 milliseconds)
      .randomSwitch(
         exec(ScenarioPayments1.chain_payment1),
         exec(ScenarioPayment1.chain_payment2)
       )
      .exec(chain_logout)
  }



2013/10/30 <natalja....@gmail.com>

natalja....@gmail.com

unread,
Oct 31, 2013, 5:35:58 AM10/31/13
to gat...@googlegroups.com
This is exactly, that I want
Thank You!
*facepalm*

среда, 30 октября 2013 г., 17:36:53 UTC+2 пользователь Stéphane Landelle написал:

Nicolas Rémond

unread,
Oct 31, 2013, 5:45:47 AM10/31/13
to gat...@googlegroups.com
Also, I'm not really sure why you have an enclosing repeat(1){} block ?

cheers
Nicolas

natalja....@gmail.com

unread,
Nov 4, 2013, 7:21:04 AM11/4/13
to gat...@googlegroups.com
I migrate this scenario from Gatling 1.5
I change repeating times from test to test. 

четверг, 31 октября 2013 г., 11:45:47 UTC+2 пользователь Nicolas Rémond написал:

natalja....@gmail.com

unread,
Nov 4, 2013, 7:55:09 AM11/4/13
to gat...@googlegroups.com
I'm still very novice in scala, that is why I really need help with  randomSwitch in my test

I have test scenario:
.feed(Users)
    .repeat(5) { 
       exec(ScenarioLogin.chain_login)
      .pause(500 milliseconds)
      .randomSwitch(
         exec(ScenarioPayments1.chain_payment1),
         exec(ScenarioPayments2.chain_payment2),
         exec(ScenarioPayments3.chain_payment3),
         exec(ScenarioPayments4.chain_payment4),
         exec(ScenarioPayments5.chain_payment5),
  )
.exec(chain_logout)
     }

In this scenario 100 users do 100 payments, so each user do 1 payment.
Is there any possibility, that each user will do all 5 payments, but in random sequence. So each user after login will do 5 payments in random sequence and logout.

Is there possibility, where I can tell, that each user have to make 3 random payment during one session.

Stéphane Landelle

unread,
Nov 4, 2013, 8:15:00 AM11/4/13
to gat...@googlegroups.com
Hi,

First of all, you don't have to write "exec(ScenarioPayments1.chain_payment1)", ScenarioPayments1.chain_payment1 is probably already a chain and would be enough.

Hadn't thought of this use case, so there's no immediate built in, but definitively doable.
Do you want distinct payment types?

Stéphane

natalja....@gmail.com

unread,
Nov 4, 2013, 9:32:29 AM11/4/13
to gat...@googlegroups.com
Thank You, Stéphane, for Your quick response!

Yes, I would like, that each payment is called one time by the user and every user call all 5 payments in random order

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

Stéphane Landelle

unread,
Nov 4, 2013, 9:56:03 AM11/4/13
to gat...@googlegroups.com
OK.
We'll add some built-ins for this, but until then, things will be a bit verbose :

import scala.concurrent.forkjoin.ThreadLocalRandom
import scala.util.Random

// set into the session a "choices" attribute that's a random sequence of 5 unique indices
.exec(_.set("choices", new Random(ThreadLocalRandom.current).shuffle(Seq(0, 1, 2, 3, 4))))
// loop over choices
.foreach("${choices}", "choice") {
doIfEqualsOrElse(0, "${choice}") {
chain1
} {
doIfEqualsOrElse(1, "${choice}") {
chain2
} {
doIfEqualsOrElse(2, "${choice}") {
chain3
} {
doIfEqualsOrElse(3, "${choice}") {
chain4
} {
chain5
}
}
}
}

Get it?

Stéphane
Reply all
Reply to author
Forward
0 new messages