custom feeder for maping records from csv to userId

Hi,

Lets assume that we have scenario in which every virtual user should use only its login data because system doesn’t support 2 users with the same login be logged in simultaneously.
We have 10 users and their login, passwords in csv file. We can’t use circular strategy for feeder because it is possible, with that strategy, that at some point of time, if we have 10 users, we might get situation when first user haven’t finished his job and second already finished.
In that case second user will read login information of first and as result first user got logged out because system doesn’t support this behavior.
So we need to have strict relation between virtual user and data from csv file.

I need something like following feeder, but I cant use session.userId field due to fact that feeder doesn’t see session information.
Moreover, in this feeder I will need to implement verification whether records size is at least equals number of virtual users. How can I get this information from feeder.

val params = new Feeder[String] {

val records = csv(""“rpd_params_create_instance.csv”"").data.toList
// need verify that count of records in csv is enough to all virtual users

def hasNext = true;

def next = {
val idx = session => {session.userId}
records(session.userId)
}
}

I guess this type of feeder should be very useful and might be added to standard strategy list

Thanks,
Ievgen

Hi,

I suggest that you don’t rely on the Session’s userId : in Gatling 2, userId is not an integer anymore, it’s a String, partly built on a random UUID, therefore (almost) completely random.

You have several options to ensure you have the enough data for the feeder which doesn’t require to implement a custom feeder.

1/ If you want to use a CSV file, you can use Scala’s require in your simulation to check at simulation start that there is enough data.
You’ll need to :

  • set the number of users in a val, to make available outside setUp(…)
  • As Gatling’s feeder is based on Scala’s Iterator, you can call size or length on it to get the number of lines
  • Use Scala’s require to stop the simulation if there’s not enough data

You should have something like this :

val nbUsers = 100 // Reuse that in setUp(…)
require(csv(“mycsv.csv”).size >= nbUsers, “Not enough users in CSV file !”)

2/ If you have access to the database where the user accounts are stored (if it’s stored in an SQL database of course), you can always use a JDBC feeder.
Like the previous solution, store the number of users in a val and use it to pop as many user accounts as you like, directly from the database :

val nbUsers = 100
val jdbcFeeder = jdbc(“jdbc:mysql://theDbUrl”, “username”, “password”, "SELECT username, password FROM accounts LIMIT " + nbUsers)

Cheers,

Pierre

Thanks for answer.

But how can I use session object from feeder to read some values from current user session?

Thanks,
Ievgen

Пʼятниця, 16 серпня 2013 р. 22:13:07 UTC+3 користувач Pierre DAL-PRA написав:

You can’t access the session inside the feeder, for two reasons :

  • As loading the feeder data could be an expensive operation, feeders are loaded at the same time the simulation is “loaded” (instantiated and ready to run), not while the simulation is running
  • Therefore, there is no “hook” to access the session, as there is no session before the simulation starts
    However, you can always transform the feeder’s data after it has been injected in the session with feed(…), using an exec(Session => Session), like that :

.feed(feeder)
.exec(session => session.set(“password”, session(“password”).as[String] + “foo”))

If your feeder loaded in your session an attribute named “password” with value “1234”, after the exec the “password” attribute’s value will be “1234foo”.