Skip to content

Instantly share code, notes, and snippets.

@nremond
Last active May 27, 2019 09:28
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save nremond/4354730 to your computer and use it in GitHub Desktop.
Save nremond/4354730 to your computer and use it in GitHub Desktop.
Demo of Gatling Websocket API
package basic
import com.excilys.ebi.gatling.core.Predef._
import com.excilys.ebi.gatling.http.Predef._
import akka.util.duration._
import bootstrap._
import scala.collection.mutable
// Simulation for the Play20 chat sample app
// cf : (https://github.com/playframework/Play20/tree/master/samples/scala/websocket-chat)
class ChatSimulation extends Simulation {
val usernames = List("albert", "robert", "monique", "madelaine", "léon",
"louis", "léonard", "marie-jeanne", "lucien", "joseph", "françois", "marine")
val usersFeeder = new Feeder[String] {
val remainingUsernames = mutable.Queue[String](usernames : _*)
override def hasNext = !remainingUsernames.isEmpty
override def next: Map[String, String] = {
Map("user"-> remainingUsernames.dequeue)
}
}
val scn = scenario("Play20 chat example")
.feed(usersFeeder)
.exec(websocket("Chat").open("ws://localhost:9000/room/chat?username=${user}"))
.pauseExp(3 seconds)
.exec(websocket("Chat").sendMessage("""{"text" : "Hello, I'm ${user}"}"""))
.pauseExp(3 seconds)
.exec(websocket("Chat").sendMessage("""{"text" : "Do you know any other ${user} ?"}"""))
.pauseExp(3 seconds)
.exec(websocket("Chat").close())
setUp(scn.users(usernames.size).ramp(2))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment