You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@jmeter.apache.org by Adam Bradley <ad...@yahoo.com> on 2006/06/21 07:03:59 UTC

Variables - reassigning values to existing variables

Hi,

I've currently trying to reassign a value to a variable and was 
wondering if this is possible/recommended ?

My skeletal test case and an image are attached.

Thanks in advance!
Adam

Re: Variables - reassigning values to existing variables

Posted by Adam Bradley <ad...@yahoo.com>.
> ---sample BeanShell code ---
> if (debug == "True")
>         log.info("Processing " + vars.get("MessageType") + " message")
> ---sample BeanShell code ---
> 
> The methods you'll most likely use are
> 
> vars.get
> vers.put
> and vars.remove
> 
> See http://jakarta.apache.org/jmeter/api/ for more information.

As with any Java code you'll still need to import classes if you
want to use methods they provide

---snip---
import org.apache.jmeter.threads.JMeterVariables;
import org.apache.jmeter.samplers.SampleResult;
import org.apache.jorphan.logging.LoggingManager;
import org.apache.log.Logger;
import org.apache.jmeter.protocol.ldap.sampler;

log.info("SampleResult Class " + SampleResult.Class);
log.info(SampleResult.getResponseDataAsString());

log.info("ResponseMessage Class " + ResponseMessage.Class);
log.info("ResponseMessage " + ResponseMessage);

log.info("SearchResult Class " + SearchResult.Class);
//log.info(SampleResult.getResponseDataAsString());

vars.put("testVar","surprise!");

Iterator i = vars.getIterator();
while(i.hasNext()) {
   Map.Entry me = i.next();
   if(String.class.equals(me.getValue().getClass()))
     log.info(me.toString());
}
---snip---

See if this works for you
Adam


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


Re: BeanShell setup

Posted by sebb <se...@gmail.com>.
Have you downloaded the BeanShell jar and put it in the JMeter lib directory?

S
On 27/06/06, Vitalie Valache <Vi...@bnm.org> wrote:
> Hi !
> I keep getting this error on my jmeter.log when I try to run a test  plan with BeanShell PreProcessor object.
> ->ERROR - jmeter.modifiers.BeanShellPreProcessor: bsh.Interpreter
>
> Think its caused by BeanShell setup.
> How should I configure BeanShell?
> --
> DISCLAIMER:
> Any e-mail messages from the National Bank of Moldova are sent in good faith, but shall not be binding nor construed as constituting any obligation on the part of the Bank.
> The information transmitted is intended only for the person or entity to which it is addressed and may contain confidential and/or privileged material. If you received this in error, please contact the sender and delete the material from any computer.
>
> ---------------------------------------------------------------------
> 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


BeanShell setup

Posted by Vitalie Valache <Vi...@bnm.org>.
Hi !
I keep getting this error on my jmeter.log when I try to run a test  plan with BeanShell PreProcessor object.
->ERROR - jmeter.modifiers.BeanShellPreProcessor: bsh.Interpreter

Think its caused by BeanShell setup.
How should I configure BeanShell?
-- 
DISCLAIMER:
Any e-mail messages from the National Bank of Moldova are sent in good faith, but shall not be binding nor construed as constituting any obligation on the part of the Bank.
The information transmitted is intended only for the person or entity to which it is addressed and may contain confidential and/or privileged material. If you received this in error, please contact the sender and delete the material from any computer.

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


Re: Variables - reassigning values to existing variables

