You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@jmeter.apache.org by Marc Limotte <ms...@gmail.com> on 2010/01/12 18:27:53 UTC

How to pull multiple lines from a file and join them for use in a single HTTP request

Hi,

I'm looking for some suggestions on how to pull a random number of lines
from a file and concatenate them together for a single HTTP request.  In a
bit more detail:

I have a CSV file (two columns, but I'm only interested in the first
column) with almost 200,000 lines.  Each line contains a unique id.  I then
want to pull a random number of ids (between 1 and 60), join them with a
comma delimiter and make an HTTP request with the whole string.

For example, the file might contain:

http://rest.acme.com:8888/items/130,127,2,97
or
http://rest.acme.com:8888/items/127,26,31

Where 130, 127, 2, etc; are ids pulled from the file.

I can pre-sort the file randomly if I need to, so reading the lines in the
file in sequence is not a problem.

I tried a number of approaches using a CSV Data Set, or __CSVRead.  In
general, my approach was to use a Loop controller with a random number as
the "Loop Count"; and then use a BeanShell Pre-Processor or a UserParameters
expression to concatenate the values.  I tried using a variable and using a
property.  But none of this worked... it seems that the values created
inside the loop are not available to the HTTP request outside the loop.

Any suggestions on how I might be able to do this.

Marc

Re: How to pull multiple lines from a file and join them for use in a single HTTP request

Posted by sebb <se...@gmail.com>.
On 12/01/2010, Marc Limotte <ms...@gmail.com> wrote:
> Hi,
>
>  I'm looking for some suggestions on how to pull a random number of lines
>  from a file and concatenate them together for a single HTTP request.  In a
>  bit more detail:
>
>  I have a CSV file (two columns, but I'm only interested in the first
>  column) with almost 200,000 lines.  Each line contains a unique id.  I then
>  want to pull a random number of ids (between 1 and 60), join them with a
>  comma delimiter and make an HTTP request with the whole string.
>
>  For example, the file might contain:
>
>  http://rest.acme.com:8888/items/130,127,2,97
>  or
>  http://rest.acme.com:8888/items/127,26,31
>
>  Where 130, 127, 2, etc; are ids pulled from the file.
>
>  I can pre-sort the file randomly if I need to, so reading the lines in the
>  file in sequence is not a problem.

So why not convert the file into the required final format so you can
just read a line at a time?

>  I tried a number of approaches using a CSV Data Set, or __CSVRead.  In
>  general, my approach was to use a Loop controller with a random number as
>  the "Loop Count"; and then use a BeanShell Pre-Processor or a UserParameters
>  expression to concatenate the values.  I tried using a variable and using a
>  property.  But none of this worked... it seems that the values created
>  inside the loop are not available to the HTTP request outside the loop.
>
>  Any suggestions on how I might be able to do this.
>
>
>  Marc
>

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


Re: How to pull multiple lines from a file and join them for use in a single HTTP request

Posted by Marc Limotte <ms...@gmail.com>.
Thanks, Deepak.  I went ahead and used TestActionSampler and got
everything working.

