jmeter-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Layton, Andrew" <andrew.lay...@atosorigin.com>
Subject How to convert JMeter User Defined Variable between strings and integers?
Date Thu, 22 Jun 2006 09:26:38 GMT
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. 
_______________________________________________________


Mime
View raw message