Created
November 21, 2012 15:15
-
-
Save justinholmes/4125359 to your computer and use it in GitHub Desktop.
Gatling And Play!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package controllers | |
import play.api._ | |
import play.api.mvc._ | |
import com.excilys.ebi.gatling.core.Predef._ | |
import com.excilys.ebi.gatling.http.Predef._ | |
import com.excilys.ebi.gatling.jdbc.Predef._ | |
import com.excilys.ebi.gatling.core.result.message.RunRecord | |
import com.excilys.ebi.gatling.charts.report.ReportsGenerator | |
import com.excilys.ebi.gatling.core.runner.{Selection, Runner} | |
object Application extends Controller { | |
def index = Action { | |
gatling | |
Ok(views.html.index("Your new application is ready.")) | |
} | |
def gatling { | |
println("Creating run record") | |
import org.joda.time.DateTime._ | |
val runInfo = new RunRecord(now, "run-test", "stress-test") | |
println("Run record created > run scenario") | |
val klass = new Test | |
//klass.getClass | |
val selection = new Selection(klass.getClass, runInfo.simulationId, runInfo.runDescription) | |
val x = new Runner(selection).run | |
println("Simulation Finished.") | |
x | |
println("scenarion ran > generate reports") | |
generateReports(x) | |
println("reports generated") | |
} | |
def generateReports(runUuid: String) { | |
println("Generating reports...") | |
val start = System.currentTimeMillis | |
ReportsGenerator.generateFor(runUuid) | |
println("Reports generated in " + (System.currentTimeMillis - start) / 1000 + "s.") | |
} | |
} | |
object Scenario { | |
var httpConf = httpConfig | |
.baseURL("http://localhost:8080/") | |
.acceptCharsetHeader("ISO-8859-1,utf-8;q=0.7,*;q=0.7") | |
.acceptHeader("text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8") | |
.acceptEncodingHeader("gzip, deflate") | |
.acceptLanguageHeader("fr,fr") | |
.userAgentHeader("Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:8.0.1) Gecko/20100101 Firefox/8.0.1") | |
var scn = scenario("JMeter Benckmark with Gatling") | |
.exec(com.excilys.ebi.gatling.http.Predef.http("/") | |
.get("/") | |
.check(status.is(200))) | |
.pause(5) | |
} | |
class Test extends controllers.Simulation { | |
def apply = { | |
val urlBase = "http://localhost:8080/" | |
val httpConf = httpConfig.baseURL(urlBase) | |
Seq(Scenario.scn.configure.users(1500).ramp(100).delay(7).protocolConfig(httpConf)) | |
} | |
} | |
import com.excilys.ebi.gatling.core.Predef.{Simulation => GSimulation, _} | |
trait Simulation extends GSimulation { | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment