packagecomputerdatabase;importstaticio.gatling.javaapi.core.CoreDsl.*; importstaticio.gatling.javaapi.http.HttpDsl.*;importio.gatling.javaapi.core.*; importio.gatling.javaapi.http.*; importjava.time.Duration;publicclassBasicSimulationextendsSimulation{ //创建议信息HttpProtocolBuilder httpProtocol =http// Here is the root for all relative URLs.baseUrl("http://computer-database.gatling.io")// Here are the common headers.acceptHeader("text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8").doNotTrackHeader("1").acceptLanguageHeader("en-US,en;q=0.5").acceptEncodingHeader("gzip, deflate").userAgentHeader("Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:16.0) Gecko/20100101 Firefox/16.0");// 创建场景ScenarioBuilder scn =scenario("Scenario Name").exec(http("request_1").get("/"))//get请求// Note that Gatling has recorded real time pauses.pause(7)//暂停多久.exec(http("request_2").get("/computers?f=macbook")).pause(2).exec(http("request_3").get("/computers/6")).pause(3).exec(http("request_4").get("/")).pause(2).exec(http("request_5").get("/computers?p=1")).pause(Duration.ofMillis(670)).exec(http("request_6").get("/computers?p=2")).pause(Duration.ofMillis(629)).exec(http("request_7").get("/computers?p=3")).pause(Duration.ofMillis(734)).exec(http("request_8").get("/computers?p=4")).pause(5).exec(http("request_9").get("/computers/new")).pause(1).exec(http("request_10")// Here's an example of a POST request.post("/computers")//post请求,然后传一些form参数// Note the triple double quotes: used in Scala for protecting a whole chain of// characters (no need for backslash).formParam("name","Beautiful Computer").formParam("introduced","2012-05-30").formParam("discontinued","").formParam("company","37"));{//注入用户,刚开始就一个,协议是httpsetUp(scn.injectOpen(atOnceUsers(1)).protocols(httpProtocol));} }