Gatling scenarios to be executed sequentially?

88 views
Skip to first unread message

Hpriya

unread,
Jan 17, 2018, 4:37:26 AM1/17/18
to Gatling User Group
I have two scenarios which are in  separate scala class files, one of which is get and post requests and the other one is a database extract writing to a csv file. When the running the tests, Gatling always executes the database scala file rather than the other scenario file. What i want is that the other scenario is executed and then the database scenario. Can any one help in this regard.

Hiranmaya Mohanty

unread,
Jan 17, 2018, 11:30:16 AM1/17/18
to Gatling User Group
Simple way would be to copy both the scenarios into one scala class and then set up two injections for the scenarios one after the other in the order you want them to run.

setUp(getpost_scenario.inject(....).protocols(getpost_protocol))
setUp(database_scenario.inject(....).protocols(database_Protocol))

James Warr

unread,
Jan 18, 2018, 1:42:20 AM1/18/18
to Gatling User Group
I tried this out and got an error that 'setUp can only be called once'

Hiranmaya Mohanty

unread,
Jan 18, 2018, 4:06:41 AM1/18/18
to Gatling User Group
This should work in that case:

setUp(getpost_scenario.inject(constantUsersPerSec(1) during(30 minute)).protocols(getpost_protocol),
  database_scenario.inject(
nothingFor(30 minute),
constantUsersPerSec(1) during(10 minute)
  ).protocols(database_Protocol))

Hpriya

unread,
Jan 18, 2018, 8:22:37 AM1/18/18
to Gatling User Group
I tried this out and it still behaves the same ...i.e executing the db scenario and then the other scenario.

Hiranmaya Mohanty

unread,
Jan 18, 2018, 9:31:33 AM1/18/18
to Gatling User Group
can you share your scala file with the two scenarios and the injection setup to debug into this issue?

Hpriya

unread,
Jan 18, 2018, 9:42:43 AM1/18/18
to Gatling User Group
Please do apologize as i cannot send the exact scala class file which i am using in my project

 This is the last edited scala class file which is a skeleton of it


  Object Login { val  login = …….}
  Object Actions{val actions = }
  object dbQuery {

    val csvFileLocation = "<path>"
    val out = new BufferedWriter(new FileWriter(csvFileLocation)).append("IDS" + "\n")
    val writer = new CSVWriter(out, CSVWriter.NO_QUOTE_CHARACTER, CSVWriter.NO_ESCAPE_CHARACTER, "\n")
    val scn1 = //scenario("Database Query")

      {
       var i = 0
       feed(jdbcFeeder("jdbc:oracle:thin:<jdbc connection details, username, password, sql>))
      .exec { session =>
        val Ids = new Array[String]((jdbcFeeder("<jdbc connection details, username, password, sql>”).records.length))
        println("Ids", Ids)
        Ids(i) = session("IDS").as[Long].toString + "," +"\n"
        println(Ids(i))
        writer.writeNext(Ids)
        i = i + 1
        session
      }
  }
after {
  writer.close()
      }


val scn = scenario("Case")
  .group("login"){
    exec( Login.login)
  }
  .group("actions"){
    exec(Actions.actions)
  }
  .group("dbQuery"){
    exec(dbQuery.scn1)
  }

  .exec(flushHttpCache)
  .exec(flushCookieJar)
  .exec(flushSessionCookies)

setUp(
  scn.inject(atOnceUsers(1)).protocols(httpProtocol)
)



What is happening is that the Database query is run first and then the other stuffs.

Hiranmaya Mohanty

unread,
Jan 19, 2018, 3:43:26 AM1/19/18
to Gatling User Group
How do you check if the database query is executed first and rest of the requests later. From your scn scenario set up, it should do the login and actions first and then the db query.
Also, just to be sure, what is the goal of the flow - for each user, run some requests first and then check something in database? 
My earlier solution was based on the assumption that you run getpost requests for sometime with multiple users and then once these are finished run the db requests.
Reply all
Reply to author
Forward
0 new messages