n 29/11/2007, dennis <[EMAIL PROTECTED]> wrote:
> Hi all,
>
> I have a test plan which uses "switch controller" to distribute load to
> 2 HTTP request.
>
> My test plan looks like this:
>
> Thread Group
> -User Defined Variables
Probably unnecessary.
> -Beanshell Sampler
> -Java request
> -Switch Controller
> -HTTP Sampler1
> -HTTP Sampler2
>
> 1, In "User Defined Variables", I defined a variable named "RAND";
> 2, In Beanshell Sampler, code generated a random 0 or 1, then put the
> value to ${RAND}.
>
> int r = Math.rand()*10;
> if(r<5) vars.put("RAND", "0");
> else vars.put("RAND", "1");
Are you sure about that code? Does not work for me, as Math.rand()
does not exist and Math.random() returns a double, not an int.
> 3, Switch Controller used {$RAND} as its switch value.
> 4, The Java request is used to monitor the value generated by Beanshell
> script, so I just set Label as "RAND=${RAND}".
>
> When run the test plan, I set 10 thread to run 100 loops, what
> surprised me is the summary result:
>
> Label #Samples ...
> RAND=0 526
> RAND=1 474
> HTTP Sampler1 532
> HTTP Sampler2 468
>
> What I expected is the #samples of "RAND=0" and "HTTP Sampler1" are the
> same, while the #samplers of "RAND=1" and "HTTP Sampler2" are the same.
>
> Can anyone explain it?
I think it is due to timing - it looks as though the Switch Controller
is evaluating the RAND variable before it gets reset by BeanShell. To
check this, you can use the __log() function, i.e. use
${__log(${RAND})}
as the Switch value.
If you omit the UDV, you will see that the RAND variable is not
defined the first time round - and will be taken as 0.
Looks like there might be a bug here ...
>
> Thanks,
> Dennis
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]