Discussion:
How to pass a variable as a parameter to random function
bvm101
2007-06-12 19:47:58 UTC
Permalink
Within a BeanShell PreProcessor I have a following code:

java.util.List ids = new java.util.ArrayList();
ids.add("key1");
ids.add("key2");
ids.add("key3");

int clientSize = ids.size();

${__Random(0,3 ,myRandom)};

vars.put("Col_65537", ids.get(${myRandom}));


However, when calling random function I would like to pass a variable for
the max value, in this case "clientSize", instead of number 3.

Your help will be greatly appreciated.

Thanks,

Boban
--
View this message in context: http://www.nabble.com/How-to-pass-a-variable-as-a-parameter-to-random-function-tf3909593.html#a11085352
Sent from the JMeter - User mailing list archive at Nabble.com.
Ankem, Balaji
2007-06-12 19:55:05 UTC
Permalink
Hi,

I want to record when I am testing on my desktop browser.

My website is linked to different servers. Once the request is changed
to different server I am not getting the page as I kept the server name
in HTTP Request defaults to a single server.

Is there any way to direct the request to any server name?


Thanks in advance.

Regards
Balaji
sebb
2007-06-12 22:25:58 UTC
Permalink
Post by bvm101
java.util.List ids = new java.util.ArrayList();
ids.add("key1");
ids.add("key2");
ids.add("key3");
int clientSize = ids.size();
${__Random(0,3 ,myRandom)};
The above line should give the clue ... try

${__Random(0,${clientSize} ,myRandom)};
Post by bvm101
vars.put("Col_65537", ids.get(${myRandom}));
However, when calling random function I would like to pass a variable for
the max value, in this case "clientSize", instead of number 3.
Your help will be greatly appreciated.
If your test uses this Pre-processor a lot, you may find you get memory leaks.

You could put the code in an init file, and then call a method passing
in the Random number.
Post by bvm101
Thanks,
Boban
--
View this message in context: http://www.nabble.com/How-to-pass-a-variable-as-a-parameter-to-random-function-tf3909593.html#a11085352
Sent from the JMeter - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
bvm101
2007-06-12 22:48:09 UTC
Permalink
I did try ${__Random(0,${clientSize} ,myRandom)};, however, I get following
error (error log):


2007/06/12 17:41:43 ERROR - jmeter.threads.JMeterThread:
java.lang.NumberFormatException: For input string: "${clientSize}"
at java.lang.NumberFormatException.forInputString(Unknown Source)
at java.lang.Long.parseLong(Unknown Source)
at java.lang.Long.parseLong(Unknown Source)
at org.apache.jmeter.functions.Random.execute(Random.java:78)
at
org.apache.jmeter.engine.util.CompoundVariable.execute(CompoundVariable.java:127)
at
org.apache.jmeter.engine.util.CompoundVariable.execute(CompoundVariable.java:96)
at
org.apache.jmeter.testelement.property.FunctionProperty.getStringValue(FunctionProperty.java:85)
at
org.apache.jmeter.testbeans.TestBeanHelper.prepare(TestBeanHelper.java:69)
at
org.apache.jmeter.threads.TestCompiler.runPreProcessors(TestCompiler.java:109)
at
org.apache.jmeter.threads.TestCompiler.configureSampler(TestCompiler.java:98)
at org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:236)
at java.lang.Thread.run(Unknown Source)

${__Random(0,${clientSize} ,myRandom)};
Post by sebb
Post by bvm101
java.util.List ids = new java.util.ArrayList();
ids.add("key1");
ids.add("key2");
ids.add("key3");
int clientSize = ids.size();
${__Random(0,3 ,myRandom)};
The above line should give the clue ... try
${__Random(0,${clientSize} ,myRandom)};
Post by bvm101
vars.put("Col_65537", ids.get(${myRandom}));
However, when calling random function I would like to pass a variable for
the max value, in this case "clientSize", instead of number 3.
Your help will be greatly appreciated.
If your test uses this Pre-processor a lot, you may find you get memory leaks.
You could put the code in an init file, and then call a method passing
in the Random number.
Post by bvm101
Thanks,
Boban
--
http://www.nabble.com/How-to-pass-a-variable-as-a-parameter-to-random-function-tf3909593.html#a11085352
Sent from the JMeter - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
---------------------------------------------------------------------
--
View this message in context: http://www.nabble.com/How-to-pass-a-variable-as-a-parameter-to-random-function-tf3909593.html#a11088976
Sent from the JMeter - User mailing list archive at Nabble.com.
sebb
2007-06-12 22:59:20 UTC
Permalink
Post by bvm101
I did try ${__Random(0,${clientSize} ,myRandom)};, however, I get following
There's a space after ${clientSize} - try removing it.

