2017-05-04 65 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