Bug 61567 - JMeter test ran through JUnit fails within maven-surefire-plugin (mvn clean install)
Summary: JMeter test ran through JUnit fails within maven-surefire-plugin (mvn clean i...
Status: REOPENED
Alias: None
Product: JMeter - Now in Github
Classification: Unclassified
Component: Main (show other bugs)
Version: 3.0
Hardware: All All
: P2 normal (vote)
Target Milestone: ---
Assignee: JMeter issues mailing list
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-09-27 14:26 UTC by Serhiy
Modified: 2017-11-22 12:42 UTC (History)
1 user (show)



Attachments
Demo project (7.81 KB, application/x-zip-compressed)
2017-09-29 13:46 UTC, Serhiy
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Serhiy 2017-09-27 14:26:28 UTC
I have described issue in details at

https://stackoverflow.com/questions/46429778/when-running-jmeter-script-from-java-functions-and-properties-do-not-work/

It has sample code. Th eproblem I have found is that JMeter wants to have a library in classpath with exact name of "ApacheJMeter_functions.jar" it can't be  "ApacheJMeter_functions-3.3.jar" even if the files are binary equal.

This means that I can't load "ApacheJMeter_functions.jar" from Maven which is very inconvenient and causes additional issues.

Please change behavior so that "ApacheJMeter_functions*.jar" worked as well.
Comment 1 Philippe Mouawad 2017-09-27 18:26:18 UTC
See my answer on SO.

For information , to ask question use jmeter mailing list:

- http://jmeter.apache.org/mail2.html

Closing as WORKSFORME.
If issue persists , please reopen.

Regards
Comment 2 Serhiy 2017-09-28 09:13:59 UTC
Jmeter itself runs. The funstions do not work. For example, if you set "${__P(threadsNum,1)}" as a value for "Number of Threads" for thread group you will see in the log "starting 0 threads". Functions start to work only if jar is named exactly ApacheJMeter_functions.jar this means that I can't use this jar from Maven.
Comment 3 Philippe Mouawad 2017-09-28 09:15:10 UTC
Did you try the solution described in my SO answer ?
There is an issue in your code anyway.

Thank you
Comment 4 Serhiy 2017-09-29 13:46:08 UTC
Created attachment 35389 [details]
Demo project
Comment 5 Serhiy 2017-09-29 13:53:52 UTC
Sorry for confusion. I have copied jmeter.properties file to teh other location. So it has nothing to do with the behavior of the code.

I have attached demo project. Unzip it, edit pom.xml and src\main\java\mytst\tst1\App.java to specify correct JMeter home. After this run "mvn package". 

In the log you will see that everything is fine and one of the log lines will be following:
--
Starting thread group... number=1 threads=2 ramp-up=1 perThread=500.0 delayedStart=false
--

Now go back to pom.xml and comment out dependency to "${jmeter.home}/lib/ext/ApacheJMeter_functions.jar" and uncomment maven dependency which has to be downloaded from Maven repo. Run "mvn package" again. 

In the logs you will see following
--
 Starting thread group... number=1 threads=0 ramp-up=1 perThread=Infinity delayedStart=false
--

As you see the difference is that with "ApacheJMeter_functions.jar" it was "threads=2" but with "ApacheJMeter_functions-3.3.jar" you get "threads=0". But two jars are binary equal(I have checked this) and the only difference is their name.In the jmeter script I am setting "ThreadGroup.num_threads" to ${__P(xxx,2)} which is function.
Comment 6 Philippe Mouawad 2017-09-29 20:03:35 UTC
Hello,
Thanks for the project.
It helped me understand your problem.

I notice:
- Code works if App is ran as a Main application
- Code works if AppTest is ran from Eclipse
- Code fails when ran through mvn clean install


The failure is due to this code:

- https://github.com/apache/jmeter/blob/trunk/src/jorphan/org/apache/jorphan/reflect/ClassFinder.java#L335
Comment 7 Sebb 2017-11-22 11:25:43 UTC
I think the failure is due to the project setup.

The POM mixes system and non-system JMeter dependencies.
No wonder JMeter has problems with the classpath.
Comment 8 Philippe Mouawad 2017-11-22 11:27:47 UTC
The mix is just to highlight the bug.
When only using non system dependencies, test fails.
IMO it's a jmeter issue.
Comment 9 Serhiy 2017-11-22 12:42:20 UTC
(In reply to Sebb from comment #7)
> I think the failure is due to the project setup.
> 
> The POM mixes system and non-system JMeter dependencies.
> No wonder JMeter has problems with the classpath.

This has nothing to do with the bug. You hav to use "system" scope if you want to add jar called "ApacheJMeter_functions.jar". This is definitely bug. 

Try it yourself and remove this. That's the entire point of this issue.
Comment 10 The ASF infrastructure team 2022-09-24 20:38:10 UTC
This issue has been migrated to GitHub: https://github.com/apache/jmeter/issues/4506