Posted by Adam Bradley <ad...@yahoo.com>.
> 
> How can I do that, what should I use (I heard about beanshell, wouldn't it be too much this  simple operation )?!
> 

I couldn't find any way other than using BeanShell.


---sample BeanShell code ---
if (debug == "True")
         log.info("Processing " + vars.get("MessageType") + " message")
---sample BeanShell code ---

The methods you'll most likely use are

vars.get
vers.put
and vars.remove

See http://jakarta.apache.org/jmeter/api/ for more information.

On a side note, I'm still having issue getting this code to work
---snip---
Iterator i = vars.getIterator();
while(i.hasNext())
{
     Map.Entry me = i.next();
     if(String.class.equals(me.getValue().getClass())) {
        print(me);
}
---snip---

Keep getting this error

---snip---
Caused by: Sourced file: inline evaluation of: ``import bsh.util.*; 
debug = "True"; majorDebug = "True";  if (debug == "True")   . . . '' : 
Typed variable declaration : Error in method invocation: No args method 
getIterator() not found in 
class'org.apache.jmeter.threads.JMeterVariables' : at Line: 9 : in file: 
inline evaluation of: ``import bsh.util.*;  debug = "True"; majorDebug = 
"True";  if (debug == "True")   . . . '' : vars .getIterator ( )
---snip---

*sniff*
Adam


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


Re: Variables - reassigning values to existing variables

Posted by Vitalie Valache <Vi...@bnm.org>.
Hi, 
maybe its  a dummy question but I still don't get it. 
How to reassign a new value to a previously defined user parameter(variables)??

I have:

Thread Group-
                       |-User Parameters  ----------(here I define a variable VAR1 with default "zero" value)
                       |-If Controller         ----------(${__javaScript("${VAR1}"=="zero")}

                                |- <<< DO  VARIABLE REASSIGNING , ${VAR1} ="one">>>

                       |-If Controller         ----------(${__javaScript("${VAR1}"=="one")}
                                |- <<< VARIABLE REASSIGNED>>>


How can I do that, what should I use (I heard about beanshell, wouldn't it be too much this  simple operation )?!

Thanks!
               

                                      
-- 
DISCLAIMER:
Any e-mail messages from the National Bank of Moldova are sent in good faith, but shall not be binding nor construed as constituting any obligation on the part of the Bank.
The information transmitted is intended only for the person or entity to which it is addressed and may contain confidential and/or privileged material. If you received this in error, please contact the sender and delete the material from any computer.

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


Re: Variables - reassigning values to existing variables

Posted by Adam Bradley <ad...@yahoo.com>.
sebb wrote:
> You might be better off using the Switch Controller rather than
> multiple If Controllers - however it's difficult to advise without
> knowing what you are trying to do.

Thanks for the tip - I'll give that a go.
Adam


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


RE: How to convert JMeter User Defined Variable between strings and integers?

Posted by "Layton, Andrew" <an...@atosorigin.com>.
Thanks for this:  the function does indeed add an integer to a variable
despite the latter appearing to be a string otherwise. 

I embedded this in a Sampler:

${__intSum(${var_1},4,var_1)} //  adds 4 to var_1 as expected. 

Regards
Andrew Layton


-----Original Message-----
From: sebb [mailto:sebbaz@gmail.com] 
Sent: 22 June 2006 10:43
To: JMeter Users List
Subject: Re: How to convert JMeter User Defined Variable between strings
and integers?

Note that there is a JMeter function for adding numbers:

http://jakarta.apache.org/jmeter/usermanual/functions.html#__intSum

Also, there are various Counters you can use.

Maybe you don't need BeanShell.

S.
On 22/06/06, Layton, Andrew <an...@atosorigin.com> wrote:
> I have reached the stage of including a Beanshell sampler and
successfully accessing UDV variables.
> Beanshell can put integers and / or strings into response message for
a regex extractor to take them out again - I am able to get the time in
millisec as a string.
> The Question: how to get a string number from a User Variable and
convert to integer, say just to increment numerically?
> I guess that this could be done using a local int variable or Integer
object, but how?
> My upbringing is C and I cannot claim Java knowledge; however most of
my Beanshell code works as expected and required, i.e I can do string
_or_ integer operations on local variables OK, and vars.get( ) and
vars.put ( ) work too.
> According to Java docs I have read, a variable of class Integer should

> be creatable with a string as its argument - but this won't work -
causes an error.
> Attempting valueOf ( ) or parseInt ( ) from Java  doc also cause an
error.
> Trying the methods allegedly allowed by Java on a class String cause
errors in Beanshell Sampler execution
> (error   messages are coarse-grained and  unhelpful:
>  HTTP response code 500 and response message:
"org.apache.jorphan.util.JMeterException: Error invoking bsh method
eval"
> //
> I found info on StringBuffer in a Java book - this looks tantalising 
> again but I still can't see how to use it without error or a void
value I have included more notes and comments below.
> Help please !
> // sprintf ( "what %d", a ) ; // this causes an error with valid int a

> ; fair enough it's C code // print (a ) ; // no error but dunno where 
> the result goes to // // //  Integer rc ("234" ) ; // as shown in 
> Javadoc: causes an error // Integer rc = "999" ; // Fails - 
> unsurprising //  rc = parseInt ("324" ) ;  // error
> Integer rc ; // // Works OK !  rc is an Integer which is happy with an
int.   - see later
> String argh = "234" ;  // this line works OK //  rc = valueOf ( argh 
> ); // error // rc = argh.valueOf ( ) ;  // error  rc = 999 ; // can 
> assign value to an Integer String foo = "Foo" ; // OK foo = foo + 
> rc.toString ( ) ; // CAN convert Integer to string - foo gets 
> concatenation as expected //CAN access variables as strings and copy 
> to local String variable - this one is "88" as set earlier in script 
> String bar = vars.get("Siebel_Count") ; // rc = bar ;  // can't just 
> assign integer to string // // rc = bar.toInteger ( ) ;// Fails
> // rc = Integer (bar ) ;   // Fails
> //  StringBuffer SB ; // no error but what use is this?
> StringBuffer SB ( bar ) ; //  no error but SB is void when 
> concatenated into ResponseMessage as below //  SB =  "bar"  ;  // 
> error // Some working code - integer arithmetic int  result ; int a = 
> 4 ;
>    result = (a+3) * 6 ; // CAN do arithmetic on these int variables
>    rc = rc + result ; // OK to add int to Integer //  //  foo = 
> toString (result ) ; // Error ResponseMessage = "output =  "  + foo  +

> " " + result  + " " + (rc+3) + "SB = " + SB ;  // OK with integers or
strings: concatenates not adds!
>
>
>
> _______________________________________________________
>
> This e-mail and the documents attached are confidential and intended 
> solely for the addressee; it may also be privileged. If you receive 
> this e-mail in error, please notify the sender immediately and destroy
it.
> As its integrity cannot be secured on the Internet, the Atos Origin 
> group liability cannot be triggered for the message content. Although 
> the sender endeavours to maintain a computer virus-free network, the 
> sender does not warrant that this transmission is virus-free and will 
> not be liable for any damages resulting from any virus transmitted.
> _______________________________________________________
>
>
>
> ---------------------------------------------------------------------
> 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


Re: How to convert JMeter User Defined Variable between strings and integers?

Posted by sebb <se...@gmail.com>.
Note that there is a JMeter function for adding numbers:

http://jakarta.apache.org/jmeter/usermanual/functions.html#__intSum

Also, there are various Counters you can use.

Maybe you don't need BeanShell.

S.
On 22/06/06, Layton, Andrew <an...@atosorigin.com> wrote:
> I have reached the stage of including a Beanshell sampler and successfully accessing UDV variables.
> Beanshell can put integers and / or strings into response message for a regex extractor to take them out again - I am able to get the time in millisec as a string.
> The Question: how to get a string number from a User Variable and convert to integer, say just to increment numerically?
> I guess that this could be done using a local int variable or Integer object, but how?
> My upbringing is C and I cannot claim Java knowledge; however most of my Beanshell code works as expected and required, i.e I can do string _or_ integer operations on local variables OK, and vars.get( ) and vars.put ( ) work too.
> According to Java docs I have read, a variable of class Integer should be creatable with a string as its argument -
> but this won't work - causes an error.
> Attempting valueOf ( ) or parseInt ( ) from Java  doc also cause an error.
> Trying the methods allegedly allowed by Java on a class String cause errors in Beanshell Sampler execution
> (error   messages are coarse-grained and  unhelpful:
>  HTTP response code 500 and response message: "org.apache.jorphan.util.JMeterException: Error invoking bsh method eval"
> //
> I found info on StringBuffer in a Java book - this looks tantalising again but I still can't see how to use it without error or a void value
> I have included more notes and comments below.
> Help please !
> // sprintf ( "what %d", a ) ; // this causes an error with valid int a ; fair enough it's C code
> // print (a ) ; // no error but dunno where the result goes to
> //
> //
> //  Integer rc ("234" ) ; // as shown in Javadoc: causes an error
> // Integer rc = "999" ; // Fails - unsurprising
> //  rc = parseInt ("324" ) ;  // error
> Integer rc ; // // Works OK !  rc is an Integer which is happy with an int.   - see later
> String argh = "234" ;  // this line works OK
> //  rc = valueOf ( argh ); // error
> // rc = argh.valueOf ( ) ;  // error
>  rc = 999 ; // can assign value to an Integer
> String foo = "Foo" ; // OK
> foo = foo + rc.toString ( ) ; // CAN convert Integer to string - foo gets concatenation as expected
> //CAN access variables as strings and copy to local String variable - this one is "88" as set earlier in script
> String bar = vars.get("Siebel_Count") ;
> // rc = bar ;  // can't just assign integer to string //
> // rc = bar.toInteger ( ) ;// Fails
> // rc = Integer (bar ) ;   // Fails
> //  StringBuffer SB ; // no error but what use is this?
> StringBuffer SB ( bar ) ; //  no error but SB is void when concatenated into ResponseMessage as below
> //  SB =  "bar"  ;  // error
> // Some working code - integer arithmetic
> int  result ;
> int a = 4 ;
>    result = (a+3) * 6 ; // CAN do arithmetic on these int variables
>    rc = rc + result ; // OK to add int to Integer //
>  //  foo = toString (result ) ; // Error
> ResponseMessage = "output =  "  + foo  + " " + result  + " " + (rc+3) + "SB = " + SB ;  // OK with integers or strings: concatenates not adds!
>
>
>
> _______________________________________________________
>
> This e-mail and the documents attached are confidential and intended
> solely for the addressee; it may also be privileged. If you receive this
> e-mail in error, please notify the sender immediately and destroy it.
> As its integrity cannot be secured on the Internet, the Atos Origin group
> liability cannot be triggered for the message content. Although the
> sender endeavours to maintain a computer virus-free network, the
> sender does not warrant that this transmission is virus-free and will
> not be liable for any damages resulting from any virus transmitted.
> _______________________________________________________
>
>
>
> ---------------------------------------------------------------------
> 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


How to convert JMeter User Defined Variable between strings and integers?

Posted by "Layton, Andrew" <an...@atosorigin.com>.
I have reached the stage of including a Beanshell sampler and successfully accessing UDV variables.
Beanshell can put integers and / or strings into response message for a regex extractor to take them out again - I am able to get the time in millisec as a string.
The Question: how to get a string number from a User Variable and convert to integer, say just to increment numerically?
I guess that this could be done using a local int variable or Integer object, but how? 
My upbringing is C and I cannot claim Java knowledge; however most of my Beanshell code works as expected and required, i.e I can do string _or_ integer operations on local variables OK, and vars.get( ) and vars.put ( ) work too.
According to Java docs I have read, a variable of class Integer should be creatable with a string as its argument -
but this won't work - causes an error.
Attempting valueOf ( ) or parseInt ( ) from Java  doc also cause an error.
Trying the methods allegedly allowed by Java on a class String cause errors in Beanshell Sampler execution 
(error   messages are coarse-grained and  unhelpful: 
 HTTP response code 500 and response message: "org.apache.jorphan.util.JMeterException: Error invoking bsh method eval"
//
I found info on StringBuffer in a Java book - this looks tantalising again but I still can't see how to use it without error or a void value
I have included more notes and comments below.
Help please ! 
// sprintf ( "what %d", a ) ; // this causes an error with valid int a ; fair enough it's C code
// print (a ) ; // no error but dunno where the result goes to 
//
// 
//  Integer rc ("234" ) ; // as shown in Javadoc: causes an error
// Integer rc = "999" ; // Fails - unsurprising
//  rc = parseInt ("324" ) ;  // error
Integer rc ; // // Works OK !  rc is an Integer which is happy with an int.   - see later
String argh = "234" ;  // this line works OK 
//  rc = valueOf ( argh ); // error
// rc = argh.valueOf ( ) ;  // error
 rc = 999 ; // can assign value to an Integer
String foo = "Foo" ; // OK
foo = foo + rc.toString ( ) ; // CAN convert Integer to string - foo gets concatenation as expected
//CAN access variables as strings and copy to local String variable - this one is "88" as set earlier in script
String bar = vars.get("Siebel_Count") ; 
// rc = bar ;  // can't just assign integer to string // 
// rc = bar.toInteger ( ) ;// Fails
// rc = Integer (bar ) ;   // Fails
//  StringBuffer SB ; // no error but what use is this? 
StringBuffer SB ( bar ) ; //  no error but SB is void when concatenated into ResponseMessage as below
//  SB =  "bar"  ;  // error
// Some working code - integer arithmetic
int  result ;
int a = 4 ;
    result = (a+3) * 6 ; // CAN do arithmetic on these int variables
    rc = rc + result ; // OK to add int to Integer //
 //  foo = toString (result ) ; // Error
ResponseMessage = "output =  "  + foo  + " " + result  + " " + (rc+3) + "SB = " + SB ;  // OK with integers or strings: concatenates not adds!



_______________________________________________________

This e-mail and the documents attached are confidential and intended
solely for the addressee; it may also be privileged. If you receive this
e-mail in error, please notify the sender immediately and destroy it.
As its integrity cannot be secured on the Internet, the Atos Origin group
liability cannot be triggered for the message content. Although the
sender endeavours to maintain a computer virus-free network, the
sender does not warrant that this transmission is virus-free and will
not be liable for any damages resulting from any virus transmitted. 
_______________________________________________________


Re: Variables - reassigning values to existing variables

Posted by sebb <se...@gmail.com>.
On 21/06/06, Adam Bradley <ad...@yahoo.com> wrote:
> Hi,
>
> I've currently trying to reassign a value to a variable and was
> wondering if this is possible/recommended ?

Configuration items are not procedural; they apply to all samplers in
their scope.

If there are two UDVs for the same variable, only one will take effect.

Please read:

http://jakarta.apache.org/jmeter/usermanual/build-test-plan.html#Scoping_rules
and
http://jakarta.apache.org/jmeter/usermanual/test_plan.html

> My skeletal test case and an image are attached.

You might be better off using the Switch Controller rather than
multiple If Controllers - however it's difficult to advise without
knowing what you are trying to do.

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


Re: Variables - reassigning values to existing variables

Posted by Adam Bradley <ad...@yahoo.com>.
Adam Bradley wrote:
> Eddie O'Sullivan wrote:
>> If you use a beanshell sampler to update the variable and use a regular
>> expression extractor to extract the updated variable that will work for
>> you.
> 
> Eddie,
> 
> Thanks for that - got that working, but now I have to fight
> 
> ---snip---
>     at java.lang.Thread.run(Unknown Source)
> Caused by: Sourced file: inline evaluation of: ``debug = "True";  if 
> (debug == "True")      log.info("MessageType " + vars.get("M . . . '' : 
> Typed variable declaration : Error in method invocation: No args method 
> getIterator() not found in 
> class'org.apache.jmeter.threads.JMeterVariables' : at Line: 6 : in file: 
> inline evaluation of: ``debug = "True";  if (debug == "True") 
> log.info("MessageType " + vars.get("M . . . '' : vars .getIterator ( )
> 
> ---snip---
> 
> But I know its there!  I've seen the API... :)
> 
> http://jakarta.apache.org/jmeter/api/org/apache/jmeter/threads/JMeterVariables.html 
> 
> 
> Adam

In the immortal works of Napolean Dynamite "freakin' idiot!"  Guess who
forgot to import...

---snip---
import org.apache.jmeter.samplers.SampleResult;
import org.apache.jmeter.threads.JMeterVariables;

SampleResult sr = new SampleResult();

log.info("sr == " + sr.toString());
log.info("sr == " + sr.Class);

vars.put("testVar","surprise!");

Iterator i = vars.getIterator();
while(i.hasNext()) {
   Map.Entry me = i.next();
   if(String.class.equals(me.getValue().getClass()))
     log.info(me.toString());
}
---snip---

Adam






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


Re: Variables - reassigning values to existing variables

Posted by Adam Bradley <ad...@yahoo.com>.
Adam Bradley wrote:
> Eddie O'Sullivan wrote:
>> If you use a beanshell sampler to update the variable and use a regular
>> expression extractor to extract the updated variable that will work for
>> you.
> 
> Eddie,
> 
> Thanks for that - got that working, but now I have to fight
> 
> ---snip---
>     at java.lang.Thread.run(Unknown Source)
> Caused by: Sourced file: inline evaluation of: ``debug = "True";  if 
> (debug == "True")      log.info("MessageType " + vars.get("M . . . '' : 
> Typed variable declaration : Error in method invocation: No args method 
> getIterator() not found in 
> class'org.apache.jmeter.threads.JMeterVariables' : at Line: 6 : in file: 
> inline evaluation of: ``debug = "True";  if (debug == "True") 
> log.info("MessageType " + vars.get("M . . . '' : vars .getIterator ( )
> 
> ---snip---
> 
> But I know its there!  I've seen the API... :)
> 
> http://jakarta.apache.org/jmeter/api/org/apache/jmeter/threads/JMeterVariables.html 
> 
> 
> Adam

In the immortal works of Napolean Dynamite "freakin' idiot!"  Guess who
forgot to import...

---snip---
import org.apache.jmeter.samplers.SampleResult;
import org.apache.jmeter.threads.JMeterVariables;

SampleResult sr = new SampleResult();

log.info("sr == " + sr.toString());
log.info("sr == " + sr.Class);

vars.put("testVar","surprise!");

Iterator i = vars.getIterator();
while(i.hasNext()) {
   Map.Entry me = i.next();
   if(String.class.equals(me.getValue().getClass()))
     log.info(me.toString());
}
---snip---

Adam






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


Re: Variables - reassigning values to existing variables

Posted by Adam Bradley <ad...@yahoo.com>.
Adam Bradley wrote:
> Eddie O'Sullivan wrote:
>> If you use a beanshell sampler to update the variable and use a regular
>> expression extractor to extract the updated variable that will work for
>> you.
> 
> Eddie,
> 
> Thanks for that - got that working, but now I have to fight
> 
> ---snip---
>     at java.lang.Thread.run(Unknown Source)
> Caused by: Sourced file: inline evaluation of: ``debug = "True";  if 
> (debug == "True")      log.info("MessageType " + vars.get("M . . . '' : 
> Typed variable declaration : Error in method invocation: No args method 
> getIterator() not found in 
> class'org.apache.jmeter.threads.JMeterVariables' : at Line: 6 : in file: 
> inline evaluation of: ``debug = "True";  if (debug == "True") 
> log.info("MessageType " + vars.get("M . . . '' : vars .getIterator ( )
> 
> ---snip---
> 
> But I know its there!  I've seen the API... :)
> 
> http://jakarta.apache.org/jmeter/api/org/apache/jmeter/threads/JMeterVariables.html 
> 
> 
> Adam

In the immortal works of Napolean Dynamite "freakin' idiot!"  Guess who 
forgot to import...

---snip---
import org.apache.jmeter.samplers.SampleResult;
import org.apache.jmeter.threads.JMeterVariables;

SampleResult sr = new SampleResult();

log.info("sr == " + sr.toString());
log.info("sr == " + sr.Class);

vars.put("testVar","surprise!");

Iterator i = vars.getIterator();
while(i.hasNext()) {
   Map.Entry me = i.next();
   if(String.class.equals(me.getValue().getClass()))
     log.info(me.toString());
}
---snip---

Adam





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


Re: Variables - reassigning values to existing variables

Posted by Adam Bradley <ad...@yahoo.com>.
Eddie O'Sullivan wrote:
> If you use a beanshell sampler to update the variable and use a regular
> expression extractor to extract the updated variable that will work for
> you.

Eddie,

Thanks for that - got that working, but now I have to fight

---snip---
	at java.lang.Thread.run(Unknown Source)
Caused by: Sourced file: inline evaluation of: ``debug = "True";  if 
(debug == "True")      log.info("MessageType " + vars.get("M . . . '' : 
Typed variable declaration : Error in method invocation: No args method 
getIterator() not found in 
class'org.apache.jmeter.threads.JMeterVariables' : at Line: 6 : in file: 
inline evaluation of: ``debug = "True";  if (debug == "True") 
log.info("MessageType " + vars.get("M . . . '' : vars .getIterator ( )

---snip---

But I know its there!  I've seen the API... :)

http://jakarta.apache.org/jmeter/api/org/apache/jmeter/threads/JMeterVariables.html

Adam


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


Re: Variables - reassigning values to existing variables

Posted by Eddie O'Sullivan <eo...@qad.com>.



If you use a beanshell sampler to update the variable and use a regular
expression extractor to extract the updated variable that will work for
you.
                                                                                       
                                                                                       
                                                                                       
 Eddie O'Sullivan                                                      (Embedded image 
 Application Performance                                                moved to file: 
 Group                                                                   pic01131.gif) 
                                                                                       
 QAD Ireland Ltd.                             eos@qad.com                              
 Hamilton House                               Tel:  +353 61 213616                     
 National Technological Park                                                           
 Limerick, Ireland                                                                     
 http://www.qad.com/                                                                   
                                                                                       
                                                                                       
 A Passion for Manufacturing                                                           
                                                                                       
                                                                                       
 This e-mail may contain QAD                                                           
 proprietary information and                                                           
    should be treated as                                                               
        confidential.                                                                  
                                                                                       





                                                                           
             Adam Bradley                                                  
             <adam_j_bradley@y                                             
             ahoo.com>                                                  To 
             Sent by: news             jmeter-user@jakarta.apache.org      
             <news@sea.gmane.o                                          cc 
             rg>                                                           
                                                                   Subject 
                                       Variables - reassigning values to   
             21/06/2006 06:03          existing variables                  
                                                                           
                                                                           
             Please respond to                                             
               "JMeter Users                                               
                   List"                                                   
             <jmeter-user@jaka                                             
              rta.apache.org>                                              
                                                                           
                                                                           




Hi,

I've currently trying to reassign a value to a variable and was
wondering if this is possible/recommended ?

My skeletal test case and an image are attached.

Thanks in advance!
Adam
<jmeterTestPlan version="1.1" properties="1.7">
  <hashTree>
    <TestPlan>
      <elementProp name="TestPlan.user_defined_variables"
elementType="org.apache.jmeter.config.Arguments">
        <stringProp
name="TestElement.gui_class">org.apache.jmeter.config.gui.ArgumentsPanel</stringProp>

        <stringProp
name="TestElement.test_class">org.apache.jmeter.config.Arguments</stringProp>

        <collectionProp name="Arguments.arguments"/>
        <stringProp name="TestElement.name">User Defined
Variables</stringProp>
        <boolProp name="TestElement.enabled">true</boolProp>
      </elementProp>
      <stringProp
name="TestElement.gui_class">org.apache.jmeter.control.gui.TestPlanGui</stringProp>

      <stringProp name="TestPlan.user_define_classpath"></stringProp>
      <boolProp name="TestPlan.serialize_threadgroups">false</boolProp>
      <stringProp
name="TestElement.test_class">org.apache.jmeter.testelement.TestPlan</stringProp>

      <stringProp name="TestElement.name">Sample test</stringProp>
      <boolProp name="TestPlan.functional_mode">false</boolProp>
      <boolProp name="TestElement.enabled">true</boolProp>
      <stringProp name="TestPlan.comments"></stringProp>
    </TestPlan>
    <hashTree>
      <org.apache.jmeter.config.Arguments>
        <stringProp
name="TestElement.gui_class">org.apache.jmeter.config.gui.ArgumentsPanel</stringProp>

        <stringProp
name="TestElement.test_class">org.apache.jmeter.config.Arguments</stringProp>

        <collectionProp name="Arguments.arguments">
          <elementProp name="testType"
elementType="org.apache.jmeter.config.Argument">
            <stringProp name="Argument.metadata">=</stringProp>
            <stringProp name="Argument.value">Case2</stringProp>
            <stringProp name="Argument.name">testType</stringProp>
          </elementProp>
        </collectionProp>
        <stringProp name="TestElement.name">testType set to
Case2</stringProp>
        <boolProp name="TestElement.enabled">true</boolProp>
      </org.apache.jmeter.config.Arguments>
      <hashTree/>
      <ThreadGroup>
        <longProp name="ThreadGroup.start_time">1150863714000</longProp>
        <stringProp
name="TestElement.test_class">org.apache.jmeter.threads.ThreadGroup</stringProp>

        <stringProp name="ThreadGroup.delay"></stringProp>
        <stringProp name="ThreadGroup.duration"></stringProp>
        <boolProp name="TestElement.enabled">true</boolProp>
        <stringProp name="ThreadGroup.num_threads">1</stringProp>
        <boolProp name="ThreadGroup.scheduler">false</boolProp>
        <stringProp
name="TestElement.gui_class">org.apache.jmeter.threads.gui.ThreadGroupGui</stringProp>

        <elementProp name="ThreadGroup.main_controller"
elementType="org.apache.jmeter.control.LoopController">
          <stringProp
name="TestElement.gui_class">org.apache.jmeter.control.gui.LoopControlPanel</stringProp>

          <stringProp name="LoopController.loops">1</stringProp>
          <stringProp
name="TestElement.test_class">org.apache.jmeter.control.LoopController</stringProp>

          <stringProp name="TestElement.name">Loop Controller</stringProp>
          <boolProp name="TestElement.enabled">true</boolProp>
          <boolProp name="LoopController.continue_forever">false</boolProp>
        </elementProp>
        <stringProp name="TestElement.name">Thread Group</stringProp>
        <longProp name="ThreadGroup.end_time">1150863714000</longProp>
        <stringProp
name="ThreadGroup.on_sample_error">continue</stringProp>
        <stringProp name="ThreadGroup.ramp_time">1</stringProp>
      </ThreadGroup>
      <hashTree>
        <IfController>
          <stringProp
name="IfController.condition">&apos;${testType}&apos;==&apos;Case1&apos;</stringProp>

          <stringProp
name="TestElement.gui_class">org.apache.jmeter.control.gui.IfControllerPanel</stringProp>

          <stringProp
name="TestElement.test_class">org.apache.jmeter.control.IfController</stringProp>

          <stringProp name="TestElement.name">Case1</stringProp>
          <boolProp name="TestElement.enabled">true</boolProp>
        </IfController>
        <hashTree>
          <OnceOnlyController>
            <stringProp
name="TestElement.gui_class">org.apache.jmeter.control.gui.OnceOnlyControllerGui</stringProp>

            <stringProp
name="TestElement.test_class">org.apache.jmeter.control.OnceOnlyController</stringProp>

            <stringProp name="TestElement.name">Finish</stringProp>
            <boolProp name="TestElement.enabled">true</boolProp>
          </OnceOnlyController>
          <hashTree/>
        </hashTree>
        <IfController>
          <stringProp
name="IfController.condition">&apos;${testType}&apos;==&apos;Case2&apos;</stringProp>

          <stringProp
name="TestElement.gui_class">org.apache.jmeter.control.gui.IfControllerPanel</stringProp>

          <stringProp
name="TestElement.test_class">org.apache.jmeter.control.IfController</stringProp>

          <stringProp name="TestElement.name">Case2</stringProp>
          <boolProp name="TestElement.enabled">true</boolProp>
        </IfController>
        <hashTree>
          <org.apache.jmeter.config.Arguments>
            <stringProp
name="TestElement.gui_class">org.apache.jmeter.config.gui.ArgumentsPanel</stringProp>

            <stringProp
name="TestElement.test_class">org.apache.jmeter.config.Arguments</stringProp>

            <collectionProp name="Arguments.arguments">
              <elementProp name="URL"
elementType="org.apache.jmeter.config.Argument">
                <stringProp name="Argument.metadata">=</stringProp>
                <stringProp
name="Argument.value">http://www.novell.com</stringProp>
                <stringProp name="Argument.name">URL</stringProp>
              </elementProp>
            </collectionProp>
            <stringProp name="TestElement.name">URL set to
www.novell.com</stringProp>
            <boolProp name="TestElement.enabled">true</boolProp>
          </org.apache.jmeter.config.Arguments>
          <hashTree/>
          <HTTPSampler>
            <stringProp name="HTTPSampler.path"></stringProp>
            <stringProp
name="TestElement.test_class">org.apache.jmeter.protocol.http.sampler.HTTPSampler</stringProp>

            <stringProp name="HTTPSampler.method">GET</stringProp>
            <boolProp name="HTTPSampler.use_keepalive">true</boolProp>
            <stringProp name="HTTPSampler.protocol"></stringProp>
            <boolProp name="TestElement.enabled">true</boolProp>
            <boolProp name="HTTPSampler.follow_redirects">true</boolProp>
            <stringProp name="HTTPSampler.port">80</stringProp>
            <elementProp name="HTTPsampler.Arguments"
elementType="org.apache.jmeter.config.Arguments">
              <stringProp
name="TestElement.gui_class">org.apache.jmeter.protocol.http.gui.HTTPArgumentsPanel</stringProp>

              <stringProp
name="TestElement.test_class">org.apache.jmeter.config.Arguments</stringProp>

              <collectionProp name="Arguments.arguments"/>
              <stringProp name="TestElement.name">User Defined
Variables</stringProp>
              <boolProp name="TestElement.enabled">true</boolProp>
            </elementProp>
            <stringProp name="HTTPSampler.mimetype"></stringProp>
            <stringProp
name="TestElement.gui_class">org.apache.jmeter.protocol.http.control.gui.HttpTestSampleGui</stringProp>

            <stringProp name="HTTPSampler.FILE_FIELD"></stringProp>
            <stringProp name="TestElement.name">HTTP Request</stringProp>
            <stringProp name="HTTPSampler.monitor">false</stringProp>
            <stringProp name="HTTPSampler.domain">${URL}</stringProp>
            <stringProp name="HTTPSampler.FILE_NAME"></stringProp>
            <boolProp name="HTTPSampler.auto_redirects">false</boolProp>
          </HTTPSampler>
          <hashTree/>
          <org.apache.jmeter.config.Arguments>
            <stringProp
name="TestElement.gui_class">org.apache.jmeter.config.gui.ArgumentsPanel</stringProp>

            <stringProp
name="TestElement.test_class">org.apache.jmeter.config.Arguments</stringProp>

            <collectionProp name="Arguments.arguments">
              <elementProp name="URL"
elementType="org.apache.jmeter.config.Argument">
                <stringProp name="Argument.metadata">=</stringProp>
                <stringProp
name="Argument.value">http://www.microsoft.com</stringProp>
                <stringProp name="Argument.name">URL</stringProp>
              </elementProp>
            </collectionProp>
            <stringProp name="TestElement.name">URL set to
www.microsoft.com</stringProp>
            <boolProp name="TestElement.enabled">true</boolProp>
          </org.apache.jmeter.config.Arguments>
          <hashTree/>
          <HTTPSampler>
            <stringProp name="HTTPSampler.path"></stringProp>
            <stringProp
name="TestElement.test_class">org.apache.jmeter.protocol.http.sampler.HTTPSampler</stringProp>

            <stringProp name="HTTPSampler.method">GET</stringProp>
            <boolProp name="HTTPSampler.use_keepalive">true</boolProp>
            <stringProp name="HTTPSampler.protocol"></stringProp>
            <boolProp name="TestElement.enabled">true</boolProp>
            <boolProp name="HTTPSampler.follow_redirects">true</boolProp>
            <stringProp name="HTTPSampler.port">80</stringProp>
            <elementProp name="HTTPsampler.Arguments"
elementType="org.apache.jmeter.config.Arguments">
              <stringProp
name="TestElement.gui_class">org.apache.jmeter.protocol.http.gui.HTTPArgumentsPanel</stringProp>

              <stringProp
name="TestElement.test_class">org.apache.jmeter.config.Arguments</stringProp>

              <collectionProp name="Arguments.arguments"/>
              <stringProp name="TestElement.name">User Defined
Variables</stringProp>
              <boolProp name="TestElement.enabled">true</boolProp>
            </elementProp>
            <stringProp name="HTTPSampler.mimetype"></stringProp>
            <stringProp
name="TestElement.gui_class">org.apache.jmeter.protocol.http.control.gui.HttpTestSampleGui</stringProp>

            <stringProp name="HTTPSampler.FILE_FIELD"></stringProp>
            <stringProp name="TestElement.name">HTTP Request</stringProp>
            <stringProp name="HTTPSampler.monitor">false</stringProp>
            <stringProp name="HTTPSampler.domain">${URL}</stringProp>
            <stringProp name="HTTPSampler.FILE_NAME"></stringProp>
            <boolProp name="HTTPSampler.auto_redirects">false</boolProp>
          </HTTPSampler>
          <hashTree/>
        </hashTree>
      </hashTree>
    </hashTree>
  </hashTree>
</jmeterTestPlan>

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