What is the replacement for InjectionStep when migrating from 2.x to 3.x Gatling?

In 2.x i’m using something like

import io.gatling.core.controller.inject.InjectionStep
var steps = MutableListInjectionStep

In 3.x that same code says not found

object InjectionStep is not a member of package io.gatling.core.controller.inject
import io.gatling.core.controller.inject.InjectionStep
^

There are now 2 different types that can’t be mixed: OpenInjectionStep and ClosedInjectionStep.

Merci Stephane.

I’m not seeing detail on this on gatling.io or in the Gatling 2.3 to 3.0 transition docs. Really appreciate it if you could tell me how I could translate something like this →

val numberOfDays = 1
val duration = (1 minute);
val stagesPerDay = 24;
val relativeRateIncreasePerDay = 0.2;
val stretchFactor = 10
var steps = MutableListInjectionStep

for (day ← 1 to numberOfDays) {
for (s ← 1 to stagesPerDay) {
val x = 2 * math.Pi * s / stagesPerDay
val rate = stretchFactor * math.sin(x) * (1 + day * relativeRateIncreasePerDay)
if (rate > 0.1) {
println(rate);
steps += (constantUsersPerSec(rate) during (duration))
}
}
}

setUp(scn.inject(steps.toList)

No offense, but this code is pretty ugly.
You should be using for comprehension instead of a mutable accumulator plus side effecting loops.
Please read https://docs.scala-lang.org/tour/for-comprehensions.html

Also, this way you wouldn’t have to explicitly use Gatling types.

Thank you for the suggestions. I’m just getting started with Gatling and saw this example from the people at Electronic Arts
https://github.com/electronicarts/gatling-aws-maven-plugin/tree/master/examples/maven-example-loadtest-project/src/test/scala/com/ea/gatling/example

Hi Stephane.

Would you mind showing me a short snippet of what you’re getting at using for comprehension to avoid Gatling types. I’ve read up on for comprehensions, maps, fold, etc. I get the basic concepts i’m just not seeing a path forward for this implementation. Appreciate any insight.

val steps =
  for {
    day <- 1 to numberOfDays
    s <- 1 to stagesPerDay
    x = 2 * math.Pi * s / stagesPerDay
    rate = stretchFactor * math.sin(x) * (1 + day * relativeRateIncreasePerDay)
    step =
    if (rate > 0.1) {
      constantUsersPerSec(rate) during duration
    } else {
      nothingFor(0)
    }
  } yield step

Merci beaucoup. Please tell me where in the city center I can buy you an apéritif.

It would be great if stuff like this could be evangelized on the gatling.io site. I realize it may be trivial, but i’ve noticed many people trying to use Gatling whom have never used Scala, asking questions and people spending time they shouldn’t have to on resolution. I also think stuff like this would promote best practices and reinforce premium usage of Gatling. Further, it surprises me that a company like EA which I showed an example of is using and publicizing code that could have been written more elegantly as you’ve shown.

Merci beaucoup. Please tell me where in the city center I can buy you an apéritif.

You’ll have to fly to Paris :slight_smile:

It would be great if stuff like this could be evangelized on the gatling.io site. I realize it may be trivial, but i’ve noticed many people trying to use Gatling whom have never used Scala, asking questions and people spending time they shouldn’t have to on resolution. I also think stuff like this would promote best practices and reinforce premium usage of Gatling.

High level injection profiles can be contributed (I haven’t checked with this one actually does), just like the one we’ve introduced for capacity tests in Gatling 3.0.
So can documentation. We do have a cookbook section too where contributions about best practices could do. We’d like to reorganize the documentation, but well… so much to do, so little time…

Further, it surprises me that a company like EA which I showed an example of is using and publicizing code that could have been written more elegantly as you’ve shown.

Well, I guess the little the people who wrote this code know about Scala suffices for their Gatling needs. Plus it works for them.

Cheers,

Stéphane Landelle

GatlingCorp CTO
slandelle@gatling.io