Gatling java.lang.NoClassDefFoundError: io/gatling/charts/component/impl/ComponentLibraryImpl

When I run a very simple simulation, I get this (with gatling 2.0 SNAPSHOT):

Exception in thread “main” java.lang.NoClassDefFoundError: io/gatling/charts/component/impl/ComponentLibraryImpl

at io.gatling.charts.component.ComponentLibrary$.(ComponentLibrary.scala:42)

at io.gatling.charts.component.ComponentLibrary$.(ComponentLibrary.scala)

at io.gatling.charts.report.ReportsGenerator$.generateFor(ReportsGenerator.scala:44)

at io.gatling.app.Gatling.generateReports$1(Gatling.scala:170)

Analysis:

I downloaded the source code for gatling. The class file in question is in the source, but not in the compiled jar.

In the source code of gatlng there is this class that never makes it to the jar file with a clear explanation if you know Scala (I don’t) about it being a mock class.

package io.gatling.charts.component.impl

/**

  • Mock implementation that is removed from the binary.
  • A unique implementation is expected to be present in the classpath.
    */
    class ComponentLibraryImpl extends ComponentLibrary {

GOAL:
I am trying to run gatling from a gradle script. Scratch that… I am trying to get Gatling 2.0 SNAPSHOT to run somehow, some way.

Gatling and Gradle Example based on this blog post about Load Testing in Gradle with Gatling.

A good friend of mine gave me A LOT OF GATLING 2.0 SCRIPTS for a project and the example from the blog was of course Gatling 1.5.

1.5 != 2.0 :slight_smile:

The 2.0 that is on the website is incompatible with the scripts my friend gave me. He says it is what is in github currently is what is needed.

I am just trying to get some simulations to run and generate a report. Basic stuff. I am new to Gatling.

After hours, screwing around with sbt and gradle, I was able to get something running, but the error above. The closest I got was calling it from gradle. The build for the dist seems to be horked or I don’t know sbt that well or both.

Running sbt dist generates a zip file with no jar files. So one that does not run. The 2.0 from the site, does not work with the 2.0 scripts that I have.

This is not the actual project. The actual project I can’t share, but this is the same error message. A small test case.

I created a little sample project here:

https://github.com/RichardHightower/reactive-java-book/tree/master/examples/project-starter-with-load-test

Sample project

I have a vertx verticle (more or less like a servlet).

public class ExampleVerticle extends Verticle {

private final String CONTENT_TYPE_KEY = “Content-Type”;
private final String CONTENT_TYPE_VALUE = “text/html; charset=UTF-8”;
private String message = “\nHi Mom!\n”;

public void start() {

HttpServer server = vertx.createHttpServer();

server.requestHandler(new Handler() {
public void handle(final HttpServerRequest request) {
doGet(request);
}
});
server.listen(8080);

}

void doGet(HttpServerRequest request) {
request.response().headers().add(CONTENT_TYPE_KEY, CONTENT_TYPE_VALUE);
request.response().setStatusCode(200).end(
this.message
);
}

public String getMessage() {
return message;
}

public void setMessage(String message) {
this.message = message;
}
}

The Gatling test is here:

package com.example

import io.gatling.core.Predef._
import io.gatling.http.Predef._
import io.gatling.http.HeaderNames._
import io.gatling.http.HeaderValues._
import io.gatling.core.scenario.Simulation
import io.gatling.http.Predef._
import io.gatling.core.Predef._
import io.gatling.http.HeaderNames._
import io.gatling.http.HeaderValues._

import scala.concurrent.duration._

class ExampleVerticleLoadTest extends Simulation {

val httpProtocol = http
.baseURL(System.getProperty(“HOST_UNDER_TEST”, “http://localhost:8080/”))

val scn = scenario(“ExampleVerticle”)
.exec(http(“Get Hello World”).get("/"))

setUp(scn.inject(atOnceUsers(1))).protocols(httpProtocol)
}

So basically… Hello World.

Running:

You run vertx like this btw

$ ./gradlew clean compileJava modZip runMod

You run gatling like this:

$ ./gradlew load

OUTPUT:

Simulation com.example.ExampleVerticleLoadTest started…

18:21:37.901 [GatlingSystem-akka.actor.default-dispatcher-2] INFO io.gatling.http.config.HttpProtocol - Start warm up

18:21:37.925 [GatlingSystem-akka.actor.default-dispatcher-2] DEBUG o.j.n.c.socket.nio.SelectorUtil - Using select timeout of 500

18:21:37.925 [GatlingSystem-akka.actor.default-dispatcher-2] DEBUG o.j.n.c.socket.nio.SelectorUtil - Epoll-bug workaround enabled = false

18:21:37.991 [GatlingSystem-akka.actor.default-dispatcher-2] DEBUG o.j.n.channel.DefaultChannelFuture - The dead lock checker in DefaultChannelFuture has been disabled as requested at your own risk.

18:21:38.041 [GatlingSystem-akka.actor.default-dispatcher-2] DEBUG c.n.h.c.p.n.NettyAsyncHttpProvider -

Non cached request

DefaultHttpRequest(chunked: false)

GET /xUrsE HTTP/1.1

Host: goo.gl

Accept: text/html,application/xhtml+xml,application/xml;q=0.9,/;q=0.8

Accept-Language: en-US,en;q=0.5

Connection: keep-alive

Accept-Encoding: gzip,deflate

User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:16.0) Gecko/20100101 Firefox/16.0

using Channel

[id: 0xc5bb3a41, /0:0:0:0:0:0:0:1:63255 => goo.gl/74.125.224.224:80]

18:21:38.230 [New I/O worker #2] DEBUG c.n.h.c.p.n.NettyAsyncHttpProvider -

Request DefaultHttpRequest(chunked: false)

GET /xUrsE HTTP/1.1

Host: goo.gl

Accept: text/html,application/xhtml+xml,application/xml;q=0.9,/;q=0.8

Accept-Language: en-US,en;q=0.5

Connection: keep-alive

Accept-Encoding: gzip,deflate

User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:16.0) Gecko/20100101 Firefox/16.0

Response DefaultHttpResponse(chunked: false)

HTTP/1.1 301 Moved Permanently

Content-Type: text/html; charset=UTF-8

Cache-Control: no-cache, no-store, max-age=0, must-revalidate

Pragma: no-cache

Expires: Fri, 01 Jan 1990 00:00:00 GMT

Location: http://gatling-tool.org/

X-Content-Type-Options: nosniff

X-Frame-Options: SAMEORIGIN

X-XSS-Protection: 1; mode=block

Server: GSE

Alternate-Protocol: 80:quic

Content-Length: 206

18:21:38.231 [New I/O worker #2] DEBUG c.n.h.c.p.netty.NettyConnectionsPool - Adding uri: http://goo.gl:80 for channel [id: 0xc5bb3a41, /0:0:0:0:0:0:0:1:63255 => goo.gl/74.125.224.224:80]

18:21:38.232 [GatlingSystem-akka.actor.default-dispatcher-2] INFO io.gatling.http.config.HttpProtocol - Warm up done

18:21:38.243 [GatlingSystem-akka.actor.default-dispatcher-2] INFO i.gatling.core.controller.Controller - Total number of users : 1

18:21:38.294 [GatlingSystem-akka.actor.default-dispatcher-3] INFO i.g.c.result.writer.FileDataWriter - Initializing

18:21:38.294 [GatlingSystem-akka.actor.default-dispatcher-10] INFO i.g.c.r.writer.ConsoleDataWriter - Initializing

18:21:38.296 [GatlingSystem-akka.actor.default-dispatcher-3] INFO i.g.c.result.writer.FileDataWriter - Initialized

18:21:38.296 [GatlingSystem-akka.actor.default-dispatcher-10] INFO i.g.c.r.writer.ConsoleDataWriter - Initialized

18:21:38.299 [GatlingSystem-akka.actor.default-dispatcher-11] DEBUG i.gatling.core.controller.Controller - Launching All Scenarios

18:21:38.303 [GatlingSystem-akka.actor.default-dispatcher-11] DEBUG i.gatling.core.controller.Controller - Finished Launching scenarios executions

18:21:38.303 [GatlingSystem-akka.actor.default-dispatcher-11] DEBUG i.gatling.core.controller.Controller - Setting up max duration

18:21:38.304 [GatlingSystem-akka.actor.default-dispatcher-11] INFO i.gatling.core.controller.Controller - Start user #554931357585131387-0

When I run a very simple simulation, I get this (with gatling 2.0 SNAPSHOT):

Exception in thread “main” java.lang.NoClassDefFoundError: io/gatling/charts/component/impl/ComponentLibraryImpl

at io.gatling.charts.component.ComponentLibrary$.(ComponentLibrary.scala:42)

at io.gatling.charts.component.ComponentLibrary$.(ComponentLibrary.scala)

at io.gatling.charts.report.ReportsGenerator$.generateFor(ReportsGenerator.scala:44)

at io.gatling.app.Gatling.generateReports$1(Gatling.scala:170)

Analysis:

I downloaded the source code for gatling. The class file in question is in the source, but not in the compiled jar.

In the source code of gatlng there is this class that never makes it to the jar file with a clear explanation if you know Scala (I don’t) about it being a mock class.

package io.gatling.charts.component.impl

/**

  • Mock implementation that is removed from the binary.
  • A unique implementation is expected to be present in the classpath.
    */
    class ComponentLibraryImpl extends ComponentLibrary {

The ComponentLibraryImpl in gatling-charts doesn’t do anything.
The “real” implementation of ComponentLibraryImpl is in Gatling Highcharts : https://github.com/excilys/gatling-highcharts/blob/master/src/main/scala/io/gatling/charts/component/impl/ComponentLibraryImpl.scala
gatling-chart’s ComponentLibraryImpl is actually filtered out of the JAR during the build : https://github.com/excilys/gatling/blob/master/project/BuildSettings.scala#L71

GOAL:
I am trying to run gatling from a gradle script. Scratch that… I am trying to get Gatling 2.0 SNAPSHOT to run somehow, some way.

Gatling and Gradle Example based on this blog post about Load Testing in Gradle with Gatling.

A good friend of mine gave me A LOT OF GATLING 2.0 SCRIPTS for a project and the example from the blog was of course Gatling 1.5.

1.5 != 2.0 :slight_smile:

The 2.0 that is on the website is incompatible with the scripts my friend gave me. He says it is what is in github currently is what is needed.

I am just trying to get some simulations to run and generate a report. Basic stuff. I am new to Gatling.

After hours, screwing around with sbt and gradle, I was able to get something running, but the error above. The closest I got was calling it from gradle. The build for the dist seems to be horked or I don’t know sbt that well or both.

Running sbt dist generates a zip file with no jar files. So one that does not run. The 2.0 from the site, does not work with the 2.0 scripts that I have.

If you want to build Gatling locally, you should use the publishLocal task. It installs the JARs in your local Ivy repo but it’s fine since you’re working with Gradle.

This is not the actual project. The actual project I can’t share, but this is the same error message. A small test case.

I created a little sample project here:

https://github.com/RichardHightower/reactive-java-book/tree/master/examples/project-starter-with-load-test

It looks like you’re not pulling gatling-highcharts, which explains why Gatling fails during reports generation : the reports engine is basically missing.
You only need to add compile ‘io.gatling.highcharts:gatling-highcharts:2.0.0-SNAPSHOT’ to your dependencies and it should work fine.

It works now. Thanks. I was missing gatling-highcharts.

The missing link:

compile ‘io.gatling.highcharts:gatling-charts-highcharts:2.0.0-SNAPSHOT’

Now I have an environment to learn and use gatling. Yeah! :slight_smile:

So for anyone else who would like to use this gradle script with gatling 2.0 snapshot, here are some instructions. (I am assuming you are not a Scala pro like myself.)

1) Edit sbt and add 8x more memory or you get OutOfMemoryExceptions

$ emacs /usr/local/Cellar/sbt/0.13.1/bin/sbt

Add a lot of memory!

#!/bin/sh

test -f ~/.sbtconfig && . ~/.sbtconfig

exec java -Xmx6g ${SBT_OPTS} -jar /usr/local/Cellar/sbt/0.13.1/libexec/sbt-launch.jar “$@”

2) Build Gatling and highcharts

$ git pull https://github.com/excilys/gatling.git

$ sbt publishM2

$ git pull https://github.com/excilys/gatling-highcharts.git
$ sbt publishM2

I guess use publishLocal if you are using Ivy. We (clients that I work for) mostly use maven so publishM2 puts things where the maven projects can find them. I suppose SBT and gradle use ivy so… IDK.

You can find the example here:

https://github.com/RichardHightower/reactive-java-book (I don’t know if this “book” will ever get done… I started it last week, but it where I am putting my notes for vertx, hazelcast, boon, websocket and slumberdb, docker, microservice stuff that I am working on, … now gatling examples… it is nascent so not much there).

$ git pull https://github.com/RichardHightower/reactive-java-book.git

$ cd reactive-java-book/examples/project-starter-with-load-test/

Runs the sample verticle (horrible, it will be one task at some point)

$ ./gradlew clean compileJava modZip install runMod

Run gatling

$ ./gradlew clean load

Gatling will print out where the reports are located.

Open with Chrome or Safari, do not use FireFox, unless you want to. :slight_smile:

Ok… now I am going to go learn gatling.

BTW, that graph looks beautiful. I can’t wait until I run some real tests.

Pierre DAL-PRA… Thanks man! I really appreciate it.

I saw that dependency at some point in the near past between the meetings, and doctor appointments, and phone calls, etc. I said, I have to remember to find this jar file. Then I promptly forgot. Doh!

Thanks man. Once I added that, it all worked.

You’re welcome :slight_smile:

Glad that I could help !

Still, I don’t recall having to increase heap size in order to build Gatling with sbt.
@pdalpra Did you?

Maybe a tiny bit, but SBT is mostly PermGen-hungry : the JVM’s default MaxPermSize is just not enough.

@Rick:
Thanks for sharing your experiences and lessons learned while working with gradle and gatling SNAPSHOT.

I read the same blog post you did on the Rally Software blog (about using gatling for load testing) and it got me really inspired.

Just curious…did you ever get gradle and gatling SNAPSHOT to work without using SBT to build it?