Feeders

Learn about Feeders that provide data to the simulation.

In the previous lesson, we learned about throttling. In this lesson, we will learn about the different ways to pass test data to the Gatling test script using Feeders.

What are Feeders?

Feeders supply data to the simulations. Feeders are basically Iterator[Map[String, T]].

During the execution of a scenario, every user is fed with the same Feeder. However, every time the user reaches this step, Gatling will pop a record out of the Feeder, which will be injected into the user’s session, resulting in a new session instance for that user.

Types of Feeders

Continuous iterator

For generating records continuously until the simulation ends (in our case, a random number between 0 and 100), we can use the following:

import java.util.concurrent.ThreadLocalRandom._

def randomNumber(start: Int, end: Int) = current().nextInt(start, end + 1);

val feeder = Iterator.continually(Map("random_number" -> randomNumber(1, 100))
Press + to interact
import io.gatling.core.Predef._
import io.gatling.http.Predef._
import scala.concurrent.duration._
import java.util.concurrent.ThreadLocalRandom._
class SampleSimulation extends Simulation {
val httpProtocol = http
.baseUrl("http://localhost:8080")
.acceptHeader("*/*")
.doNotTrackHeader("1")
.userAgentHeader(
"Mozilla/5.0 (Windows NT 5.1; rv:31.0) Gecko/20100101 Firefox/31.0"
)
.disableWarmUp
.disableCaching
// generating a random number - both start and end are inclusive
def randomNumber(start: Int, end: Int) = current().nextInt(start, end + 1)
// for creating a feeder for generating continuously a random number
val feeder = Iterator.continually(Map("random_number" -> randomNumber(1, 5)))
val getScenario = scenario("BasicSimulation - GET")
.feed(feeder)
.exec(
http("GET request")
.get("/todo/${random_number}")
.check(status.is(200))
)
setUp(getScenario.inject(constantUsersPerSec(2) during(5 seconds))).protocols(httpProtocol)
}

In the above example, we create a method randomNumber that returns a random number between the ...