2016-10-05 101 views
0

我想在以下情形中添加一個條件。
我想從方案退出if(counter=8 or WorkflowStatus=true)添加每個http請求都會增加的計數器

有誰知道如何添加這將增加8後高達8次,每次請求,並退出計數器,以及上述條件下,如果要求得到WorkflowStatus = true,則退出在下面的情況?

讓我知道你是否需要更多的澄清。 謝謝。

class LaunchResources extends Simulation { 

    val scenarioRepeatCount = Integer.getInteger("scenarioRepeatCount", 1).toInt 
    val userCount = Integer.getInteger("userCount", 1).toInt 
    val UUID = System.getProperty("UUID", "24d0e03") 
    val username = System.getProperty("username", "p1") 
    val password = System.getProperty("password", "P12") 
    val testServerUrl = System.getProperty("testServerUrl", "https://someurl.net") 


    val httpProtocol = http 
     .baseURL(testServerUrl) 
     .basicAuth(username, password) 
     .connection("""keep-alive""") 
     .contentTypeHeader("""application/vnd+json""") 


    val headers_0 = Map(
     """Cache-Control""" -> """no-cache""", 
     """Origin""" -> """chrome-extension://fdmmgasdw1dojojpjoooidkmcomcm""") 


    val scn = scenario("LaunchAction") 
     .repeat (scenarioRepeatCount) { 
      exec(http("LaunchAResources") 
       .post("""/api/actions""") 
       .headers(headers_0) 
       .body(StringBody(s"""{"UUID": "$UUID", "stringVariables" : {"externalFilePath" : "/Test.mp4"}}""")) 
       .check(jsonPath("$.id").saveAs("WorkflowID"))) 

     .exec(http("SaveWorkflowStatus") 
       .get("""/api/actions/{$WorkflowID}""") 
       .headers(headers_0) 
       .check(jsonPath("$.status").saveAs("WorkflowStatus"))) 

     } 

    setUp(scn.inject(atOnceUsers(userCount))).protocols(httpProtocol) 
} 

回答

0

您可以使用Redis來存儲您的計數號碼,每次請求正在進行時控制Redis號碼。 我在3分鐘內使用Redis計算了我的http帖子數,如果在3分鐘內計數超過10次,我將禁用此帖子的ip地址,並且此ip在未來3分鐘內將獲得403禁止錯誤。

+0

就實現了這個,.asLongAs(會話=>會話重用此。屬性(「WorkflowStatus」)!=「false」&& count.getAndIncrement()<8){...}它工作。 – Peter

+0

如何讓這些請求失敗?像, 我有以下代碼中的3個條件, 1.如果請求Count> 8,則退出循環 2.如果WorkflowStatus == False,則退出循環 3.如果WorkflowFailed == True,則退出循環 在上述任何情況下,有許多請求失敗的機會,例如,如果在觸發請求8次後WorkflowStatus未獲得「真」,那麼該請求應失敗。但不是顯示失敗計數顯示成功計數。 如何計算並顯示在上述條件下失敗的失敗請求 – Peter

1

我個人使用這個技巧在每個請求有一個計數器遞增

val scn = scenario("Scenario Conversion") 
.exec{session => session.set("number",session.userId.split("-").last.toInt)} 

您可以在另一個會話值

val scn = scenario("Scenario Conversion") 
.exec{session => session.set("number",session.userId.split("-").last.toInt)} 
.exec{session => session.set("timestamp", nextDay(session("number").as[Int]/1000))} 
+0

感謝您的答案@crak。如果可能的話,你能幫我解決這個問題嗎?如果我的計數大於8或FailedStatus = true,我想將KO狀態。請看看。 http://stackoverflow.com/questions/39991234/how-to-add-status-ko-in-gatling-script – Peter

+0

@peter你可以使用會話(「號碼」)在檢查功能? – crak

+0

怎麼樣?任何語法或例子? – Peter