2008/5/3 anneb <[EMAIL PROTECTED]>:
> Hi,
>
> I am trying to do some calculations with variables inside a loop
> controller, but it looks like variables are reset to their initial
> values each time the loop is executed.
>
> What I am doing (Jmeter 2.3.1):
>
> test plan
> --thread group
> ----User defined variables (name: y, value 0)
> ----Loop Controller (loop count: 4)
> ------User defined variables (name: z, value ${__javaScript(${y}+1,y)} )
> ------Debug Sampler
> ------View Results Tree
>
> according to the documentation the function ${__javaScript(${y}+1 ,
> y)} adds 1 to the value of jmeter variable 'y' and stores the result
> in jmeter variable y.
>
Yes.
However intSum() would perhaps be simpler to use in this case.
> Indeed something like that seems to happen, because this is what I get
> under tab "response data" for each of the 4 elements in the reponse
> tree:
> JMeterVariables:
> START.YMD=20080502
> JMeterThread.last_sample_ok=true
> y=1
> START.MS=1209764719713
> z=1
> START.HMS=234519
> y=0
>
>
> I was hoping to see y increase by 1 for every iteration through the
> loop, but it remains stuck at a value of 1.
>
> What is happening? What am I doing wrong? Why does variable 'y' seem
> to be reinitialized when assigned to new user defined variable 'z'?
UDVs are Configuration items - they are processed once at the start.
> How can I use variables inside a loop that memorize values assigned in
> previous iterations through the loop?
>
> I looked at other ways of changing variables in loops such as the
> counter pre processor, but for my metering purposes I need more
> variables and I need to do more than just simple increments by fixed
> amounts.
>
> Then I found the BSF sampler, but there is at least an error in the
> documentation:
> at http://jakarta.apache.org/jmeter/usermanual/component_reference.html
> where it is stated that responses should be returned through
>
> SampleResponse.setSuccessful(true/false)
> SampleResponse.setResponseCode("code")
> SampleResponse.setResponseMessage("message")
>
> but "SampleResponse" is not a known object to javascript in this context.
> I figured out that instead SampleResponse
>
> SampleResult.setSuccessful(true);
>
> should be used.
I guess the docs need to be updated...
> resulting in the following setup:
> test plan
> --thread group
> ----User defined variables (name: y, value 0)
> ----Loop Controller (loop count: 4)
> ------BSF Sampler
> ------Debug Sampler
> ------View Results Tree
>
> The BSF Sampler script is:
> vars.put("y",${y}+1);
> SampleResult.setSuccessful(true);
> SampleResult.setResponseCode("200");
> SampleResult.setResponseMessage("OK") ;
>
>
> Now only the first iteration through the loop works reasonably well:
> Result Tree response data:
> BSF Sampler:
> [EMAIL PROTECTED]
> Debug Sampler:
> JMeterVariables:
> START.YMD=20080502
> JMeterThread.last_sample_ok=true
> START.MS=1209764719713
> START.HMS=234519
> y=1
>
> However in the second and later iterations the BSF sampler fails and
> jmeter.log contains the following messages:
>
> WARN - jmeter.protocol.java.sampler.BSFSampler:
> java.lang.RuntimeException: No Context associated with current Thread
> at org.mozilla.javascript.Context.getContext(Context.java:2195)
> at
> org.mozilla.javascript.ScriptRuntime.toObject(ScriptRuntime.java:834)
> at org.mozilla.javascript.Context.toObject(Context.java:1572)
>
> It looks like the required jmeter context passed to the javascript
> interpreter got lost at the end of the first execution of the BSF
> sampler?
Possibly, I've not used BSF much.
> Is there a working sample around that does some variable arithmetic
> wile iterating through a control loop?
Try using the User Parameters Pre-Processor instead; that will run
before every sample in scope.
Or use the functions on the samplers directly.
> Thanks,
>
> Anne
>
> ---------------------------------------------------------------------
> 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]