JMeter Beanshell Integer Error

Andreas Lassak

i have problem with Integer in JMeter Beanshell Sampler/Pre/Post processor. I have some array of values, and i want to use each value of this array to set JMeterProperty for next use.

GOAL> have some N rows from query. For Example UPSTREAM column has diff values and i need it save them for next use. Because i will use them for call CMD.exe as parameters by "OS Processes Sampler".

So, if UPSTREAM_1=XXX, UPSTREAM_2=AAA, 
CMD.EXE will looks like: CMD.EXE -upstream_1 -upstream_2, etc.

From SQL i got Array of values

COUNT=31
UPSTREAM_#=31
UPSTREAM_1=XXX
UPSTREAM_2=AAA
....

In PostProcessor i set:

${__setProperty(COUNT, ${COUNT_1})};

I am trying this scrpit:

import java.util.*;
import java.text.*; 
import java.io.*;

int max = Integer.parseInt(vars.get(${COUNT_1})); //--COUNT=31, Integer doesnt work
int n = vars.get(${COUNT_1}); //--COUNT=31, this also doesnt work

for (int i=1;i<=n;i++)
{
   ${__setProperty(UPSTREAM_i, ${UPSTREAM_i})};
}

But JMeter log say that it dont know the "INT"

2016/10/03 14:52:13 ERROR - jmeter.util.BeanShellInterpreter: Error invoking bsh method: eval   Sourced file: inline evaluation of: `` import java.util.*; import java.text.*;  import java.io.*;  int max = Integer.p . . . '' : Typed variable declaration : Error in method invocation: Method get( int ) not found in class'org.apache.jmeter.threads.JMeterVariables' 
2016/10/03 14:52:13 WARN  - jmeter.protocol.java.sampler.BeanShellSampler: org.apache.jorphan.util.JMeterException: Error invoking bsh method: eval Sourced file: inline evaluation of: `` import java.util.*; import java.text.*;  import java.io.*;  int max = Integer.p . . . '' : Typed variable declaration : Error in method invocation: Method get( int ) not found in class'org.apache.jmeter.threads.JMeterVariables' 

Can somebody help me? Maybe i miss some libs or something. JRE/JDK i have.


UPDATE_1

User Variables all:

COUNT   ${__property(COUNT)}    Count of Rows from SQL Query

Test_Plan:

enter image description here

PostProcessor Log:

SamplerProperties:
variableNames=DATE,DOWNSTREAM,UPSTREAM,COUNT,etc.

JMeterVariables:
COUNT=31
COUNT_#=31
COUNT_1=31
COUNT_2=31
.....
DATE_#=31
DATE_1=04.10.2016
DATE_2=04.10.2016
.....
DOWNSTREAM_#=31
DOWNSTREAM_1=DDD11
DOWNSTREAM_2=DDD11
.....
UPSTREAM_#=31
UPSTREAM_1=XXX
UPSTREAM_2=AAA
....
JMeterProperties:
COUNT= 31
DATE= 04.10.2016
DOWNSTREAM= DDD11
TEST= 1

Debug Loop log:

SamplerProperties:
BeanShellSampler.query=import java.util.*;
 import java.text.*; 
 import java.io.*;
 int n = Integer.parseInt(vars.get("COUNT")); 
 for (int i=1;i<=n;i++)
 {
      props.setProperty("UPSTREAM_"+i, vars.get("UPSTREAM_i"));
 }
    JMeterVariables:
    COUNT=31
    COUNT_#=31
    COUNT_1=31
    COUNT_2=31
    .....
    DATE_#=31
    DATE_1=04.10.2016
    DATE_2=04.10.2016
    .....
    DOWNSTREAM_#=31
    DOWNSTREAM_1=DDD11
    DOWNSTREAM_2=DDD11
    .....
    UPSTREAM_#=31
    UPSTREAM_1=XXX
    UPSTREAM_2=AAA
    ....
    JMeterProperties:
    COUNT= 31
    DATE= 04.10.2016
    DOWNSTREAM= DDD11
    TEST= 1

This is in Jmeter log now:

2016/10/03 17:12:24 ERROR - jmeter.util.BeanShellInterpreter: Error invoking bsh method: eval   Sourced file: inline evaluation of: ``import java.util.*;  import java.text.*;   import java.io.*;  int n = Integer.pa . . . '' : Method Invocation props.setProperty 
2016/10/03 17:12:24 WARN  - jmeter.protocol.java.sampler.BeanShellSampler: org.apache.jorphan.util.JMeterException: Error invoking bsh method: eval Sourced file: inline evaluation of: ``import java.util.*;  import java.text.*;   import java.io.*;  int n = Integer.pa . . . '' : Method Invocation props.setProperty 

UPDATE_2

UBIK LOAD PACK's solution works :), GOAL updated.

UBIK LOAD PACK

Your Beanshell script has many errors:

 import java.util.*;
 import java.text.*; 
 import java.io.*;
 int n = Integer.parseInt(vars.get("COUNT")); 
 for (int i=1;i<=n;i++)
 {
      props.setProperty("UPSTREAM_"+i, vars.get("UPSTREAM_"+i));
 }

Note what you are doing is setting in props (global) what you get from vars (specific to each user) , so this may be wrong.

Read:

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related