然后在 MySimulation.scala 就可以 import ,使用里面定义好的方法了:
import scala.concurrent.duration._ import scala.util.Random import io.gatling.core.Predef._ import io.gatling.http.Predef._ import io.gatling.jdbc.Predef._ import Feeders._ class MySimulation extends Simulation { val brownse = feed(randomOffsetFeeder) .exec( home ) } |
用户注入策略
<= 10: 一把注入
> 10: 每10秒注入10个用户
val injectStrategy = if (USERS_COUNT > 10) { splitUsers(USERS_COUNT) into( rampUsers(10) over(5 seconds) ) separatedBy(10 seconds) } else { atOnceUsers(USERS_COUNT) } |
压测时间策略
= 0: 所有模拟用户不循环,执行完测试场景即退出
> 0: 所有模拟用户循环执行测试场景,直到达到指定时间
val scn = scenario("My test scenario") .doIfOrElse(DURATION > 0) { forever( exec(steps) ) } { exec(steps) } val setup = setUp( scn.inject( injectStrategy ).protocols(httpProtocol) ) if (DURATION > 0) { setup.maxDuration(DURATION minutes) } |