Yan Lincle
Yan Lincle

Reputation: 291

Jmeter Beanshell couldn't recognize Set<String>

I want to delete the data in redis before taking the sample so I put the code in Beanshell Preprocessor. But the code is not running,just like the Beanshell can not recognize the Set ,part of my code is below:

import redis.clients.jedis.Jedis;
import java.util.Set;

String new_pattern = "*WITHDRAW_RISK_CONTROL_*";
Set<String> keysSet = null;
System.out.println("here****************");

and Set<String> keySet =null is not working.I have imported Set import java.util.Set; Is this Jmeter problem? or any reason?

The second question is :it can recognize the class Jedis in Jedis jar.But it can not support Jedis JedisPoolConfig ,why?

Upvotes: 5

Views: 1850

Answers (3)

Liu Zhen
Liu Zhen

Reputation: 1

You could use "Object keysSet" instead of "Set keysSet". It solved my problem.

Upvotes: 0

Dmitri T
Dmitri T

Reputation: 168002

  • Diamond operator was introduced in Java 7 which appeared in 2011
  • JMeter comes with Beanshell 2.0b5 which was released in 2005

So it is expected that Java 7 features are not supported by quite an outdated Beanshell interpreter. It should work if you remove <String> bit.

Beanshell set initialization

I expect the problem lives somewhere else. In order to debug your Beanshell script you can try out the following approaches:

  1. Add debug(); directive at the very beginning of your script. It will trigger debugging information output to STDOUT (where you expect your here**************** line)
  2. Wrap "suspicious" code in try/catch block like

    try {
        // your Beanshell
        // code here
    
    } catch (Throwable ex) {
        log.info("Something went wrong", ex);
    }
    

    Inspect jmeter.log file for failure details.

See How to use BeanShell: JMeter's favorite built-in component guide for advanced information on Beanshell scripting in JMeter.

Upvotes: 2

UBIK LOAD PACK
UBIK LOAD PACK

Reputation: 34516

Beanshell does not support Generics.

You should use instead JSR223PreProcessor + Groovy instead:

Note that there is a Redis DataSet if that's your request:

Upvotes: 3

Related Questions