jmeter-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Stromas, Aaron (NIH/OD) [C]" <stroma...@od.nih.gov>
Subject RE: ForEach and BeanShell question
Date Fri, 26 Jun 2009 15:41:36 GMT
Maybe the problem is elsewhere... This is an excerpt of the test plan:

ForEach
    Debug Sampler
    If Controller (: ${threetuple} != null
        BeanShell Preprocessor :
           String[] p = vars.get("threetuple").split("~");
           for (int i = 1; i <= p.length; i++) {
              vars.put("params_" + i, p[i]);
           }
    Debug Sampler

The first Debug Sampler shows that threetuple is not null, so I expect to see params_1, params_2,...
 in the second Debug Sampler, but I don't see them. Why? (sorry for dragging this on)

-a

-----Original Message-----
From: sebb [mailto:sebbaz@gmail.com] 
Sent: Friday, June 26, 2009 10:36 AM
To: JMeter Users List
Subject: Re: ForEach and BeanShell question

On 26/06/2009, Stromas, Aaron (NIH/OD) [C] <stromasam@od.nih.gov> wrote:
>
>
>  -----Original Message-----
>  From: sebb [mailto:sebbaz@gmail.com]
>
> Sent: Friday, June 26, 2009 9:39 AM
>  To: JMeter Users List
>  Subject: Re: ForEach and BeanShell question
>
>  On 26/06/2009, Stromas, Aaron (NIH/OD) [C] <stromasam@od.nih.gov> wrote:
>  > -----Original Message-----
>  >  From: sebb [mailto:sebbaz@gmail.com]
>  >
>  > Sent: Friday, June 26, 2009 8:45 AM
>  >  To: JMeter Users List
>  >  Subject: Re: ForEach and BeanShell question
>  >
>  >  On 26/06/2009, Stromas, Aaron (NIH/OD) [C] <stromasam@od.nih.gov> wrote:
>  >  >
>  >  >
>  >  >  -----Original Message-----
>  >  >  From: sebb [mailto:sebbaz@gmail.com]
>  >  >  Sent: Thursday, June 25, 2009 2:08 PM
>  >  >  To: JMeter Users List
>  >  >  Subject: Re: ForEach and BeanShell question
>  >  >
>  >  >  On 25/06/2009, Stromas, Aaron (NIH/OD) [C] <stromasam@od.nih.gov>
wrote:
>  >  >  > Greetings!
>  >  >  >
>  >  >  >  I have a test plan that uses a RE Extractor to convert the values
of the HTML select element to the input values of the ForEach controller. These values are
of the form X,M,N~Y,A,B~...~Z,C,D, and I can see from the log that they are properly generated.
The reference name for these values is tuple. The ForEach controller Input variable prefix
is tuple, and the Output variable name is threetuple.
>  >  >  >
>  >  >  >  I am emulating Javascript which breaks up the value of selected option
and submits an HTTP request with the values of each of thre-tuple as parameter. To that end,
I have another ForEach controller as a child of the first one with the BeanShell preprocessor:
>  >  >  >
>  >  >  >  String[] tuples = vars.get("threetuple_1").split("~");
>  >  >  >
>  >  >  >  List list = new ArrayList();
>  >  >  >
>  >  >  >  for (int i = 0; i < tuples.length; i++) {
>  >  >  >     list.add(tuples[i].split(","));
>  >  >  >  }
>  >  >  >
>  >  >  >  vars.put("params", list);
>  >  >  >
>  >  >  >  The inner ForEach controller has a HTTP Request sampler with a BeanShell
preprocessor whose job is to break up the three-tuple into individual parameters.
>  >  >  >
>  >  >  >  In short, no HTTP sampler ever executes, and the log shows that the
inner ForEach controller receives null input.
>  >  >  >
>  >  >  >  I can see in the log, what I presume to be invocation of the outer
ForEach:
>  >  >  >
>  >  >  >  ... jmeter.control.ForEach resultstring isDone=SAR,713,0~RCC,988,343...
>  >  >  >
>  >  >  >
>  >  >  >  and the inner ForEach:
>  >  >  >
>  >  >  >  ... jmeter.control.ForeachController: No entries found - null first
entry: params_1
>  >  >  >
>  >  >  >  The questions are: is there any way of knowing why the BeanShell preprocessor
did not execute?
>  >  >  >
>  >  >  >  Once that problem resolved, I need to tackle the business of the ForEach
output variable which gets loop index appended to it, so how can the BeanShell "know" which
variable to use?
>  >  >  >
>  >  >  >  Any suggestions?
>  >  >
>  >  >  The ForEach Controller needs multiple variables, not a list:
>  >  >
>  >  >  http://jakarta.apache.org/jmeter/usermanual/component_reference.html#ForEach_Controller
>  >  >
>  >  >
>  >  >
>  >  > It still isn't working for me. This is the schematic of my test:
>  >  >
>  >  >  ForEach controller
>  >  >    Input var prefix: tuple
>  >
>  >  What sets "tuple_1" etc?
>  >
>  >
>  > These are set by the Regular Expression extractor prior the ForEach controller
(Reference Name: tuple)
>  >
>  >
>  >  >    Output var name: threetuple
>  >  >    |
>  >  >    |
>  >  >    ForEach controller
>  >  >       Input var prefix: params
>  >
>  >  These need to be set BEFORE the controller is executed.
>  >
>  >
>  > That is what the BeanShell PREprocessor is for, is it not?
>
>  Pre-Processors are invoked before samplers in their scope.
>
>
> Which is precisely what I'm trying to achieve. Namely, I need the preprocessor to run
before the inner ForEach controller executes, but it does not happen. The Debug Sampler does
not show any params_* suggesting that the preprocessor didn't execute. I don't see what I'm
doing wrong. :-(
>

You have put the PreProcessor inside the ForEach Controller, so it
only exectutes if the FE controller runs.

>
>  >
>  >  >       Output var prefix: reqparams
>  >  >       |
>  >  >       |
>  >  >       BeanShell preprocessor
>  >  >       |   String packed = vars.get("threetuple")
>  >  >       |   String[] tuples =packed.split("~");
>  >  >       |   for (int i = i; i <= tuples.length; i++) {
>  >
>  >  I presume that is int i = 1; ...
>  >
>  > Yes, of course, I was free typing, not cut'n pasting
>  >
>  >
>  >  >       |       vars.put("params" + "_" + i, tuples[i-1]);
>  >  >       |
>  >  >       |
>  >
>  >  This is all too late.
>  >
>  >  >       HTTP request
>  >  >       |
>  >  >       BeanShell preprocessor
>  >
>  >  Did you mean post-processor?
>  >
>  >
>  > No, the idea is to unpack the string into parameters for the HTTP request.
>
>  OK, then it would be clearer to move it before the sampler, though of
>  course that won't affect when it is called.
>
>  >
>  >  >            String packed = vars.get("params");
>  >  >            String[] names = new String[]{"type", "p1", "p2", "p3"};
>  >  >            for (int i = 0; i < names.length; i++) {
>  >  >                vars.put(names[i], p[i]);
>  >  >            }
>  >  >
>  >  >
>  >  >  I have also tried vars.get("threetuple_1") in the first BeanShell. No matter
what I try, in the log I see "jmeter.control.ForeachController: No entries found - null first
entry: params_1".
>  >
>  >  That's because it is null.
>  >
>  >  >  Sorry for badgering, but I must be missing something basic. TIA,
>  >
>  >  Use the Debug Sampler to show what variables are set at that point in
>  >  the test plan.
>  >
>  >
>  > That is golden, thank you. I tried to use it before, but probably at the wrong
place, so it didn't show me much.
>
>  Use it liberally.
>
>  >
>  >  >  -a
>  >  >
>  >  >
>  >  >  ---------------------------------------------------------------------
>  >  >  To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
>  >  >  For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
>  >  >
>  >  >
>  >
>  >  ---------------------------------------------------------------------
>  >  To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
>  >  For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
>  >
>  >
>  >  ---------------------------------------------------------------------
>  >  To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
>  >  For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
>  >
>  >
>
>  ---------------------------------------------------------------------
>  To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
>  For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
>
>
>  ---------------------------------------------------------------------
>  To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
>  For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
>
>

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


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


Mime
View raw message