I am trying to write a sample Gatling test. This test runs correctly in a different maven project but not working with an existing project where I am trying to add gatling
It identifies the Simulation tests,as soon as enter option 1 or 2
it crashes with below error
02:32:40.519 [main] INFO i.g.c.config.GatlingConfiguration$ - Gatling will try to load 'gatling.conf' config file as ClassLoader resource.
02:32:41.258 [GatlingSystem-akka.actor.default-dispatcher-5] INFO akka.event.slf4j.Slf4jLogger - Slf4jLogger started
02:32:49.267 [main] ERROR io.gatling.app.Gatling$ - Run crashed
java.lang.NoSuchFieldError: DNT
at io.gatling.http.HeaderNames$.<clinit>(Headers.scala:44)
at io.gatling.http.HttpDsl.$init$(HttpDsl.scala:52)
at io.gatling.http.Predef$.<clinit>(Predef.scala:19)
at io.gatling.javaapi.http.internal.HttpCheckBuilders$.<clinit>(HttpCheckBuilders.scala:24)
at io.gatling.javaapi.http.internal.HttpCheckBuilders.status(HttpCheckBuilders.scala)
at io.gatling.javaapi.http.HttpDsl.status(HttpDsl.java:142)
at com.mastercard.perf.ClaimTest.<init>(ClaimTest.java:20)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at java.lang.Class.newInstance(Class.java:442)
at io.gatling.app.SimulationClass$Java.params(SimulationClass.scala:35)
at io.gatling.app.Runner.run(Runner.scala:59)
at io.gatling.app.Gatling$.start(Gatling.scala:90)
at io.gatling.app.Gatling$.fromMap(Gatling.scala:44)
at io.gatling.app.Gatling.fromMap(Gatling.scala)
at com.mastercard.perf.Engine.main(Engine.java:13)
02:32:49.315 [GatlingSystem-akka.actor.default-dispatcher-5] INFO akka.actor.CoordinatedShutdown - Running CoordinatedShutdown with reason [ActorSystemTerminateReason]
This is a Springboot project,I have just written a main call to run the gatling code
Engine class
import io.gatling.app.Gatling;
import io.gatling.core.config.GatlingPropertiesBuilder;
public class Engine {
public static void main(String[] args) {
GatlingPropertiesBuilder prop = new GatlingPropertiesBuilder()
.resourcesDirectory(IDEPathHelper.mavenResourcesDirectory.toString())
.resultsDirectory(IDEPathHelper.resultsDirectory.toString())
.binariesDirectory(IDEPathHelper.mavenBinariesDirectory.toString());
Gatling.fromMap(prop.build());
}
}
IDEPath helper
public class IDEPathHelper {
static final Path mavenSourcesDirectory;
static final Path mavenResourcesDirectory;
static final Path mavenBinariesDirectory;
static final Path resultsDirectory;
static final Path recorderConfigFile;
static {
try {
Path projectRootDir = Paths.get(IDEPathHelper.class.getClassLoader().getResource("gatling.conf").toURI()).getParent().getParent().getParent();
Path mavenTargetDirectory = projectRootDir.resolve("target");
Path mavenSrcTestDirectory = projectRootDir.resolve("src").resolve("test");
mavenSourcesDirectory = mavenSrcTestDirectory.resolve("java");
mavenResourcesDirectory = mavenSrcTestDirectory.resolve("resources");
mavenBinariesDirectory = mavenTargetDirectory.resolve("test-classes");
resultsDirectory = mavenTargetDirectory.resolve("gatling");
recorderConfigFile = mavenResourcesDirectory.resolve("recorder.conf");
} catch (URISyntaxException e) {
throw new ExceptionInInitializerError(e);
}
}
}
Main Test
import io.gatling.javaapi.core.ScenarioBuilder;
import io.gatling.javaapi.core.Simulation;
import io.gatling.javaapi.http.HttpProtocolBuilder;
import static io.gatling.core.CoreDsl.*;
import static io.gatling.javaapi.core.CoreDsl.*;
import static io.gatling.javaapi.http.HttpDsl.http;
import static io.gatling.javaapi.http.HttpDsl.status;
public class ClaimTest extends Simulation {
private HttpProtocolBuilder httpProtocol = http.baseUrl("http://reqree.in");
private ScenarioBuilder users = scenario("Test").exec(
http("Giuven users")
.get("/2")
.check(
status().is(200)).
check(jsonPath("$.data.first_name").is("Janet"),status().is(200))
).pause(1);
{
setUp(users.injectOpen(atOnceUsers(1)).protocols(httpProtocol));
}
}
Thanks in advance
You’re most likely mixing Gatling and your Spring Boot application, which causes a version clash at runtime on the Netty version (you’re forcing a downgrade, causing a field to be missing in older versions).
I recommend that you store your Gatling test in a directory that doesn’t depend on your application’s classpath, eg a subdirectory that’s not a module of your parent pom.xml that pulls all your application deps.