You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jmeter-dev@jakarta.apache.org by Edgar Poce <ed...@gmail.com> on 2005/08/11 08:57:33 UTC

If controller condition evaluation

hi

I'm using Jmeter for testing a local app and I found that the If 
Controller doesn't behave as I expected. The expected behavior is that 
it evaluates the condition once per child element, or just once?. I 
dived into the code and I found that the If controller evaluates the 
condition for each sampler (option B. see below) . I read the javadocs 
and it's still not clear, it says

<snip>
  * it will execute the set of statements
  * (samplers/controllers, etc) while the 'condition' is true.
  * In a programming world - this is equivalant of :
  *   if (condition) {
  *        statements ....
  *   }
</snip>

A.
if (condition) {
  statements....
}

is different from

B.
while (condition) {
  next statement
}

Personally, I'd prefer option A. rather than B. WDYT?. I attach a patch. 
The patch adds an instance variable that holds the result obtained on 
the first evaluation.

BR,
edgar

Re: If controller condition evaluation

Posted by sebb <se...@gmail.com>.
A work-round might be to add a SimpleController, viz:

If Controller
 Simple Controller
   Sampler 1
   Sampler 2

S.

On 11/08/05, Edgar Poce <ed...@gmail.com> wrote:
> hi
> 
> I'm using Jmeter for testing a local app and I found that the If
> Controller doesn't behave as I expected. The expected behavior is that
> it evaluates the condition once per child element, or just once?. I
> dived into the code and I found that the If controller evaluates the
> condition for each sampler (option B. see below) . I read the javadocs
> and it's still not clear, it says
> 
> <snip>
>  * it will execute the set of statements
>  * (samplers/controllers, etc) while the 'condition' is true.
>  * In a programming world - this is equivalant of :
>  *   if (condition) {
>  *        statements ....
>  *   }
> </snip>
> 
> A.
> if (condition) {
>  statements....
> }
> 
> is different from
> 
> B.
> while (condition) {
>  next statement
> }
> 
> Personally, I'd prefer option A. rather than B. WDYT?. I attach a patch.
> The patch adds an instance variable that holds the result obtained on
> the first evaluation.
> 
> BR,
> edgar
> 
> 
> Index: IfController.java
> ===================================================================
> RCS file: /home/cvspublic/jakarta-jmeter/src/core/org/apache/jmeter/control/IfController.java,v
> retrieving revision 1.11
> diff -u -r1.11 IfController.java
> --- IfController.java   12 Jul 2005 20:51:00 -0000      1.11
> +++ IfController.java   11 Aug 2005 06:43:42 -0000
> @@ -50,6 +50,8 @@
> 
>        private final static String CONDITION = "IfController.condition";
> 
> +    private Boolean result = null ;
> +
>        /**
>         * constructor
>         */
> @@ -143,8 +145,11 @@
>         *      the iteration even starts !
>         */
>        public Sampler next() {
> -               boolean result = evaluateCondition(getCondition());
> -               if (result)
> +        if (this.current==0)
> +        {
> +            result = new Boolean(evaluateCondition(getCondition()));
> +        }
> +               if (result.booleanValue())
>                        return super.next();
>                else
>                        try {
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: jmeter-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: jmeter-dev-help@jakarta.apache.org
> 
>

---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-dev-help@jakarta.apache.org