You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@jmeter.apache.org by kushalag <ku...@avaya.com> on 2011/08/29 22:37:32 UTC

Storing values in an Array

Hi,

I am trying to run a login scenario test with subsequent keep-alive type
messages.
The scenario is:
1) User logs in
2) Server responds with ok message and sends a session ID and unique token
3) At regular intervals the user sends a "keep-alive" message with session
ID and unique token, every 6 seconds

I already have a reg-expression extractor to extract the session ID and
token from the server's response, however I need to increase the number of
users in the same thread (without changing the number of threads). 
Therefore, i created a loop with a counter to run through the login sequence
for each of the users (user names are numeric). 

What I need to know now is how to store the unique token for each user into
a single variable that I can feed into a for-each loop for the keep-alive
messages.

Thanks,

Kushal

--
View this message in context: http://jmeter.512774.n5.nabble.com/Storing-values-in-an-Array-tp4747712p4747712.html
Sent from the JMeter - User mailing list archive at Nabble.com.

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


Re: Storing values in an Array

Posted by Bruce Ide <fl...@gmail.com>.
Yep. Sorry I wasn't being very clear there was I?

So set up the user counter as I suggested, and then

vars.put("token_${userCounter}", "${newToken});

Then you can iterate through the token array with a foreach loop! :-)

If you need additional information you can make more arrays too. Just do:

vars.put("username_${userCounter}", "${username}");

And so forth. But if you do this, you'll need to make a new counter and
increment it in  your foreach loop if you want to reference the various data
elements you need:

vars.put("username", vars.get("username_${newCounter}));
vars.put("newCounter", Integer.toString(${newCounter} + 1));

If you're iterating over token with a foreach, in this case, you won't need
to get token as well since the foreach element would have done that for you.
You can try the other iterator elements too, but consult the user's manual
if you haven't used them before, as their syntax may not be what you expect.

-- 
Bruce Ide
FlyingRhenquest@gmail.com

Re: Storing values in an Array

Posted by kushalag <ku...@avaya.com>.
Won't the "var.put" overwrite the previous value in "userCounter"?

What I need to do is, after each user logs in they will receive a unique
token from the server:

Token 1: adfkdkdkfja1234
Token 2: 234ksk343ksldf3
Token 3: kfkdf225699ssss
Token 4: 45k6k5k400000s
Token 5: 4444kk4k4k4k55

I need to be able to store them in one variable such that when I feed the
variable to the for-each loop it can reference each token individually.

--
View this message in context: http://jmeter.512774.n5.nabble.com/Storing-values-in-an-Array-tp4747712p4747928.html
Sent from the JMeter - User mailing list archive at Nabble.com.

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


Re: Storing values in an Array

Posted by Bruce Ide <fl...@gmail.com>.
I usually end up making a user defined variable userCounter = 1 and then
increment it as part of a BSF sampler inside the loop;

int counter = ${userCounter}; // or
Integer.parseInt(vars.get("userCounter"));
counter = counter + 1;
vars.put("userCounter", Integer.toString(counter));

You could probably do this in an __eval or __javascript or something, but I
don't know if it really buys you any more or less trying to do it that way.
I tend to prefer BSF samplers (With Groovy) for being more readiable. To a
java programmer anyway...

-- 
Bruce Ide
FlyingRhenquest@gmail.com