how to seed the app with data before running the scenarios?

hi there,
i’m looking for advice on how to seed the an app with data before running any scenario.

let me explain …

i’m going to run the gatling simulation in various environments (e.g.: dev, staging), and I need certain data to be available for the jdbcFeeder.
because i can not control what data these environment already have, before i run any scenario i want to:

  1. find if the environment already has the data needed for the scenario
  2. if not, using the app’s http rest api create such data, so it would be available for the jdbcFeeder

as an example, assuming the needed data is XXX, i’d like to do something like this:

  1. if (JdbcFeederSource(url, username, password, sqlForXXX)).records.size < howManyXXX) {

  2. repeat (howManyXXX, “i”)
    exec(http(“create XXX”)
    .post("/api/XXX")
    .headers(headers_n)
    .body(StringBody(jsonForXXX).asJSON)
    }

  3. val xxx = jdbcFeeder(url, username, password, sqlForXXX)

I know that worse come to worse I can use the something like (new AsyncHttpClient).preparePost(…).execute.get to achieve 2, but that would be ugly and i would prefer gatling’s elegancy a lot better.

I see that the Simulation class has a method: def before(step: => Unit): Unit , and was wondering if it can be used somehow to achieve 1 & 2

I think this is not an exceptional need, and would expect others have already done similar things, so no need for me to reinvent the wheel …

thoughts?

thanks in advance,
Benny

I’d rather go with test environment images, or scripts wrapping the stress tests, but yes, you can use the before hook for this, just that you can’t use Gatling DSL there. You can for example use AsyncHttpClient.