import com.excilys.ebi.gatling.core.Predef._
import com.excilys.ebi.gatling.http.Predef._
import com.excilys.ebi.gatling.jdbc.Predef._
import com.excilys.ebi.gatling.http.Headers.Names._
import akka.util.duration._
import bootstrap._
class MySimulation extends Simulation {
val httpConf = httpConfig
.baseURL("http://www.bfsstudios.com.au")
.acceptCharsetHeader("ISO-8859-1,utf-8;q=0.7,*;q=0.7")
.acceptHeader("text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8")
.acceptEncodingHeader("gzip, deflate")
.acceptLanguageHeader("fr,fr-fr;q=0.8,en-us;q=0.5,en;q=0.3")
.disableFollowRedirect
val headers_1 = Map(
"Keep-Alive" -> "115")
val scn = scenario("Scenario name")
.exec(
http("main page")
.get("/")
.headers(headers_1)
.check(status.is(200)))
.pause(0 milliseconds, 100 milliseconds)
.feed(csv("worker_id.csv").circular)
.exec(
http("Worker page")
.get("/worker/${worker_id}")
.check(status.is(200)))
setUp(scn.users(10).ramp(10).protocolConfig(httpConf))
}
- 1. 一个Gatling测试脚本就是一个scala的类,该类必须继承Simulation类,这样gatling才能识别其实一个测试集。该代码的后缀名必须为.scala
- 2. 测试中可以通过httpConf为http请求做基本的配置。
- 3. 一个scenario定义了一个测试用例。
- 4. 一个测试用例可以包含多个http请求,每个http请求可以设置自己的http method ,http header等.
- 5. 运行完之后,可以同个check检测每个请求的返回值
- 6. 可以通过feeder为同一个用例注入不同的参数数据,feeder中的文件默认从user-files目录下的data文件中查找。
- 7. 定义完scenario,通过setUp方法指定scenario的运行方式,我例子中的表示用10个用户并发跑测试,而ramp(10)的意思是10秒钟逐渐增加到10个用户,即每秒新起一个用户运行测试。
我的脚本的运行过程如下:
DSLGatling提供了为运行性能测试非常完善的DSL,这儿有其支持的所有的命令:
http://gatling-tool.org/cheat-sheet/ 使用Gatling之前,扫一眼所有的命令,对写脚本非常有帮助,因此虽然Gatling是scala的脚本,没有scala经验的同志使用起来也不会有任何问题。
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请
点击举报。