从设置线程组(jmeter)获取线程组中的线程数
我有一个JMeter测试计划,它只执行一次简单的操作 我遇到的问题是,我的测试设置需要知道线程组将有多少线程。为了让事情更清楚,下面是测试计划的一个简单表示:从设置线程组(jmeter)获取线程组中的线程数,jmeter,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 "Numbe
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完全无关,因此不是重复的您可以尝试在测试计划中定义一个用户定义的变量,比如“Users\u Test”,并为其分配要运行测试的虚拟用户数
然后,只需在线程组“线程数(用户):${users\u test}中使用该变量,您就可以在设置中执行相同的操作。您可以尝试在测试计划中定义一个用户定义的变量,比如“users\u test”,并为其分配要运行测试的虚拟用户数
然后,只需在线程组“线程数(用户):${users\u test}中使用该变量,您就可以在设置中执行相同的操作。不知道线程数的速度表明您的测试设计糟糕 事实上,你已经在6小时前得到了同一问题的答案,这表明你不愿意学习,更喜欢社区为你解决问题 以防万一,我会用更简单的词重复:
- 如果需要克服JMeter的限制,就必须使用脚本
- 建议的方法是使用和
- JMeterAPI引用位于
- 文章提供了将Groovy与JMeterAPI结合使用的示例
- 获取所有线程组的线程数的示例代码:
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()) }
演示:import org.apache.jmeter.engine.StandardJMeterEngine 导入org.apache.jmeter.threads.ThreadGroup 导入org.apache.jorphan.collections.HashTree 导入org.apache.jorphan.collections.SearchByClass 导入java.lang.reflect.Field StandardJMeterEngine=ctx.getEngine() 字段测试=engine.getClass().getDeclaredField(“测试”) test.setAccessible(true) HashTree testPlanTree=(HashTree)test.get(引擎) SearchByClass threadGroupSearch=新建SearchByClass(ThreadGroup.class) testPlanTree.traverse(threadGroupSearch) 集合threadGroups=threadGroupSearch.getSearchResults() threadGroups.each{ log.info(“线程组:“+it.getName()+”;线程数:“+it.getNumThreads()”) }
- 如果需要克服JMeter的限制,就必须使用脚本
- 建议的方法是使用和
- JMeterAPI引用位于
- 文章提供了将Groovy与JMeterAPI结合使用的示例
- 获取所有线程组的线程数的示例代码:
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()) }
演示:import org.apache.jmeter.engine.StandardJMeterEngine 导入org.apache.jmeter.threads.ThreadGroup 导入org.apache.jorphan.collections.HashTree 导入org.apache.jorphan.collections.SearchByClass 导入java.lang.reflect.Field StandardJMeterEngine=ctx.getEngine() 字段测试=engine.getClass().getDeclaredField(“测试”) test.setAccessible(true) HashTree testPlanTree=(HashTree)test.get(引擎) SearchByClass threadGroupSearch=新建SearchByClass(ThreadGroup.class) testPlanTree.traverse(threadGroupSearch) 集合threadGroups=threadGroupSearch.getSearchResults() threadGroups.each{ log.info(“线程组:“+it.getName()+”;线程数:“+it.getNumThreads()”) }