On Tue, Jan 12, 2010 at 10:59 AM, Deepak Shetty <sh...@gmail.com> wrote:
> Hi
> If I remember correctly Pre processors wont work unless you have atleast one
> sampler . The way around this is
> a. Use a Bean Shell Sampler instead (will show up in the results though)
> b. Use a TestActionSampler (this is a dummy sampler which will allow you to
> attach your Pre Processor)
>
> regards
> deepak
>
> On Tue, Jan 12, 2010 at 10:52 AM, Marc Limotte <ms...@gmail.com> wrote:
>
>> Hi Deepak.
>>
>> Thanks for correcting me.  After adding a Debug Sampler as you
>> suggested, I see now that the loop only works if the Sampler exists.
>> So, I've gotten my test plan to work... but only if the Debug Sampler
>> is included and enabled.  Do you know why that is?  I don't want to
>> leave Debug on, b/c of it's impact on the testing performance.
>>
>> I did verify that there are no errors in jmeter.log.  Here is the
>> structure of my test:
>>
>> Thread Group
>>    Random Variable
>>    Loop Controller (loop count is the Random Variable)
>>        Only Once
>>            BeanShell Pre Proc (   vars.put("mylist","");   )
>>            *DebugSampler
>>        CSV Data Set Config
>>        BeanShell Pre Proc  (   concats the last value from the CSV to
>> "mylist"  )
>>        *DebugSampler
>>    HTTP Sampler ( uses the variable ${mylist}  )
>>    View Results Tree
>>
>> Again, if I disable either of those DebugSamplers, it stops working.
>>
>> Marc
>>
>>
>> On Tue, Jan 12, 2010 at 9:35 AM, Deepak Shetty <sh...@gmail.com> wrote:
>> >> I tried using a variable and using a
>> >>property.  But none of this worked... it seems that the values created
>> >>inside the loop are not available to the HTTP request outside the loop.
>> > Not true. If you set a variable it is available outside . use a debug
>> > sampler with a view results tree listener to see what values get set and
>> > check you are using the variable in the HTTP request .
>> > If you still cant figure it out , please provide the structure of your
>> test
>> > (for e.g. you might have attached the pre processor to an incorrect
>> > location  , e.g. if it is under a controller then it applies to all
>> elements
>> > in the controller) and finally check jmeter.log to verify that your
>> > beanshell is actually executing without errors.
>> >
>> > regards
>> > deepak
>> >
>> > On Tue, Jan 12, 2010 at 9:27 AM, Marc Limotte <ms...@gmail.com>
>> wrote:
>> >
>> >> Hi,
>> >>
>> >> I'm looking for some suggestions on how to pull a random number of lines
>> >> from a file and concatenate them together for a single HTTP request.  In
>> a
>> >> bit more detail:
>> >>
>> >> I have a CSV file (two columns, but I'm only interested in the first
>> >> column) with almost 200,000 lines.  Each line contains a unique id.  I
>> then
>> >> want to pull a random number of ids (between 1 and 60), join them with a
>> >> comma delimiter and make an HTTP request with the whole string.
>> >>
>> >> For example, the file might contain:
>> >>
>> >> http://rest.acme.com:8888/items/130,127,2,97
>> >> or
>> >> http://rest.acme.com:8888/items/127,26,31
>> >>
>> >> Where 130, 127, 2, etc; are ids pulled from the file.
>> >>
>> >> I can pre-sort the file randomly if I need to, so reading the lines in
>> the
>> >> file in sequence is not a problem.
>> >>
>> >> I tried a number of approaches using a CSV Data Set, or __CSVRead.  In
>> >> general, my approach was to use a Loop controller with a random number
>> as
>> >> the "Loop Count"; and then use a BeanShell Pre-Processor or a
>> >> UserParameters
>> >> expression to concatenate the values.  I tried using a variable and
>> using a
>> >> property.  But none of this worked... it seems that the values created
>> >> inside the loop are not available to the HTTP request outside the loop.
>> >>
>> >> Any suggestions on how I might be able to do this.
>> >>
>> >> Marc
>> >>
>> >
>>
>> ---------------------------------------------------------------------
>> 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


Re: How to pull multiple lines from a file and join them for use in a single HTTP request

Posted by sebb <se...@gmail.com>.
On 12/01/2010, Deepak Shetty <sh...@gmail.com> wrote:
> Hi
>  If I remember correctly Pre processors wont work unless you have atleast one
>  sampler .

You can't apply a Pre-Processor to something that's not there ...

Same is true of Post Processors and Timers.

