I have a class that extends Simulation. This class is used to define individual POST requests from the api I am testing.
What I would like to do is create a chained sequence of 2-3 requests. Then there needs to be a final request that is randomly selected by the randomSwitch.
The switch contains 3 requests that are defined elsewhere within this class. Each has its own feeder calls, exec method, flow control and check statements and is assigned to a val object.
To run with Gatling, I have a second Simulation class that sets up http protocol and injects load. It instantiates class members and serves as a generic ‘runner’ to exercise each predefined scenario.
I’ve gotten this to work for each individual request in my class, as well as my sequence (until randomSwitch was added).
The switch looks like this >
.randomSwitch (
5.0 → exec(request3),
10.0 → exec(request4),
85.0 → exec(request5)
)
It gets called right after 2 inline scenarios (each having its own .exec, .feed and .check statements) .
The switch looks OK in the editor (no error indications), but when I try to run it, I get an error like this>
Exception in thread “main” java.lang.NullPointerException
at io.gatling.core.structure.Execs$class.exec(Execs.scala:31)
at io.gatling.core.Predef$.exec(Predef.scala:33)
at performance.simulations.scenarios.PostRequests.(PostRequests.scala:167)
at performance.simulations.Injector.(Injector.scala:31)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at java.lang.Class.newInstance(Class.java:374)
at io.gatling.core.runner.Runner.run(Runner.scala:37)
at io.gatling.app.Gatling.start(Gatling.scala:236)
at io.gatling.app.Gatling$.fromMap(Gatling.scala:55)
at io.gatling.app.Gatling$.runGatling(Gatling.scala:80)
at io.gatling.app.Gatling$.runGatling(Gatling.scala:59)
at io.gatling.app.Gatling$.main(Gatling.scala:51)
at io.gatling.app.Gatling.main(Gatling.scala)
Is this not a legal use case? If so, what should I do to fix it?
A full code sample is attached.
Thanks in advance.
gatling_randomSwitchSample.txt (2.65 KB)