2016-12-28 56 views
0

我試圖創建一個測試計劃,當達到某個值時,然後發生一些功能。測試計劃由多個以循環運行的線程組成,當達到某些條件時,我想發起HTTP請求。我會在下面討論它的內核: 在我的測試中,我有多線程循環方式的邏輯,當條件滿足時(條件每10秒滿足一次),那麼我需要迭代通過一個值,它的價值應該從以前的迭代保存 - 我定義的值是一個屬性(user.properties) - startIndex = 0(初始化爲0)。 所以我做了一個While Controller它的狀況是這樣的:JMeter循環索引和屬性更新

${__javaScript(${__P(startIndex,)}<=${currBulk},)}

我期待的HTTP請求,這依賴於內部,而價值startIndex要當startIndex<=currBulk變量執行。

While Controller裏面的HTTP請求應該被解僱,直到所有的指標都包括在內,我都寫過這樣的內部BeanShell PostProcessor

int startIndexIncInt = Integer.parseInt(props.getProperty("startIndex")); //get the initiated index of the loop 
startIndexIncInt = startIndexIncInt + 1; //increment it and see if needed to fire the request again, by the original While condition 
vars.put("startIndexIncIntVar", String.valueOf(startIndexIncInt)); 
props.put("startIndex",vars.get("startIndexIncIntVar")); //the property incremental and update 

所以,我爲了把它設計一樣,在下一時間(10秒後)我將更新startIndex,這將與新的currBulk(它總是由我的測試計劃更新)進行比較。 而我只是不能完成它。我不斷收到類似的錯誤:

startIndexIncInt = Integer.parseInt(props.ge . . . '' : Typed variable declaration : Method Invocation Integer.parseInt 

不用說,我也定義不設置好的了var startIndexIncIntVar(我通過調試取樣檢查)。 此外,我的問題是沒有與時間進入while,我的問題基本上是我應該增量和使用我的HTTP請求(while條件,和beanshell後處理器腳本)的變量

只爲更多它的信息,如果我寫它的僞代碼它應該是這樣的:

startInc = 0 
----Test plan loop---- 
------ test logic, currBulk incremented through the test----- 
if(time condition to enter while){ 
    while (startIndex <= currBulk){ 
    Send HTTP request (the request depends on startIndex value) 
    startIndex++ 
    } 
} 

請協助

回答

1

,因爲我看不到任何的BeanShell腳本,這似乎是與你的startIndex財產問題錯誤,代碼是好的,所以我的期望是startIndex屬性未設置或不能轉換爲整數。您可以通過兩種方式獲得關於你的BeanShell腳本中的問題的方法的詳細信息:

  1. 添加debug()命令腳本的開始 - 你會看到很多在控制檯窗口調試輸出。
  2. 把你的代碼中try block,如:

    try { 
        int startIndexIncInt = Integer.parseInt(props.getProperty("startIndex")); //get the initiated index of the loop 
        startIndexIncInt = startIndexIncInt + 1; //increment it and see if needed to fire the request again, by the original While condition 
        vars.put("startIndexIncIntVar", String.valueOf(startIndexIncInt)); 
        props.put("startIndex", vars.get("startIndexIncIntVar")); //the property incremental and update 
    } catch (Throwable ex) { 
        log.error("Beanshell script failure", ex); 
        throw ex; 
    } 
    

    這樣你就可以看到問題的原因在JMeter的。日誌文件

其實看來你是overscripting遞增一個變量可以使用內置的組件,如Counter測試元件或__counter()函數來完成。有關該域的更多信息,請參閱How to Use a Counter in a JMeter Test文章。