A place for global init function?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

A place for global init function?

Seth Ladd
Hello,

I'm looking into using the BeanShell Sampler to write performance tests
for high level service facades.  Is there a place to init some code only
once, at the beginning of the test run?  For instance, I'd like to start
a Spring ApplicationContext before the test begins, so that all my
BeanShell Samplers have access to this ApplicationContext.

I could write a JavaClientSampler, and do my inits in the constructor or
static block, but that's a bit more work.  If I can use the BeanShell
Sampler, that would be great.

Any ideas?

Also, wondering if it will ever be possible to add multiple classpath
references to JMeter.  I'd like to test code outside of JMeter, without
having to copy over all the jars and supporting code into JMeter's lib
directory.  From the docs, it says the CLASSPATH var is ignored.

Thanks!
Seth

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: A place for global init function?

sebb-2-2
On 6/2/05, Seth Ladd <[hidden email]> wrote:
> Hello,
>
> I'm looking into using the BeanShell Sampler to write performance tests
> for high level service facades.  Is there a place to init some code only
> once, at the beginning of the test run?  For instance, I'd like to start
> a Spring ApplicationContext before the test begins, so that all my
> BeanShell Samplers have access to this ApplicationContext.

From the manual:

"If the property "beanshell.sampler.init" is defined, it is passed to
the Interpreter as the name of a sourced file. This can be used to
define common methods and variables. There is a sample init file in
the bin directory: BeanShellFunction.bshrc."

This file is processed when the sampler is created, so will be invoked
at most once per thread per test. I'm not sure if variables are shared
between all threads, but it should be easy enough to find out.

S.

> I could write a JavaClientSampler, and do my inits in the constructor or
> static block, but that's a bit more work.  If I can use the BeanShell
> Sampler, that would be great.
>
> Any ideas?
>
> Also, wondering if it will ever be possible to add multiple classpath
> references to JMeter.  I'd like to test code outside of JMeter, without
> having to copy over all the jars and supporting code into JMeter's lib
> directory.  From the docs, it says the CLASSPATH var is ignored.
>
> Thanks!
> Seth
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: A place for global init function?

sebb-2-2
In reply to this post by Seth Ladd
On 6/2/05, Seth Ladd <[hidden email]> wrote:
> Hello,
 
[...]

> Also, wondering if it will ever be possible to add multiple classpath
> references to JMeter.  I'd like to test code outside of JMeter, without
> having to copy over all the jars and supporting code into JMeter's lib
> directory.  From the docs, it says the CLASSPATH var is ignored.
>

That's a feature of Java, not JMeter.

There may be something about this in the FAQ.

S.

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: A place for global init function?

Seth Ladd

>>Also, wondering if it will ever be possible to add multiple classpath
>>references to JMeter.  I'd like to test code outside of JMeter, without
>>having to copy over all the jars and supporting code into JMeter's lib
>>directory.  From the docs, it says the CLASSPATH var is ignored.
>>
>
>
> That's a feature of Java, not JMeter.
>
> There may be something about this in the FAQ.

I was thinking something along the lines of Eclipse, or even Ant.  Both
allow you to add in extra paths to be included in the classpath during
runtime.  That type of functionality would be really helpful for JMeter,
as it would easily allow for testing Java code.

Of course, we can do a build and move all supporting jars over.  But
someday it would be nice to have the ability, through the GUI, to add in
paths and jars.

Thanks,
Seth

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: A place for global init function?

Seth Ladd
In reply to this post by sebb-2-2
sebb wrote:

> On 6/2/05, Seth Ladd <[hidden email]> wrote:
>
>>Hello,
>>
>>I'm looking into using the BeanShell Sampler to write performance tests
>>for high level service facades.  Is there a place to init some code only
>>once, at the beginning of the test run?  For instance, I'd like to start
>>a Spring ApplicationContext before the test begins, so that all my
>>BeanShell Samplers have access to this ApplicationContext.
>
>
> From the manual:
>
> "If the property "beanshell.sampler.init" is defined, it is passed to
> the Interpreter as the name of a sourced file. This can be used to
> define common methods and variables. There is a sample init file in
> the bin directory: BeanShellFunction.bshrc."
>
> This file is processed when the sampler is created, so will be invoked
> at most once per thread per test. I'm not sure if variables are shared
> between all threads, but it should be easy enough to find out.

Ah, thanks.  I wasn't sure if the file was processed, or just available
to share common functions.  I guess since it's interpretted, it would
have to be processed.

Perfect!

Thanks very much,
Seth

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: A place for global init function?

sebb-2-2
On 6/2/05, Seth Ladd <[hidden email]> wrote:

> sebb wrote:
> > On 6/2/05, Seth Ladd <[hidden email]> wrote:
> >
> > This file is processed when the sampler is created, so will be invoked
> > at most once per thread per test. I'm not sure if variables are shared
> > between all threads, but it should be easy enough to find out.
>
> Ah, thanks.  I wasn't sure if the file was processed, or just available
> to share common functions.  I guess since it's interpretted, it would
> have to be processed.
>
> Perfect!
>
> Thanks very much,

No problem - glad that the BSH Sampler is proving useful.

I added in case we needed it, but all we've ended up using is the
BeanShell server ...
[We use that to make changes to a property that is then used to
control throughput.]

S.

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: A place for global init function?

Seth Ladd

> No problem - glad that the BSH Sampler is proving useful.
>
> I added in case we needed it, but all we've ended up using is the
> BeanShell server ...
> [We use that to make changes to a property that is then used to
> control throughput.]

It's very useful.  For instance, I am using it to test remote spring
services using spring's httpinvoker.  Using the bean shell is much
easier than writing a custom java class.

I'd love to figure out how to get one object instance available to all
threads.  That would be nice, but right now one object instance per
thread is fine.

Thanks again,
Seth

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: A place for global init function?

sebb-2-2
On 6/3/05, Seth Ladd <[hidden email]> wrote:

>
> > No problem - glad that the BSH Sampler is proving useful.
> >
> > I added in case we needed it, but all we've ended up using is the
> > BeanShell server ...
> > [We use that to make changes to a property that is then used to
> > control throughput.]
>
> It's very useful.  For instance, I am using it to test remote spring
> services using spring's httpinvoker.  Using the bean shell is much
> easier than writing a custom java class.
>
> I'd love to figure out how to get one object instance available to all
> threads.  That would be nice, but right now one object instance per
> thread is fine.

I've just re-checked, and the BSH Sampler creates new version of the
interpreter for each Sampler in each thread.

So any variables in the script are local to the sampler (but will
persist across loops).

However, one can use vars.get("VAR") and vars.put("VAR",value); to
get/set thread variables.

JMeter does not currently have any global variables, as far as I can see.

But I've just found that there is a shared namespace within BeanShell
- see "Special Variables and Values", which is on page 34 of the BSH
Manual version 1.3.

This can be used as follows within the bshrc script:

synchronized(bsh.shared){
  if (bsh.shared.myobj == void) {
     print("myobj = void");
     bsh.shared.myobj=123; // Or something a bit more useful
  } else {
     print("myobj = " + bsh.shared.myobj);
  }
}

[I'm not entirely sure whether synchronized() works or is a no-op, so
you might need to adjust the ramp-up time]

Note that the bsh.shared namespace is not reset at the end of a test
run, so this may not be suitable for repeated test runs.

S.

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]