mardi 17 novembre 2015

Gatling scala script randomize scenario

I use the script below, It should send a post request which contains some data which is read from a file. I want to randomize the requests so sometimes it send "R1_BINFile_0" and sometimes "R2_Binfile_1". For some reason it doesn't work and it send always the same request

package computerdatabase

import io.gatling.core.Predef._
import io.gatling.http.Predef._
import scala.concurrent.duration._

class MYSimulation extends Simulation {

  val feeder = csv("CsvConfigFile.csv").circular
  val PATH = sys.env("GATLING_HOME")

  val httpConf = http
    .baseURL("https://HOST") // Here is the root for all relative URLs
    .acceptHeader("text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8") 
    .acceptCharsetHeader("UTF-8")
    .acceptLanguageHeader("en-US,en;q=0.5")
    .acceptEncodingHeader("gzip, deflate")
    .userAgentHeader("Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:16.0) Gecko/20100101 Firefox/16.0")

   val headers_10 = Map("Content-Type" -> "application/octet-stream") 
   val rnd = new scala.util.Random
   val scn = scenario("Scenario1")
      .feed(feeder)
      .doIfOrElse(rnd.nextInt(100) > 50) {
         exec(http("R1")
               .post("https://HOST/web/")
               .headers(headers_10)
               .body(RawFileBody(PATH  + "\\user-files\\data\\" + "${R1_BinFile}" + "_0")))
      } {
         .exec(http("R1")
               .post("https://HOST/web/")
               .headers(headers_10)
               .body(RawFileBody(PATH  + "\\user-files\\data\\" + "${R1_BinFile}" + "_1")))
      }


    setUp(scn.inject(constantUsersPerSec(5) during (100 seconds)).protocols(httpConf))
}




Aucun commentaire:

Enregistrer un commentaire