Slide 10
Slide 10 text
© ZOZO, Inc.
10
Gatlingのテストシナリオ
Scalaでのテストシナリオ記述例
● Simulationクラスを拡張して利用
● setUpに定義したシナリオを設定
● 実行時に環境変数から値を読み取り閾
値等を決定
import io.gatling.core.Predef._
import io.gatling.http.Predef._
import scala.concurrent.duration._
class SampleScenario extends Simulation {
val env = sys.env.getOrElse("ENV", "dev")
val endpoint = env match {
case "dev" => "https://hogehoge.com/"
}
val usersPerSec = sys.env.getOrElse("CONCURRENCY", "2").toDouble
val durationSec = sys.env.getOrElse("DURATION", "10").toInt
val httpProtocol = http
.baseUrl(endpoint)
.userAgentHeader("Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:16.0)
Gecko/20100101 Firefox/16.0")
.shareConnections
val headers = Map("Content-Type" -> "accept: application/json")
val request = exec(http("request User sample API")
.get("/helloworld")
.headers(headers)
.check(status.is(200)))
val singleRequest = scenario("Request (" + env + ") user sample api").exec(request)
setUp(
singleRequest.inject(constantUsersPerSec(usersPerSec) during(durationSec
seconds)).protocols(httpProtocol)
)
}