>  The way around this is
>  a. Use a Bean Shell Sampler instead (will show up in the results though)
>  b. Use a TestActionSampler (this is a dummy sampler which will allow you to
>  attach your Pre Processor)
>
>  regards
>
> deepak
>
>
>  On Tue, Jan 12, 2010 at 10:52 AM, Marc Limotte <ms...@gmail.com> wrote:
>
>  > Hi Deepak.
>  >
>  > Thanks for correcting me.  After adding a Debug Sampler as you
>  > suggested, I see now that the loop only works if the Sampler exists.
>  > So, I've gotten my test plan to work... but only if the Debug Sampler
>  > is included and enabled.  Do you know why that is?  I don't want to
>  > leave Debug on, b/c of it's impact on the testing performance.
>  >
>  > I did verify that there are no errors in jmeter.log.  Here is the
>  > structure of my test:
>  >
>  > Thread Group
>  >    Random Variable
>  >    Loop Controller (loop count is the Random Variable)
>  >        Only Once
>  >            BeanShell Pre Proc (   vars.put("mylist","");   )
>  >            *DebugSampler
>  >        CSV Data Set Config
>  >        BeanShell Pre Proc  (   concats the last value from the CSV to
>  > "mylist"  )
>  >        *DebugSampler
>  >    HTTP Sampler ( uses the variable ${mylist}  )
>  >    View Results Tree
>  >
>  > Again, if I disable either of those DebugSamplers, it stops working.
>  >
>  > Marc
>  >
>  >
>  > On Tue, Jan 12, 2010 at 9:35 AM, Deepak Shetty <sh...@gmail.com> wrote:
>  > >> I tried using a variable and using a
>  > >>property.  But none of this worked... it seems that the values created
>  > >>inside the loop are not available to the HTTP request outside the loop.
>  > > Not true. If you set a variable it is available outside . use a debug
>  > > sampler with a view results tree listener to see what values get set and
>  > > check you are using the variable in the HTTP request .
>  > > If you still cant figure it out , please provide the structure of your
>  > test
>  > > (for e.g. you might have attached the pre processor to an incorrect
>  > > location  , e.g. if it is under a controller then it applies to all
>  > elements
>  > > in the controller) and finally check jmeter.log to verify that your
>  > > beanshell is actually executing without errors.
>  > >
>  > > regards
>  > > deepak
>  > >
>  > > On Tue, Jan 12, 2010 at 9:27 AM, Marc Limotte <ms...@gmail.com>
>  > wrote:
>  > >
>  > >> Hi,
>  > >>
>  > >> I'm looking for some suggestions on how to pull a random number of lines
>  > >> from a file and concatenate them together for a single HTTP request.  In
>  > a
>  > >> bit more detail:
>  > >>
>  > >> I have a CSV file (two columns, but I'm only interested in the first
>  > >> column) with almost 200,000 lines.  Each line contains a unique id.  I
>  > then
>  > >> want to pull a random number of ids (between 1 and 60), join them with a
>  > >> comma delimiter and make an HTTP request with the whole string.
>  > >>
>  > >> For example, the file might contain:
>  > >>
>  > >> http://rest.acme.com:8888/items/130,127,2,97
>  > >> or
>  > >> http://rest.acme.com:8888/items/127,26,31
>  > >>
>  > >> Where 130, 127, 2, etc; are ids pulled from the file.
>  > >>
>  > >> I can pre-sort the file randomly if I need to, so reading the lines in
>  > the
>  > >> file in sequence is not a problem.
>  > >>
>  > >> I tried a number of approaches using a CSV Data Set, or __CSVRead.  In
>  > >> general, my approach was to use a Loop controller with a random number
>  > as
>  > >> the "Loop Count"; and then use a BeanShell Pre-Processor or a
>  > >> UserParameters
>  > >> expression to concatenate the values.  I tried using a variable and
>  > using a
>  > >> property.  But none of this worked... it seems that the values created
>  > >> inside the loop are not available to the HTTP request outside the loop.
>  > >>
>  > >> Any suggestions on how I might be able to do this.
>  > >>
>  > >> Marc
>  > >>
>  > >
>  >
>  > ---------------------------------------------------------------------
>  > 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


Re: How to pull multiple lines from a file and join them for use in a single HTTP request

Posted by Deepak Shetty <sh...@gmail.com>.
Hi
If I remember correctly Pre processors wont work unless you have atleast one
sampler . The way around this is
a. Use a Bean Shell Sampler instead (will show up in the results though)
b. Use a TestActionSampler (this is a dummy sampler which will allow you to
attach your Pre Processor)

regards
deepak

On Tue, Jan 12, 2010 at 10:52 AM, Marc Limotte <ms...@gmail.com> wrote:

