2017-05-04 62 views
0

我想要設置Gatling,以便在一次設置中,我可以發送3000個請求,其中95%將使用一個測試文件,另外5%則是另一個測試文件。這些文件恢復成JSON文件(在下面的代碼稱爲「userFeeder」。加特林能支持上述情景?設置Gatling根據百分比/比率發送請求?

代碼當前如下,這適用於每秒辦法的要求,但需要修正。

class AddUserSimulation extends Simulation { 

    private val conf = ConfigFactory.load() //loads a setup file of parameters 
    private val TOKEN_VALUE = "tokenvalue" 
    private val userFeeder = jsonFile("/" + conf.getString("environment") + "/testaddUser.json") 

    val httpConf = http 
    .baseURL(conf.getString("api.gateway.url")) // Here is the root for all relative URLs 
    .header("Referer", conf.getString("referer")) 
    .header("Cache-Control", "no-cache") 
    .contentTypeHeader("application/json") 

    val Login = new ADFSAuthentication Login 

    val scnAPI = scenario("test add User") // A scenario is a chain of requests and pauses 
    .feed(userFeeder.circular) 
    .exec(Login.process) 
    .repeat(conf.getInt("repeat.count")) { 
     exec(http("test add User") 
     .post("/" + conf.getString("environment") + "https://stackoverflow.com/users/") 
     .body(StringBody("${payload}")).asJSON 
     .header("Authorization", "Bearer ${"+TOKEN_VALUE+"}") 
    .check(status.is(200))) 
    .pause(conf.getInt("execution.pause")) 
    } 
    setUp(scnAPI.inject(constantUsersPerSec(11) during(30 minutes)).protocols(httpConf)) 
} 

任何幫助是極大的讚賞。

回答

0

當然!首先設置兩個饋線,然後成立了兩個方案中,使用一個第一進紙器,一個使用第二進紙器。最後setUp都與用戶的數量,您願望(對應你的分銷)

的代碼可能是這個樣子:

private val firstFeeder = jsonFile("/" + conf.getString("environment") + "/testaddUser.json") 
private val secondFeeder = jsonFile("/" + conf.getString("environment") + "/testaddUser2.json") 

val scnAPI = scenario("test add User") 
    .feed(firstFeeder) 
    //... 

val scnAPI2 = scenario("second test add User") 
    .feed(secondFeeder) 
    //... 

setUp(scnAPI.inject(constantUsersPerSec(95) during(30 minutes)).protocols(httpConf), 
     scnAPI2.inject(constantUsersPerSec(5) during(30 minutes)).protocols(httpConf)) 

注:這不會創建一個只3000的要求,但我覺得你的想法。

+0

這正是我們最終使用的。感謝這個輸入,使用兩個饋線是解決方案。 – user3190153