2015-05-04 20 views
3

我嘗試使用各種「休息」和「atOnceUsers」進行注射。 我沒有找到一個很好的文檔解決方案。Gatling的可變rampUp

我的方法是用本地計數器創建一個名爲「getNextNumber()」的函數,以增加「atOnceUsers」的數量,但函數在開始時只調用一次。

任何想法?

我的代碼:

class TestCombinationGetFiles extends Simulation { 
    var counter: Int =1 

    def getNextNumber():Int = { 
     counter+= 1 
     return counter 
    }  

    val Get20Files = scenario("get20Files") 
    .feed(UuidFeeder.feeder) 
    .exec(WebAuth.AuthenticateUser) 
    .pause(30) 
    .exec(WebCloudContent.GoToTestFolder20) 

val Get10Files = scenario("get10Files").feed(UuidFeeder.feeder) 
    .exec(WebAuth.AuthenticateUser) 
    .pause(15) 
    .exec(WebCloudContent.GoToTestFolder10) 

val loadFolder20TestRamp =    
    scenario("loadFolder20TestRamp").exec(WebAuthSwisscom.AuthenticateUser,    
    WebCloudContentSwisscom.GoToTestFolder20)  

setUp(Get20Files.inject(
    splitUsers(36) into( 
     atOnceUsers(getNextNumber())) 
     separatedBy(30 seconds)) 

     /* messy Code with correct functionality 
     atOnceUsers(1), 
     nothingFor(30 seconds), 
     atOnceUsers(2), 
     nothingFor(30 seconds), 
     atOnceUsers(3), 
     nothingFor(30 seconds), 
     atOnceUsers(4), 
     nothingFor(30 seconds), 
     atOnceUsers(5), 
     nothingFor(30 seconds), 
     atOnceUsers(6), 
     nothingFor(30 seconds), 
     atOnceUsers(7), 
     nothingFor(30 seconds), 
     atOnceUsers(8), 
     nothingFor(30 seconds)) 
     */ 
    , 
    Get10Files.inject(
     splitUsers(16) into( 
      atOnceUsers(1)) 
      separatedBy(15 seconds)) 
    ).protocols(WebSetUp.httpProtocol) 
} 

回答

1

我想你已經發現了加特林缺少功能!我將更多地開發這個功能,並向Gatling團隊提交一個pull請求(希望)將其加入到該項目中,但與此同時,您可以通過提供自己的定製InjectionStep實現來獲得所需的功能 - 只需粘貼在你Simulation文件的頂部:

import io.gatling.core.controller.inject._ 
import scala.concurrent.duration._ 

case class AtOnceIncrementalInjection(users: Int) extends InjectionStep { 
    require(users > 0, "The number of users must be a strictly positive value") 
    var count = users 

    override def chain(chained: Iterator[FiniteDuration]): Iterator[FiniteDuration] = { 
    val currentUsers = count 
    count += 1 
    Iterator.continually(0 milliseconds).take(currentUsers) ++ chained 
    } 
} 

def atOnceIncrementalUsers(initialUsers:Int) = AtOnceIncrementalInjection(initialUsers) 

這基本上就是你試圖用atOnceUsers做的,但關鍵的區別是計數爲​​chain方法,這將讓你增加行爲因爲chain將被稱爲每次加特林決定是時候發送一些請求。

現在你可以使用輔助功能在您使用atOnceUsers以同樣的方式:

splitUsers(36) into( 
    atOnceIncrementalUsers(1)) 
    separatedBy(30 seconds)) 
+0

拉動請求歡迎;-) –