> Hi Deepak.
>
> Thanks for correcting me.  After adding a Debug Sampler as you
> suggested, I see now that the loop only works if the Sampler exists.
> So, I've gotten my test plan to work... but only if the Debug Sampler
> is included and enabled.  Do you know why that is?  I don't want to
> leave Debug on, b/c of it's impact on the testing performance.
>
> I did verify that there are no errors in jmeter.log.  Here is the
> structure of my test:
>
> Thread Group
>    Random Variable
>    Loop Controller (loop count is the Random Variable)
>        Only Once
>            BeanShell Pre Proc (   vars.put("mylist","");   )
>            *DebugSampler
>        CSV Data Set Config
>        BeanShell Pre Proc  (   concats the last value from the CSV to
> "mylist"  )
>        *DebugSampler
>    HTTP Sampler ( uses the variable ${mylist}  )
>    View Results Tree
>
> Again, if I disable either of those DebugSamplers, it stops working.
>
> Marc
>
>
> On Tue, Jan 12, 2010 at 9:35 AM, Deepak Shetty <sh...@gmail.com> wrote:
> >> I tried using a variable and using a
> >>property.  But none of this worked... it seems that the values created
> >>inside the loop are not available to the HTTP request outside the loop.
> > Not true. If you set a variable it is available outside . use a debug
> > sampler with a view results tree listener to see what values get set and
> > check you are using the variable in the HTTP request .
> > If you still cant figure it out , please provide the structure of your
> test
> > (for e.g. you might have attached the pre processor to an incorrect
> > location  , e.g. if it is under a controller then it applies to all
> elements
> > in the controller) and finally check jmeter.log to verify that your
> > beanshell is actually executing without errors.
> >
> > regards
> > deepak
> >
> > On Tue, Jan 12, 2010 at 9:27 AM, Marc Limotte <ms...@gmail.com>
> wrote:
> >
> >> Hi,
> >>
> >> I'm looking for some suggestions on how to pull a random number of lines
> >> from a file and concatenate them together for a single HTTP request.  In
> a
> >> bit more detail:
> >>
> >> I have a CSV file (two columns, but I'm only interested in the first
> >> column) with almost 200,000 lines.  Each line contains a unique id.  I
> then
> >> want to pull a random number of ids (between 1 and 60), join them with a
> >> comma delimiter and make an HTTP request with the whole string.
> >>
> >> For example, the file might contain:
> >>
> >> http://rest.acme.com:8888/items/130,127,2,97
> >> or
> >> http://rest.acme.com:8888/items/127,26,31
> >>
> >> Where 130, 127, 2, etc; are ids pulled from the file.
> >>
> >> I can pre-sort the file randomly if I need to, so reading the lines in
> the
> >> file in sequence is not a problem.
> >>
> >> I tried a number of approaches using a CSV Data Set, or __CSVRead.  In
> >> general, my approach was to use a Loop controller with a random number
> as
> >> the "Loop Count"; and then use a BeanShell Pre-Processor or a
> >> UserParameters
> >> expression to concatenate the values.  I tried using a variable and
> using a
> >> property.  But none of this worked... it seems that the values created
> >> inside the loop are not available to the HTTP request outside the loop.
> >>
> >> Any suggestions on how I might be able to do this.
> >>
> >> Marc
> >>
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
>
>

Re: How to pull multiple lines from a file and join them for use in a single HTTP request

Posted by Marc Limotte <ms...@gmail.com>.
Hi Deepak.

Thanks for correcting me.  After adding a Debug Sampler as you
suggested, I see now that the loop only works if the Sampler exists.
So, I've gotten my test plan to work... but only if the Debug Sampler
is included and enabled.  Do you know why that is?  I don't want to
leave Debug on, b/c of it's impact on the testing performance.

I did verify that there are no errors in jmeter.log.  Here is the
structure of my test:

Thread Group
    Random Variable
    Loop Controller (loop count is the Random Variable)
        Only Once
            BeanShell Pre Proc (   vars.put("mylist","");   )
            *DebugSampler
        CSV Data Set Config
        BeanShell Pre Proc  (   concats the last value from the CSV to
"mylist"  )
        *DebugSampler
    HTTP Sampler ( uses the variable ${mylist}  )
    View Results Tree

Again, if I disable either of those DebugSamplers, it stops working.

Marc


