I want to be able to pass parameters to a Gatling Simulation. I have tried this, however it is failing. (The issue seems to be due to inner class)
object PerfTestManager extends App {
run("trymain", 10, 2, 3);
def run(dcName: String, minutes: Int, threads: Int, maxThreads: Int) = {
class BasicSimul extends Simulation {
val scn = scenario("a").feed(QueryFeeder.myfeeder)
.exec(http("test").get(s => SolrEnv.getPath(s("params").validate[String].get)));
private val hostport = SolrEnv.hostport
val httpConf = http.baseURL(hostport)
.acceptHeader("text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8")
.acceptEncodingHeader("gzip, deflate")
.acceptLanguageHeader("en-US,en;q=0.5")
.userAgentHeader("Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:16.0) Gecko/20100101 Firefox/16.0");
setUp(scn.inject(atOnceUsers(threads)).protocols(httpConf))
}
val simClass = classOf[BasicSimulation].getName
val props = new GatlingPropertiesBuilder
props.dataDirectory(Paths2.dataDirectory.toString)
props.resultsDirectory(Paths2.resultsDirectory.toString)
props.bodiesDirectory(Paths2.bodiesDirectory.toString)
props.binariesDirectory(Paths2.mavenBinariesDirectory.toString)
props.simulationClass(simClass)
props.runDescription("runonce")
props.outputDirectoryBaseName("0")
Gatling.fromMap(props.build) // <-- failing line
}
}
My intention is to eventually run a webservice, which will be used to schedule and parameterize the Simulations from a UI. While I have a some alternatives which I can try, something closer to the above code seems the easiest to maintain. Above code fails, as gatling is unable to create an instance of BasicSimul
Caused by: java.lang.NoSuchMethodException: computerdatabase.PerfTestManager$BasicSimul$1.<init>()
at java.lang.Class.getConstructor0(Class.java:3082)
at java.lang.Class.newInstance(Class.java:412)
I also tried to pass parameters to BasicSimulation, however, the framework requires a default constructor so that was not successful either.
My alternative will be to declare the following in an object
val q = new Queue
The scheduling webservice will enqueue a new TestConfig based on the parameters, and BasicSimulation
will dequeue()
to get its TestConfig. Synchronized constructs can be used to avoid race conditions.