Last active
May 27, 2019 09:28
-
-
Save nremond/4354730 to your computer and use it in GitHub Desktop.
Demo of Gatling Websocket API
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 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