0
val scn = scenario("newUser")
    .exec(http("request_0")
        .get("/wordpress/?page_id=83")
        .headers(headers_0))
    .pause(1)
    .exec(http("request_1")
        .post("/wordpress/?page_id=83")
        .headers(headers_1)
        .body(RawFileBody("new_user_request_0001.txt")))

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

My question is the following... I have to load 100 text files with structure like that in the example ("new_user_request_0001.txt"), using numbers between 0 to 100 randomly. How can I do? Thank you all

  • 3
    If you have to load 100 files with values of 0 to 100 randomly - does that mean you're just looking for a random _sorting_ of the files (i.e. each value in [0, 100) should be used exactly once), or do you want to select the values randomly so that some might repeat themselves? – Tzach Zohar Apr 05 '18 at 13:56
  • The range "0 to 100" contains 101 numbers, not hundred... But I assume these are minor details. – Andrey Tyukin Apr 05 '18 at 17:50

2 Answers2

0

It's easy. You can use Random.shuffle

scala.util.Random.shuffle(0 to 100)
Ivan Dyachenko
  • 1,348
  • 9
  • 16
0

You could try to use uniformRandomSwitch, generate a sequence of 100 ChainBuilders, and then use the (...): _* syntax to unpack it as an argument to a vararg-method:

val scn = scenario("newUser")
    .exec(http("request_0")
        .get("/wordpress/?page_id=83")
        .headers(headers_0))
    .pause(1)
    .uniformRandomSwitch(
        ((0 until 100).map{ idx =>
          http("request_1")
          .post("/wordpress/?page_id=83")
          .headers(headers_1)
          .body(RawFileBody(s"new_user_request_0${idx}.txt")))
        }): _*
    )

The s" ... ${idx} ..." syntax injects the idx argument passed by map into the string.

Andrey Tyukin
  • 43,673
  • 4
  • 57
  • 93