forked from karatelabs/karate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCatsChainedSimulation.scala
43 lines (31 loc) · 1.33 KB
/
CatsChainedSimulation.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package mock
import com.intuit.karate.gatling.PreDef._
import io.gatling.core.Predef._
import scala.concurrent.duration._
import scala.util.Random
class CatsChainedSimulation extends Simulation {
MockUtils.startServer(0)
val protocol = karateProtocol(
"/cats/{id}" -> Nil
)
val feeder = Iterator.continually(Map("name" -> (Random.alphanumeric.take(20).mkString + "-name")))
val feederToKarate = scenario("feederToKarate")
.exec(karateSet("name", session => session("name").as[String]))
val create = scenario("create").exec(karateFeature("classpath:mock/cats-chained.feature@name=create"))
val read = scenario("read").exec(karateFeature("classpath:mock/cats-chained.feature@name=read")).exec(session => {
println("*** id in gatling: " + session("id").as[String])
println("*** session status in gatling: " + session.status)
session
})
val createAndRead = scenario("createAndRead").group("createAndRead") {
feed(feeder)
.exec(feederToKarate)
.exec(create)
// for demo: injecting a new variable name expected by the 'read' feature
.exec(karateSet("expectedName", session => session("name").as[String]))
.exec(read)
}
setUp(
createAndRead.inject(rampUsers(10) during (5 seconds)).protocols(protocol)
).assertions(details("createAndRead").failedRequests.percent.is(0))
}