Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

karate\examples\gatling Project is not working throwing "java.lang.ClassNotFoundException: mock.CatsKarateSimulation" starting with gradle #2562

Open
SergKV opened this issue May 17, 2024 · 4 comments

Comments

@SergKV
Copy link

SergKV commented May 17, 2024

OS: Win 10 Pro
Gradle: Gradle 8.1.1
Gatling: 3.9.5
Java: openjdk 17.0.7 2023-04-18 LTS

Steps to reproduce:

  1. clone git repo
  2. navigate to folder -> "karate\examples\gatling"
  3. run gatling test with "gradle gatling" or with "gradle gatlingRun" command

Result:
09:52:16.061 [main] ERROR io.gatling.app.Gatling$ - Run crashed
java.lang.IllegalArgumentException: User defined Simulation class mock.CatsKarateSimulation could not be loaded
at io.gatling.app.Selection$Selector.findUserDefinedSimulationInClassloader$1(Selection.scala:84)
at io.gatling.app.Selection$Selector.$anonfun$singleSimulationFromConfig$4(Selection.scala:88)
at scala.Option.orElse(Option.scala:477)
at io.gatling.app.Selection$Selector.$anonfun$singleSimulationFromConfig$3(Selection.scala:88)
at scala.Option.flatMap(Option.scala:283)
at io.gatling.app.Selection$Selector.singleSimulationFromConfig(Selection.scala:87)
at io.gatling.app.Selection$Selector.$anonfun$selection$1(Selection.scala:50)
at scala.Option.getOrElse(Option.scala:201)
at io.gatling.app.Selection$Selector.selection(Selection.scala:42)
at io.gatling.app.Selection$.apply(Selection.scala:35)
at io.gatling.app.Runner.run(Runner.scala:53)
at io.gatling.app.Gatling$.start(Gatling.scala:89)
at io.gatling.app.Gatling$.fromArgs(Gatling.scala:51)
at io.gatling.app.Gatling$.main(Gatling.scala:39)
at io.gatling.app.Gatling.main(Gatling.scala)
Caused by: java.lang.ClassNotFoundException: mock.CatsKarateSimulation
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:520)
at java.base/java.lang.Class.forName0(Native Method)
at java.base/java.lang.Class.forName(Class.java:375)
at io.gatling.app.Selection$Selector.$anonfun$singleSimulationFromConfig$2(Selection.scala:73)
at scala.util.Try$.apply(Try.scala:210)
at io.gatling.app.Selection$Selector.findUserDefinedSimulationInClassloader$1(Selection.scala:73)
... 14 common frames omitted
Exception in thread "main" java.lang.IllegalArgumentException: User defined Simulation class mock.CatsKarateSimulation could not be loaded
at io.gatling.app.Selection$Selector.findUserDefinedSimulationInClassloader$1(Selection.scala:84)
at io.gatling.app.Selection$Selector.$anonfun$singleSimulationFromConfig$4(Selection.scala:88)
at scala.Option.orElse(Option.scala:477)
at io.gatling.app.Selection$Selector.$anonfun$singleSimulationFromConfig$3(Selection.scala:88)
at scala.Option.flatMap(Option.scala:283)
at io.gatling.app.Selection$Selector.singleSimulationFromConfig(Selection.scala:87)
at io.gatling.app.Selection$Selector.$anonfun$selection$1(Selection.scala:50)
at scala.Option.getOrElse(Option.scala:201)
at io.gatling.app.Selection$Selector.selection(Selection.scala:42)
at io.gatling.app.Selection$.apply(Selection.scala:35)
at io.gatling.app.Runner.run(Runner.scala:53)
at io.gatling.app.Gatling$.start(Gatling.scala:89)
at io.gatling.app.Gatling$.fromArgs(Gatling.scala:51)
at io.gatling.app.Gatling$.main(Gatling.scala:39)
at io.gatling.app.Gatling.main(Gatling.scala)
Caused by: java.lang.ClassNotFoundException: mock.CatsKarateSimulation
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:520)
at java.base/java.lang.Class.forName0(Native Method)
at java.base/java.lang.Class.forName(Class.java:375)
at io.gatling.app.Selection$Selector.$anonfun$singleSimulationFromConfig$2(Selection.scala:73)
at scala.util.Try$.apply(Try.scala:210)
at io.gatling.app.Selection$Selector.findUserDefinedSimulationInClassloader$1(Selection.scala:73)
... 14 more

@ptrthomas
Copy link
Member

ptrthomas commented May 17, 2024

@SergKV this example may indeed be out of date and we are more experienced with maven. please consider submitting a PR - meanwhile 1.5.X supports the Java option of Gatling instead of Scala - so see if that helps: https://github.com/karatelabs/karate-todo/tree/karate-1.5

@SergKV
Copy link
Author

SergKV commented May 17, 2024

Thx a lot for instant reaction,
I'll spend some time playing with ideas which you just brought to table.
Going to to turn back and write my results here after some time.

@xloypaypa
Copy link

Just fixed that, the issue is:

  1. the Scala code is not added as part of testing source code. So when you run the gatlingRun, it will not compile the scala files. So that's why gatling cannot found that class.
  2. After added it to src. There are few grammar issues about scala. so just import required language packages.

@ptrthomas
Copy link
Member

@xloypaypa merged with thanks !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants