Trying to extend Gatling into Play!

I am trying to extend Gatling into a Play! project so I can build a web interface which will create performance tests.

However I am having some difficulties with Gatling’s Simulation abstract class

type mismatch; found : java.lang.Class[?0] where type ?0 <: controllers.Test required: Class[com.excilys.ebi.gatling.core.scenario.configuration.Simulation] Note: ?0 <: com.excilys.ebi.gatling.core.scenario.configuration.Simulation, but Java-defined class Class is invariant in type T. You may wish to investigate a wildcard type such as _ <: com.excilys.ebi.gatling.core.scenario.configuration.Simulation.

Regards and thanks in advance.

https://gist.github.com/4125359

Hi Justin,

I don’t really undestand what you want to do. Is it a web interface to run tests, or to create them ?

If you want to integrate gatling tests into a Play 2.0 app, Andy Petrella has been working on a Play plugin for Gatling (https://github.com/andypetrella/gatling-play2-plugin). Maybe you can find something interesting in it :wink:

Cheers,

Sounds fun!

I think your problem is that Selection is currently invariant in the class type (maybe we should change that?).

Try to replace val klass = new Test by val klass = classOf[Test].asInstanceOf[Class[GSimulation]] and then directly pass it to the Selection constructor. Note that you must create a Test instance as you do, as the Runner with create a new one by reflection.

Cheers,

Stéphane

Cheers, yeah I will opensource it will generate tests then submit them to an Akka cluster part of 2.1 :slight_smile: to be executed.

Hi,

I have been trying to integrate Gatling with play framework so that I can have a webinterface to execute the gatling commands. I tried to compile Andy’s project from sbt but its throwing up errors. Could you guide me plz?

Hi,
What are the errors ?

sbt.ResolveException: unresolved dependency: be.nextlab#gatling-sbt-plugin;0.0.1-SNAPSHOT: not found

Hi Stephane,

I followed the steps which were mentioned here, but couldnt run it from play framework. Below is the error am getting when I give “val klass = classOf[CASimulation].asInstanceOf[Class[com.excilys.ebi.gatling.core.scenario.configuration.Simulation]]”, here CASimulation is a class written for running from gatling.sh.

type mismatch; found : Class[?0] where type ?0 <: Class[com.excilys.ebi.gatling.core.scenario.configuration.Simulation] required: Class[com.excilys.ebi.gatling.core.scenario.configuration.Simulation]

Plz help.

Thanks!

Hi,

I don’t see anything with this code:
val klass = classOf[CASimulation].asInstanceOf[Class[com.excilys.ebi.gatling.core.scenario.configuration.Simulation]]

what does the method you pass klass look like?

Hi Stephane,

Below is the CASimulation class. I am trying to call Selection class of Gatling by passing an instance of Simulation class and other 2 parameters. But when I try to pass the Simulation, it always through error. I wanted to run Selection by passing parameters from Play framework. I have followed the steps attached in this mail thread.

class CASimulation extends Simulation {

var time1 :Long =0;

var time2 :Long =0;

val logger = org.slf4j.LoggerFactory.getLogger(“TEST”)

val httpConf = httpConfig.baseURL(“http://xx”).acceptHeader(“application/xml”)

.responseInfoExtractor { response =>

if (response.getStatusCode == 200) {

val extendedResponse = response.asInstanceOf[com.excilys.ebi.gatling.http.response.ExtendedResponse]

if(extendedResponse.getUri.toString.equals(“http://xx/xx/xx”)){

time1 = extendedResponse.responseReceivingStartDate

logger.info(“uri time {} : {}”,extendedResponse.getUri,time1)

logger.info(“time1&2 {} : {}”,time1,time2)

logger.info(“Latency : {}”,time1-time2)

}

}

Nil

}

val httpPEConf = httpConfig.baseURL(“http://xx”).acceptHeader(“application/xml”)

.responseInfoExtractor { response =>

if (response.getStatusCode == 200) {

val extendedResponse = response.asInstanceOf[com.excilys.ebi.gatling.http.response.ExtendedResponse]

time2 = extendedResponse.requestSendingEndDate

logger.info(“Time for PE : {}”,time2)

logger.info(“requst body {}”,extendedResponse.request.getStringData)

}

Nil

}

val headers_3 = Map(

“Connection” → “keep-alive”,

“Content-Type” → “application/x-www-form-urlencoded”,

“LoginToken” → “${logintoken}”)

val headers_4 = Map(

“Connection” → “keep-alive”,

“Content-Type” → “application/xml”)

val scn = scenario(“CometAdapter”)

.feed(csv(Console.readLine))

.exec(http(“CreateSession”)

.post("/CometAdapter/CreateSession")

.body(""“xxxxxx”"")

.headers(headers_3)

.check(status.is(200)))

.exec(

http(“LogClientInfo”)

.put("/xxx")

.check(status.is(200)))

.repeat(Console.readInt) {exec(

http(“GetNotifications”)

.get("/xx")

.check(status.is(200)))

}

setUp(

scn.users(1).protocolConfig(httpConf)

)

}

Hi Stephane,

I have been trying to run the Gatling2.0.3M3a from play framework. . I am getting the error “[RuntimeException: java.lang.NoClassDefFoundError: Could not initialize class io.gatling.http.config.HttpProtocolBuilder$]” I have all dependencies declared in Build.scala and I do not get any compilation error. But at runtime I am not getting the HttpConfig class. I tried giving this gatling http jar in classpath of the terminal, set all the classpath as given inside gatling.sh file. None of these worked.

To verify if the other settings are correct, I commenetd out the lines calling httpprotocol and then when ran, I got the NullPointerexception at “val x = new Runner(selection).run”. I am attaching the files. Kindly help.

Build.scala (3.05 KB)

Application.scala (1.2 KB)

gatlingsample.scala (733 Bytes)

Hi Divya,

I’ll try to have a look later. I’m just back from Scala.Io and I’m dead tired!

Cheers,

Stéphane

Thanks a lot Stephane for the update :slight_smile: I shall be waiting for your input.

Hi Divya,

You have to first set up the GatlingConfiguration singleton before trying to run anything, just like it’s done in the Gatling companion.
Just add GatlingConfiguration.setUp() before running the Runner.

Cheers,

Stéphane

Hi Stephane,

Thanks a lot, I am able to run the tests from Play :slight_smile:

Thanks,
Divya

Cool!

Feel free to show what you come up with.

Cheers,

Stéphane

Hi Stephane,

I am stuck at one more point. I am trying to generate the reports also for the tests similar to what is being done in Gatling currently.

Here is what I have written in Application.scala :

def generateReports(outputDirectoryName: String, dataReader: => DataReader) {

println(“Generating reports…”)

val start = currentTimeMillis

val indexFile = ReportsGenerator.generateFor(outputDirectoryName, dataReader)

println(s"Reports generated in ${(currentTimeMillis - start) / 1000}s.")

println(s"Please open the following file : $indexFile")}

val outputDirectoryName ="."

lazy val dataReader = DataReader.newInstance(outputDirectoryName)

for this, I am getting the error “java.lang.IllegalArgumentException: requirement failed: simulation directory doesn’t contain any log file.”

I can see that simulation.log file is created at …/results/-20131028152233/simulation.log. Could you tell me how I should be giving the

That’s the first element of Tuple2 returned by Runner.run:
https://github.com/excilys/gatling/blob/master/gatling-app/src/main/scala/io/gatling/app/Gatling.scala#L195

so happy to tell you that it worked :slight_smile:
Thanks a lot !!!