-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathThrottleExtension.scala
36 lines (28 loc) · 1 KB
/
ThrottleExtension.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
package io.praveen.gatling.extension.dsl
import io.gatling.core.controller.throttle._
import scala.concurrent.duration.FiniteDuration
/**
* Created by praveesi on 05/06/16.
*/
object ThrottleExtension {
/**
* Add multi jump DSL to the Throttling DSL.
*/
def multiJump(times: Int) = {
MultiJumpStep(times)
}
case class MultiJumpStep(times: Int) {
def initRps(initRps: Int) = MultiJumpInitRps(initRps, times)
}
case class MultiJumpInitRps(initRps: Int, times: Int) {
def jumpBy(jumpBy: Int) = MultiJumpJumpBy(jumpBy, initRps, times)
}
case class MultiJumpJumpBy(jumpBy: Int, initRps: Int, times: Int) {
def stabilizeFor(stabilizeFor: FiniteDuration) = mj(times, initRps, jumpBy, stabilizeFor)
}
private def mj(times: Int, startAt: Int, jumpByRps: Int, stabilizeFor: FiniteDuration): List[ThrottleStep] =
(0 to times)
.foldLeft(List.empty[ThrottleStep]) { (acc, currCount) =>
Hold(stabilizeFor) :: Jump(startAt + currCount * jumpByRps) :: acc
}
}