Jmeter cant read custom JAR depedencies - maven

I wrote a Maven application that I want to use in my Jmeter BeanShell script.
The Maven application is using Google Guice 4.2.2 for dependecy injection and it is calling an API at the end (Code needs to perform some other operations before calling the API and that's why I am not using the JMeter Plugin). I am creating the uber JAR (Fat JAR) with maven-shade-plugin. When I run the Jar from the command line the application run successfully!
However, When I load the JAR in my Jmeter test plan and call my application main method in the Jmeter BeanShell I am getting the following error:
java.lang.NoSuchMethodError: com.google.common.base.Preconditions.checkArgument(ZLjava/lang/String;Ljava/lang/Object;)V
at com.google.inject.Key.ensureRetainedAtRuntime(Key.java:341) ~[load-testing.jar:?]
.
.
.
Now lots of other threads mentioned that this can be because of older Google Guava version (20.x older) but from the dependency tree I see the Guava version is 25.1-android and I can run my JAR successfully from the command line!!
Also, I list the classes in the Uber JAR by running jar -tf command and I can see that the com.google.common.base.Preconditions class is there.
I would appreciate it if someone can shed some light on this matter and help me to resolve this?

It seems that your fat-jar contains multiple versions of Guava (which may be caused by the shade-plugin).
Make sure to lock it to single version by using Mavens dependency management in each maven module. (https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html#Dependency_Management)

The Beanshell itself might be a problem, since JMeter 3.1 it's recommended to use JSR223 Test Elements and Groovy language for scripting, the reasons are in:
Groovy is more "modern" language which supports all modern Java features while with Beanshell you're stuck at Java 1.5 language level (no lambdas, no generics, no multi-catch etc.)
Groovy performance is much better comparing to Beanshell cause Grooovy engine implements Compilable interface and is capable of caching compiled scripts providing performance very close to native Java code
Groovy provides a lot of enhancements on top of standard Java SDK
Check out Apache Groovy - Why and How You Should Use It article for more details.

I have finally cofirmed my comment. The problem was my JAR Guava version was conflicting with Jmeter Guava version (which is 17.0) and Jmeter for some reason is picking up its own Guava version, after downgrading Guice version to 3.0 which does not depend on guava, I successfully ran my JAR through Jmeter.
There is still a mystery on why Jmeter is overriding my JAR Guava version with its own. I will create a ticket with Jmeter in order to find more about this mystery but this change solved my problem

Related

Can we run karate tests on GraalVM JDK?

I have a REST API running on Springboot 3 and I test it using the karate framework.
As native is a new feature of springboot 3 I tried to run the API on GraalVM.
My app can run but when it comes to running tests I get this error :
java.lang.IllegalArgumentException: Could not find option with name js.ecmascript-version.
at org.graalvm.truffle/com.oracle.truffle.polyglot.PolyglotEngineException.illegalArgument(PolyglotEngineException.java:131)
at org.graalvm.truffle/com.oracle.truffle.polyglot.OptionValuesImpl.failNotFound(OptionValuesImpl.java:274)
at org.graalvm.truffle/com.oracle.truffle.polyglot.PolyglotEngineImpl.parseOptions(PolyglotEngineImpl.java:736)
at org.graalvm.truffle/com.oracle.truffle.polyglot.PolyglotEngineImpl.<init>(PolyglotEngineImpl.java:313)
at org.graalvm.truffle/com.oracle.truffle.polyglot.PolyglotImpl.buildEngine(PolyglotImpl.java:288)
at org.graalvm.sdk/org.graalvm.polyglot.Engine$Builder.build(Engine.java:625)
I use GraalVM 22.3.0 and karate-junit5 1.1.0 (I also tried more recent versions but it does not work).
Is there a compatibility problem between the Karate framework and the graalVM since the karate core already uses graaljs dependencies ?
Thank you in advance
Yes, can you first try 1.4.0.RC3 and refer this thread - or comment there also with your findings: https://github.com/karatelabs/karate/issues/2148
But if you want to use the GraalVM instead of a normal JVM, I don't think that's supported. But a PR is welcome.

Exported jar file is not visible in JUnit request sampler

i try to select class file in jmeter junit request sampler.i want help how to choose my class file in junit request sampler
i export the package and stored it in apache lib->junit folder
then,restart the jmeter, but my class file is not visible in junit request sampler and i import all the selenium jar files into the project including selenium standalone jar.
#Test
public void performence()
{
WebDriver driver=new HtmlUnitDriver();
driver.get("https://www.spicejet.com/");
System.out.println( driver.getTitle());
}
}
please help me to resolve this
I think your main issue is probably you didn't put dependencies (Webdriver) of your JUnit classes in lib folder.
Check jmeter.log to see what the error is and clarify your question.
Try checking Search for JUnit 4 annotations (instead of JUnit3) box (it is not checked by default hence JMeter is looking for JUnit3-style annotations)
Make sure your class has an empty constructor or constructor with a single String parameter. Other class types are not supported as of JMeter 5.0
Make sure to place the .jar with your test into lib/junit folder of your JMeter installation and other libraries (i.e. Selenium java client) to lib folder of your JMeter installation. Carefully select dependency libraries versions in order to avoid so called JAR Hell as JMeter and Selenium might rely on different versions of the same library.
JMeter restart will be required to pick up any changes
Check jmeter.log file for any suspicious entries. In the absolute majority of cases JMeter will print the information regarding the error or failure there.
See How to Use JUnit With JMeter article for more information on JUnit and JMeter integration.
If you don't have large number of JUnit-based tests which you want to import into JMeter and you're starting development from scratch it might be easier to go for WebDriver Sampler plugin which provides JMeter with smooth Selenium support and possibility to write Selenium-related code in variety of languages including Java.
You can install WebDriver Sampler plugin using JMeter Plugins Manager

Maven, NetBeans Platform, Wrapper Modules and Annotation Processors on dependencies

I have a Maven NetBeans platform application. One of its modules is a wrapper to a java project (jar) that exposes some services to the Lookup. In the wrapped project I use the maven-processor-plugin to process the annotations so everything gets registered in the Lookup. I’m unable to see the exposed classes on the wrapped module. I tried running the maven-processor-plugin but it is skipped since there are no source files in the wrapped module. Even if there were it wouldn’t fix the problem.
You can get the code here, in the Marauroa Server Manager project, Module: jWrestling Wrapper.
The code for the wrapped module can be found here. Annotated classes within the modules work fine.
Is there a way to execute the annotation processors on the dependencies of a project? Am I missing something obvious?
the wrapped jar project cannot contain nb.org annotations. these generate META_INF/generated-layer.xml file that is only read from a MODULE jar, not the wrapped non-module jar
the binary dependency contains some netbeans-originating annotations? and you want to process it through the maven plugin? that won't work. Most if not all netbeans annotations are compile-time only, meaning that they are processed at compile time and not retained in the bytecode. so only su
Besides for Netbeans annotations (which are based on jdk 1.6 annotation processors, you don't need the processor plugin, compile plugin should be sufficient.

Maven & Axis2 plugin - different stub code generation

I'm using Maven 3.0.4 and Axis2 1.5.1 plugin. I've a problem with the generation of a stub class using AXIS2 plugin on Maven.
Depending on the JDK currently configured on the build environment, AXIS2 plugin generates a different stub class source code. I've tried the generation using JDK 1.6 and then JDK 1.7.
Is there any way to "force" the JDK (i.e. 1.6) used by the AXIS2 plugin inside Maven (without changing environment)? (I would like to have a code generation independent from the environment)
Any help will be much appreciated.
I assume you select your JDK like described here :
http://maven.apache.org/plugins/maven-compiler-plugin/examples/compile-using-different-jdk.html
Then, I would generate the stub using a different profile, allowing you to override some configuration, but keeping the benefits of your overall conf.
Unfortunately, all my attempts are unsuccessful.
I have to resign myself to what I was shown in another post (http://maven.40175.n5.nabble.com/Maven-amp-Axis2-plugin-different-stub-code-generation-tc5730726.html ): if I really require this type of functionality, I may have to do this work yourself. Otherwise ask Axis2 devs if someone
will volunteer to do it.

Use Local Maven Repository

How can I use jars that buildr loads by default into the local maven repo, rather than creating new (and repetitive) artifact tasks/dependencies?
For example, if were creating a scala or groovy application buildr would automatically download the scala or groovy jars respectively. Is it possible to include or merge these (default) jars into an application rather than creating a new artifact?
I think that is not possible or doable in a one step, easy way. I recommend you talk with us on the dev list of Buildr and we can probably create an enhancement for that.
For each library you would like to depend on, you usual can grep the code to find where we define the default jar we depend on.
For the example you mention, here are the default method to retrieve the default jars:
For Groovy: Buildr::Groovy::Groovyc.dependencies
For Scala: Buildr::Scala::Scalac.dependencies
I hope that helps.

Resources