At the time writing the above entry, I had to quickly hack gatling to use Akka 2.0 as Play 2.0 uses it, and I didn't wanted to have clashes.
But, thanks to Stéphane Landelle, Gatling is now Akka 2.0 enabled (since 1.1.2).
So that, it was time to give the plugin's embryo a refresh. For that I used another project that aims testing the neo4j rest plugin for Play2.0 I'm also writing. In case of, I've also introduced what I did in this project in this post.
ContentUsing the Gatling I first tested how I've been able to stress test:
- simple (get) urls
- mutating (post) urls using server form underground to compile excepted data.
- duration tests (stress testing on a given period basis)
What I liked so much, even in this embryos+, is the ease to create stress tests when coupled with Play2.0 functionalities and Gatling's DSL.
The Gatling plugin I'm currently building is located on github here and is based on sbt to build it.
But it's based on the version 1.1.4-SNAPSHOT version of Gatling's libraries (due to some fixes the Stéphane did "for me", while he was at devoxx fr, isn't he gentle !!!).
At the time writing, you'll have to build gatling and gatling-highcharts locally using maven (quick fast!).
Having created a Play 2.0 app, you now have to powerful of sbt in hands (especially if you've installed the TypeSafe stack 2.0). So, to stress test your app, you'll have first to build to plugin I told above.
First of all, clone/fork this library project on github plugin, after what, you'll just have to run
sbt publish-localin the related folder. That's it, you now have the plugin in your local repo.
In your Play 2.0 app, you now are able to define the plugin as `test` dependency, using the following
Personally, for testing I use org.specs2.Specification, for using it with the plugin (at the time writing) you'll have to create the following:
This listing is creating a fake server to enable urls to be tested, and some functions to deal with it.
To create the server, the plugin defines a Util object (be.nextlab.play.gatling.Util), which also defines rough helpers to be used in stress tests.
A full spec should look the following:
You saw, in the provided gist above, that Util also defines a way to simply defines a gatling Simulation (basically a Function0 that returns a scenario builder: Gatling DSL result).
Having that in hand, here is the fragment to stress test the root url:
As you can see, it's pretty simple, but nothing can really be checked in the body of the specs (I'm working on having relevant information to check).
But, at least you can run this test to hit 10 times the root url ramping the numbers of users by 2.
Running it (sbt test) you'll have a new gatling folder in your target folder that contains a results directory where are located all stress results in an html report (with great charts)
And all you had to do is to define the request headers and the url...
Mutating the server
If you have controllers that mutates the server, you should have define POST urls, which are using the Form feature provided by Play 2.0.
Having did so, you'll be able to stress it very easily using Map, JsObject or in the best case your Model.
Let's say we have a controller
controllers.Stuffsthat uses case classes
models.Stuff. The controller defines a stuffForm and a createStuff action.
Your stress test can now be defined like the following:
In the gist, you can see 5 points to note, they are key-clues to create reusable stress tests.
Nothing is really hardcoded, neither the path to the http end point nor the parameters data.
That's http stress testing using type checked requests. CoOl isn't it? Hey, man, we got back our lovin' type cheking (one of the best scala feature).
Heavy check, duration based
This part is more a Gatling feature highlighting.
This last example is an heavy test that uses looping over a configuration for a given period. This gives you how many users could use your application.
Such test might be shaped the following:
For now, it's NOT an official plugin neither a gatling nor a play 2.0 one, but discussions are on the way for that... stay tuned on twitter or here.