2017-04-19 37 views
0

我有一個執行一次簡單操作的JMeter測試計劃。從設置線程組(jmeter)獲取線程組中的線程數

我遇到的問題是我的測試設置需要知道線程組將具有多少個線程。爲了讓事情更清晰,這裏是測試計劃的簡單表示:

setUp Thread Group 
    needs to know the number of threads in the below thread group 
Thread Group 
    The number of threads for this thread group is determined via the "Number of Threads (users)" Thread Property. 

我可以動態地從線程組中獲得的線程數,但我不能找到讓內這個數字的任何方式而不是設置線程組。

任何想法?

理想情況下,我希望能找到像${__groovy(ctx.getTestPlan().getThreadGroupByIndex(1).getNumThreads())}這樣的東西,但是我找不到這樣的東西。

爲了清楚起見,我正在尋找在線程組屬性中直接在JMeter中分配的線程數。這個問題有絕對無關,與BlazeMeter,因此Get number of threads (defined via BlazeMeter) in a thread group from the setup thread group (jmeter)

+0

的[獲取線程數從設置線程組(JMeter的)線程組中(經由BlazeMeter定義)]可能的複製(http://stackoverflow.com/questions/43500371 /線程數定義 - 通過火焰原子線程定義 - 線程組 - 從設置) –

+0

它不是重複的,另一個問題是關於找到線程數爲由BlazeMeter分配,而這一個涉及將其直接分配給JMeter – Shawn

+0

你如何運行你的測試?通過CMD提示或從UI? –

回答

0

的快,你不知道電話號碼線程表示您的測試設計很糟糕。

,你已經給出了同樣的問題前6小時答案的事實表明,你是不願意學習,喜歡社區爲您排憂解難。

以防萬一我會重複使用更簡單的單詞:

  • 如果你需要克服你必須去的腳本一個JMeter的限制
  • 推薦的方法是在https://jmeter.apache.org/api/
  • Check out Groovy Is the New Black文章使用JSR223 Test ElementsGroovy language
  • JMeter的API參考生活使用Groovy中使用的例子JMeter API
  • 獲取所有線程組的線程數的示例代碼:

    import org.apache.jmeter.engine.StandardJMeterEngine 
    import org.apache.jmeter.threads.ThreadGroup 
    import org.apache.jorphan.collections.HashTree 
    import org.apache.jorphan.collections.SearchByClass 
    import java.lang.reflect.Field 
    
    StandardJMeterEngine engine = ctx.getEngine() 
    Field test = engine.getClass().getDeclaredField("test") 
    test.setAccessible(true) 
    HashTree testPlanTree = (HashTree) test.get(engine) 
    
    SearchByClass<ThreadGroup> threadGroupSearch = new SearchByClass<>(ThreadGroup.class) 
    testPlanTree.traverse(threadGroupSearch) 
    Collection<ThreadGroup> threadGroups = threadGroupSearch.getSearchResults() 
    threadGroups.each { 
        log.info("Thread Group: " + it.getName() + "; Number of threads: " + it.getNumThreads()) 
    } 
    

    演示:

    JMeter Groovy get thread groups number

+0

我接受了你的答案,但我認爲沒有垃圾話會好得多。你對我的行爲的假設對社區沒有任何貢獻,他​​們是錯誤的。我在6小時前沒有給出同一個問題的答案,實際上這不是同一個問題,正如我在編輯中解釋的那樣。您甚至可能會注意到,在這種情況下,對上一個問題的工作答案不起作用。在這兩種情況下,我都用腳本嘗試自己,但都失敗了。事實上,你的代碼對於熟悉Groovy和Jmeter運行時的人來說是微不足道的。' – Shawn

+0

這就是爲什麼我將這個問題標記爲可能的重複:) –

1

重複你可以嘗試在測試計劃定義一個用戶定義的變量,讓我們說「Users_test」併爲其分配虛擬用戶的數量,您想要運行測試。

然後,只需使用該變量的線程組「線程數(用戶):$ {} Users_test,你可以做同樣在設置

+0

+1是的,這是計劃B.我希望能夠專門訪問線程組屬性的值。 – Shawn