Jmeter beanshell: get variable type

Examples:

if (vars.get(“price_matchNr”) instanceof Integer){
log.info(“integer”);
}
if (vars.get(“price_matchNr”) instanceof String){
log.info(“string”);
}
if (Integer.parseInt(vars.get(“price_matchNr”)) instanceof int){
log.info(“int”);
}
if (Integer.valueOf(vars.get(“price_matchNr”)) instanceof Integer){
log.info(“Integer ValueOf”);
}

Gradle “Could not resolve all dependencies for configuration ‘:classpath’.”

Running a gradle project, you may encounter the error below. In my case it occurs after the gradle project crashed, requiring a restart.

Error message:

>Could not resolve all dependencies for configuration ':classpath'.
 >Could not load module metadata from /home/username/.gradle/caches/modules-2/metadata-2.97/descriptors/io.netty/netty-common/4.1.23.Final/671a8ecc284f9e9f4d35b614eb5de66e/descriptor.bin

Solution:

You need to delete the cache

cd /home/username/.gradle
rm -r caches

Log integer in beanshell and get integer from variables

Issue:

log.info() returns the following error in JMeter beanshell:

 Error in method invocation: Method info( int ) not found in class'org.apache.logging.slf4j.Log4jLogger'

Solution:

The error message indicates you are trying to pass an integer in the log.info() method. To prevent this issue, convert the integer to the type String using:

String SomeString = new Integer.toString(somInteger);

Similarly, numerals are passed as strings in JMeter variables, to make arithmetic operation on them, you’ll need to convert them to integer using:

int someInteger = new Integer.parseInt(someString);

Example use:

vars.put("test", new Integer(i).toString());

What is the @ sign in java used for?

The @ symbol denotes a Java Annotation. What a Java annotation does, is that it adds a special attribute to the variable, method, class, interface, or other language elements.

“In the Java computer programming language, an annotation is a form of syntactic metadata that can be added to Java source code. “

https://en.wikipedia.org/wiki/Java_annotation