2016-12-28 50 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文章。