On Tue, Jan 12, 2010 at 9:35 AM, Deepak Shetty <sh...@gmail.com> wrote:
>> I tried using a variable and using a
>>property.  But none of this worked... it seems that the values created
>>inside the loop are not available to the HTTP request outside the loop.
> Not true. If you set a variable it is available outside . use a debug
> sampler with a view results tree listener to see what values get set and
> check you are using the variable in the HTTP request .
> If you still cant figure it out , please provide the structure of your test
> (for e.g. you might have attached the pre processor to an incorrect
> location  , e.g. if it is under a controller then it applies to all elements
> in the controller) and finally check jmeter.log to verify that your
> beanshell is actually executing without errors.
>
> regards
> deepak
>
> On Tue, Jan 12, 2010 at 9:27 AM, Marc Limotte <ms...@gmail.com> wrote:
>
>> Hi,
>>
>> I'm looking for some suggestions on how to pull a random number of lines
>> from a file and concatenate them together for a single HTTP request.  In a
>> bit more detail:
>>
>> I have a CSV file (two columns, but I'm only interested in the first
>> column) with almost 200,000 lines.  Each line contains a unique id.  I then
>> want to pull a random number of ids (between 1 and 60), join them with a
>> comma delimiter and make an HTTP request with the whole string.
>>
>> For example, the file might contain:
>>
>> http://rest.acme.com:8888/items/130,127,2,97
>> or
>> http://rest.acme.com:8888/items/127,26,31
>>
>> Where 130, 127, 2, etc; are ids pulled from the file.
>>
>> I can pre-sort the file randomly if I need to, so reading the lines in the
>> file in sequence is not a problem.
>>
>> I tried a number of approaches using a CSV Data Set, or __CSVRead.  In
>> general, my approach was to use a Loop controller with a random number as
>> the "Loop Count"; and then use a BeanShell Pre-Processor or a
>> UserParameters
>> expression to concatenate the values.  I tried using a variable and using a
>> property.  But none of this worked... it seems that the values created
>> inside the loop are not available to the HTTP request outside the loop.
>>
>> Any suggestions on how I might be able to do this.
>>
>> Marc
>>
>

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


Re: How to pull multiple lines from a file and join them for use in a single HTTP request

Posted by Deepak Shetty <sh...@gmail.com>.
> I tried using a variable and using a
>property.  But none of this worked... it seems that the values created
>inside the loop are not available to the HTTP request outside the loop.
Not true. If you set a variable it is available outside . use a debug
sampler with a view results tree listener to see what values get set and
check you are using the variable in the HTTP request .
If you still cant figure it out , please provide the structure of your test
(for e.g. you might have attached the pre processor to an incorrect
location  , e.g. if it is under a controller then it applies to all elements
in the controller) and finally check jmeter.log to verify that your
beanshell is actually executing without errors.

regards
deepak

On Tue, Jan 12, 2010 at 9:27 AM, Marc Limotte <ms...@gmail.com> wrote:

> Hi,
>
> I'm looking for some suggestions on how to pull a random number of lines
> from a file and concatenate them together for a single HTTP request.  In a
> bit more detail:
>
> I have a CSV file (two columns, but I'm only interested in the first
> column) with almost 200,000 lines.  Each line contains a unique id.  I then
> want to pull a random number of ids (between 1 and 60), join them with a
> comma delimiter and make an HTTP request with the whole string.
>
> For example, the file might contain:
>
> http://rest.acme.com:8888/items/130,127,2,97
> or
> http://rest.acme.com:8888/items/127,26,31
>
> Where 130, 127, 2, etc; are ids pulled from the file.
>
> I can pre-sort the file randomly if I need to, so reading the lines in the
> file in sequence is not a problem.
>
> I tried a number of approaches using a CSV Data Set, or __CSVRead.  In
> general, my approach was to use a Loop controller with a random number as
> the "Loop Count"; and then use a BeanShell Pre-Processor or a
> UserParameters
> expression to concatenate the values.  I tried using a variable and using a
> property.  But none of this worked... it seems that the values created
> inside the loop are not available to the HTTP request outside the loop.
>
> Any suggestions on how I might be able to do this.
>
> Marc
>