0

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.

Asad Iqbal
  • 3,241
  • 4
  • 32
  • 52

1 Answers1

1

I think you can achieve the above behavior in a better way by creating a simple Scala class for doing this .Basically you can create an object

object Configuration{
 val file = getClass.getResource("data/config.properties").getFile()
 val prop = new Properties()
 prop.load(new FileInputStream(file))
 ENV =prop.getProperty("env");
}

Now in your Simulation class

class TestSimulation extends Simulation {
   val ALL_STOP_STATUS = Configuration.ENV;
 }

Similarly specialize it even more to use path variables

user666
  • 1,104
  • 12
  • 20
  • the issue comes when my application will try to run parallel load tests based on the same Simulation class but with different settings. That will require me to have some sort of synchronization on the env variables – Asad Iqbal Mar 24 '17 at 18:31
  • No need for synchronization...just change the logic to read from classpath and replace object with a class instance – user666 Mar 24 '17 at 20:27