If that does not help, make sure that clientSize is defined, e.g. by
adding the following to the BeanShell script:

print("Size=${clientSize}.";
Post by bvm101
java.lang.NumberFormatException: For input string: "${clientSize}"
at java.lang.NumberFormatException.forInputString(Unknown Source)
at java.lang.Long.parseLong(Unknown Source)
at java.lang.Long.parseLong(Unknown Source)
at org.apache.jmeter.functions.Random.execute(Random.java:78)
at
org.apache.jmeter.engine.util.CompoundVariable.execute(CompoundVariable.java:127)
at
org.apache.jmeter.engine.util.CompoundVariable.execute(CompoundVariable.java:96)
at
org.apache.jmeter.testelement.property.FunctionProperty.getStringValue(FunctionProperty.java:85)
at
org.apache.jmeter.testbeans.TestBeanHelper.prepare(TestBeanHelper.java:69)
at
org.apache.jmeter.threads.TestCompiler.runPreProcessors(TestCompiler.java:109)
at
org.apache.jmeter.threads.TestCompiler.configureSampler(TestCompiler.java:98)
at org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:236)
at java.lang.Thread.run(Unknown Source)
${__Random(0,${clientSize} ,myRandom)};
Post by sebb
Post by bvm101
java.util.List ids = new java.util.ArrayList();
ids.add("key1");
ids.add("key2");
ids.add("key3");
int clientSize = ids.size();
${__Random(0,3 ,myRandom)};
The above line should give the clue ... try
${__Random(0,${clientSize} ,myRandom)};
Post by bvm101
vars.put("Col_65537", ids.get(${myRandom}));
However, when calling random function I would like to pass a variable for
the max value, in this case "clientSize", instead of number 3.
Your help will be greatly appreciated.
If your test uses this Pre-processor a lot, you may find you get memory leaks.
You could put the code in an init file, and then call a method passing
in the Random number.
Post by bvm101
Thanks,
Boban
--
http://www.nabble.com/How-to-pass-a-variable-as-a-parameter-to-random-function-tf3909593.html#a11085352
Sent from the JMeter - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
---------------------------------------------------------------------
--
View this message in context: http://www.nabble.com/How-to-pass-a-variable-as-a-parameter-to-random-function-tf3909593.html#a11088976
Sent from the JMeter - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
bvm101
2007-06-13 00:38:47 UTC
Permalink
I am sorry, I am looking at the example to define clientSize, but I can’t
figure it out: print("Size=${clientSize}.";.
Will you elaborate?
Post by sebb
Post by bvm101
I did try ${__Random(0,${clientSize} ,myRandom)};, however, I get following
There's a space after ${clientSize} - try removing it.
If that does not help, make sure that clientSize is defined, e.g. by
print("Size=${clientSize}.";
Post by bvm101
java.lang.NumberFormatException: For input string: "${clientSize}"
at java.lang.NumberFormatException.forInputString(Unknown Source)
at java.lang.Long.parseLong(Unknown Source)
at java.lang.Long.parseLong(Unknown Source)
at org.apache.jmeter.functions.Random.execute(Random.java:78)
at
org.apache.jmeter.engine.util.CompoundVariable.execute(CompoundVariable.java:127)
at
org.apache.jmeter.engine.util.CompoundVariable.execute(CompoundVariable.java:96)
at
org.apache.jmeter.testelement.property.FunctionProperty.getStringValue(FunctionProperty.java:85)
at
org.apache.jmeter.testbeans.TestBeanHelper.prepare(TestBeanHelper.java:69)
at
org.apache.jmeter.threads.TestCompiler.runPreProcessors(TestCompiler.java:109)
at
org.apache.jmeter.threads.TestCompiler.configureSampler(TestCompiler.java:98)
at
org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:236)
at java.lang.Thread.run(Unknown Source)
${__Random(0,${clientSize} ,myRandom)};
Post by sebb
Post by bvm101
java.util.List ids = new java.util.ArrayList();
ids.add("key1");
ids.add("key2");
ids.add("key3");
int clientSize = ids.size();
${__Random(0,3 ,myRandom)};
The above line should give the clue ... try
${__Random(0,${clientSize} ,myRandom)};
Post by bvm101
vars.put("Col_65537", ids.get(${myRandom}));
However, when calling random function I would like to pass a variable
for
Post by sebb
Post by bvm101
the max value, in this case "clientSize", instead of number 3.
Your help will be greatly appreciated.
If your test uses this Pre-processor a lot, you may find you get memory leaks.
You could put the code in an init file, and then call a method passing
in the Random number.
Post by bvm101
Thanks,
Boban
--
http://www.nabble.com/How-to-pass-a-variable-as-a-parameter-to-random-function-tf3909593.html#a11085352
Post by sebb
Post by bvm101
Sent from the JMeter - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
---------------------------------------------------------------------
--
http://www.nabble.com/How-to-pass-a-variable-as-a-parameter-to-random-function-tf3909593.html#a11088976
Sent from the JMeter - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
---------------------------------------------------------------------
--
View this message in context: http://www.nabble.com/How-to-pass-a-variable-as-a-parameter-to-random-function-tf3909593.html#a11090492
Sent from the JMeter - User mailing list archive at Nabble.com.
sebb
2007-06-13 15:04:10 UTC
Permalink
Sorry, that should have been:

print("Size=${clientSize}.");

This does not define clientSize; it displays the value in the console
window so you can check that you have defined it properly.
I am sorry, I am looking at the example to define clientSize, but I can't
figure it out: print("Size=${clientSize}.";.
Will you elaborate?
Post by sebb
Post by bvm101
I did try ${__Random(0,${clientSize} ,myRandom)};, however, I get following
There's a space after ${clientSize} - try removing it.
If that does not help, make sure that clientSize is defined, e.g. by
print("Size=${clientSize}.";
Post by bvm101
java.lang.NumberFormatException: For input string: "${clientSize}"
at java.lang.NumberFormatException.forInputString(Unknown Source)
at java.lang.Long.parseLong(Unknown Source)
at java.lang.Long.parseLong(Unknown Source)
at org.apache.jmeter.functions.Random.execute(Random.java:78)
at
org.apache.jmeter.engine.util.CompoundVariable.execute(CompoundVariable.java:127)
at
org.apache.jmeter.engine.util.CompoundVariable.execute(CompoundVariable.java:96)
at
org.apache.jmeter.testelement.property.FunctionProperty.getStringValue(FunctionProperty.java:85)
at
org.apache.jmeter.testbeans.TestBeanHelper.prepare(TestBeanHelper.java:69)
at
org.apache.jmeter.threads.TestCompiler.runPreProcessors(TestCompiler.java:109)
at
org.apache.jmeter.threads.TestCompiler.configureSampler(TestCompiler.java:98)
at
org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:236)
at java.lang.Thread.run(Unknown Source)
${__Random(0,${clientSize} ,myRandom)};
Post by sebb
Post by bvm101
java.util.List ids = new java.util.ArrayList();
ids.add("key1");
ids.add("key2");
ids.add("key3");
int clientSize = ids.size();
${__Random(0,3 ,myRandom)};
The above line should give the clue ... try
${__Random(0,${clientSize} ,myRandom)};
Post by bvm101
vars.put("Col_65537", ids.get(${myRandom}));
However, when calling random function I would like to pass a variable
for
Post by sebb
Post by bvm101
the max value, in this case "clientSize", instead of number 3.
Your help will be greatly appreciated.
If your test uses this Pre-processor a lot, you may find you get memory leaks.
You could put the code in an init file, and then call a method passing
in the Random number.
Post by bvm101
Thanks,
Boban
--
http://www.nabble.com/How-to-pass-a-variable-as-a-parameter-to-random-function-tf3909593.html#a11085352
Post by sebb
Post by bvm101
Sent from the JMeter - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
---------------------------------------------------------------------
--
http://www.nabble.com/How-to-pass-a-variable-as-a-parameter-to-random-function-tf3909593.html#a11088976
Sent from the JMeter - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
---------------------------------------------------------------------
--
View this message in context: http://www.nabble.com/How-to-pass-a-variable-as-a-parameter-to-random-function-tf3909593.html#a11090492
Sent from the JMeter - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
Loading...